Commit d3de400b authored by Taddeus Kroes's avatar Taddeus Kroes

Added /raw command and better exception handling.

parent b6fb2278
...@@ -41,6 +41,12 @@ class ClientConnection(object, asyncore.dispatcher): ...@@ -41,6 +41,12 @@ class ClientConnection(object, asyncore.dispatcher):
self.port = addr[1] self.port = addr[1]
super(ClientConnection, self).connect(addr) super(ClientConnection, self).connect(addr)
def send(self, cmd):
"""
Send raw command to the chat server.
"""
self.send_queue.put(cmd)
def retrieve_users(self): def retrieve_users(self):
""" """
Retreive list of users active at the chat server. Retreive list of users active at the chat server.
...@@ -57,7 +63,10 @@ class ClientConnection(object, asyncore.dispatcher): ...@@ -57,7 +63,10 @@ class ClientConnection(object, asyncore.dispatcher):
self.send_queue.put('USER %s' % name) self.send_queue.put('USER %s' % name)
def handle_connect(self): def handle_connect(self):
"""Called when a connection is established.""" """
Called when a connection is established.
"""
if 'connect' in self.event_list: if 'connect' in self.event_list:
self.event_list['connect'](self) self.event_list['connect'](self)
......
...@@ -196,7 +196,11 @@ All commands listed below should be preceded by a slash: ...@@ -196,7 +196,11 @@ All commands listed below should be preceded by a slash:
def quit(main): def quit(main):
# Disconnect the connection # Disconnect the connection
e = None
try:
del self.connection del self.connection
except:
pass
# Reverse the curses-friendly terminal settings. # Reverse the curses-friendly terminal settings.
curses.nocbreak(); curses.nocbreak();
...@@ -206,8 +210,14 @@ All commands listed below should be preceded by a slash: ...@@ -206,8 +210,14 @@ All commands listed below should be preceded by a slash:
# Restore the terminal to its original operating mode. # Restore the terminal to its original operating mode.
curses.endwin() curses.endwin()
if e:
raise e
sys.exit(0) sys.exit(0)
def raw(main, cmd):
main.connection.send(cmd)
def user(main, name): def user(main, name):
main.connection.username(name) main.connection.username(name)
...@@ -223,6 +233,7 @@ All commands listed below should be preceded by a slash: ...@@ -223,6 +233,7 @@ All commands listed below should be preceded by a slash:
'exec': _exec, 'exec': _exec,
'help': help, 'help': help,
'quit': quit, 'quit': quit,
'raw': raw,
'user': user, 'user': user,
} }
...@@ -274,7 +285,7 @@ All commands listed below should be preceded by a slash: ...@@ -274,7 +285,7 @@ All commands listed below should be preceded by a slash:
# Call command handler. # Call command handler.
try: try:
if cmd == 'exec': if cmd == 'exec' or cmd == 'raw':
cmd_fn(self, raw_command) cmd_fn(self, raw_command)
else: else:
cmd_fn(self, *args) cmd_fn(self, *args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment