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):
self.port = addr[1]
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):
"""
Retreive list of users active at the chat server.
......@@ -57,7 +63,10 @@ class ClientConnection(object, asyncore.dispatcher):
self.send_queue.put('USER %s' % name)
def handle_connect(self):
"""Called when a connection is established."""
"""
Called when a connection is established.
"""
if 'connect' in self.event_list:
self.event_list['connect'](self)
......
......@@ -196,7 +196,11 @@ All commands listed below should be preceded by a slash:
def quit(main):
# Disconnect the connection
del self.connection
e = None
try:
del self.connection
except:
pass
# Reverse the curses-friendly terminal settings.
curses.nocbreak();
......@@ -206,8 +210,14 @@ All commands listed below should be preceded by a slash:
# Restore the terminal to its original operating mode.
curses.endwin()
if e:
raise e
sys.exit(0)
def raw(main, cmd):
main.connection.send(cmd)
def user(main, name):
main.connection.username(name)
......@@ -223,6 +233,7 @@ All commands listed below should be preceded by a slash:
'exec': _exec,
'help': help,
'quit': quit,
'raw': raw,
'user': user,
}
......@@ -274,7 +285,7 @@ All commands listed below should be preceded by a slash:
# Call command handler.
try:
if cmd == 'exec':
if cmd == 'exec' or cmd == 'raw':
cmd_fn(self, raw_command)
else:
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