Commit 6807fc3f authored by Taddeüs Kroes's avatar Taddeüs Kroes

Changed onexception() to onerror(), fixed some typo's

parent 6641c0c4
...@@ -111,7 +111,7 @@ class Connection(object): ...@@ -111,7 +111,7 @@ class Connection(object):
self.onclose(None, '') self.onclose(None, '')
break break
except Exception as e: except Exception as e:
self.onexception(e) self.onerror(e)
def send_close(self, code, reason): def send_close(self, code, reason):
""" """
...@@ -191,7 +191,7 @@ class Connection(object): ...@@ -191,7 +191,7 @@ class Connection(object):
""" """
return NotImplemented return NotImplemented
def onexception(self, e): def onerror(self, e):
""" """
Handle a raised exception. Handle a raised exception.
""" """
......
...@@ -26,7 +26,7 @@ class Server(object): ...@@ -26,7 +26,7 @@ class Server(object):
>>> def onmessage(self, client, message): >>> def onmessage(self, client, message):
>>> # handle message from client >>> # handle message from client
>>> GameServer(port=8000).run() >>> GameServer(8000).run()
""" """
def __init__(self, port, hostname='', loglevel=logging.INFO, protocols=[]): def __init__(self, port, hostname='', loglevel=logging.INFO, protocols=[]):
...@@ -96,7 +96,7 @@ class Server(object): ...@@ -96,7 +96,7 @@ class Server(object):
logging.debug(msg) logging.debug(msg)
def onexception(self, client, e): def onerror(self, client, e):
logging.error(format_exc(e)) logging.error(format_exc(e))
...@@ -120,8 +120,8 @@ class Client(Connection): ...@@ -120,8 +120,8 @@ class Client(Connection):
def onclose(self, code, reason): def onclose(self, code, reason):
self.server.remove_client(self, code, reason) self.server.remove_client(self, code, reason)
def onexception(self, e): def onerror(self, e):
self.server.onexception(self, e) self.server.onerror(self, e)
def __str__(self): def __str__(self):
return '<Client at %s:%d>' % self.sock.getpeername() return '<Client at %s:%d>' % self.sock.getpeername()
...@@ -129,5 +129,5 @@ class Client(Connection): ...@@ -129,5 +129,5 @@ class Client(Connection):
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
port = int(sys.argv[1]) if len(sys.argv) > 1 else 80 port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
Server(port, loglevel=logging.DEBUG).run() Server(port, loglevel=logging.DEBUG).run()
...@@ -21,7 +21,7 @@ class websocket(object): ...@@ -21,7 +21,7 @@ class websocket(object):
Server example: Server example:
>>> sock = websocket() >>> sock = websocket()
>>> sock.bind(('', 80)) >>> sock.bind(('', 8000))
>>> sock.listen() >>> sock.listen()
>>> client = sock.accept() >>> client = sock.accept()
...@@ -30,7 +30,7 @@ class websocket(object): ...@@ -30,7 +30,7 @@ class websocket(object):
Client example: Client example:
>>> sock = websocket() >>> sock = websocket()
>>> sock.connect(('kompiler.org', 80)) >>> sock.connect(('', 8000))
""" """
def __init__(self, protocols=[], extensions=[], sfamily=socket.AF_INET, def __init__(self, protocols=[], extensions=[], sfamily=socket.AF_INET,
sproto=0): sproto=0):
...@@ -57,7 +57,7 @@ class websocket(object): ...@@ -57,7 +57,7 @@ class websocket(object):
""" """
Equivalent to socket.accept(), but transforms the socket into a Equivalent to socket.accept(), but transforms the socket into a
websocket instance and sends a server handshake (after receiving a websocket instance and sends a server handshake (after receiving a
client handshake). Note that the handshake may raise an HandshakeError client handshake). Note that the handshake may raise a HandshakeError
exception. exception.
""" """
sock, address = self.sock.accept() sock, address = self.sock.accept()
......
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