def disconnect(self, *args, **kwargs): if "silent" in kwargs: del kwargs["silent"] if self in _connections: _connections.remove(self) BaseNamespace.disconnect(self, *args, **kwargs)
def __init__(self, collection, *args, **kwargs): """ Collection is an object with the following methods: (optional) collection.do_save(data) self.collection = None """ self.collection = collection BaseNamespace.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): BaseNamespace.__init__(self, *args, **kwargs) BroadcastMixin.__init__(self) try: self.storage = self.request.root.storage except: self.request.root.storage = {} self.storage = self.request.root.storage for var in ['user', 'channel']: if not var in self.storage: self.storage[var] = {}
def __init__(self, environ, ns_name, request=None): self._log = logging.getLogger(self.__class__.__name__) self.uuid = str(uuid.uuid1()) self.user = None self.USER_LIST_METHOD = 'users' self.LOGIN_INFO_METHOD = 'login_info' self.ENTER_USER_METHOD = 'enter' self.EXIT_USER_METHOD = 'exit' self.MESSAGE_LIST_METHOD = 'messages' self.TOP_LIST_METHOD = 'top_list' self.CHAT_METHOD = 'chat' self.REMOVE_MSG_METHOD = 'remove_msg' BaseNamespace.__init__(self, environ, ns_name, request)
def disconnect(self, *args, **kwargs): if self in connections: connections.remove(self) if "dbsession" in self.session and self.session["dbsession"] is not None: self.log("Closing leaked session") self.session["dbsession"].close() # Stupid hack to fix stupid Socket.IO bug. if "silent" in kwargs: del kwargs["silent"] if "room" in self.session: self.session["dbsession"] = dbsession = db.Session(db.engine) try: room = self.get_room() room.remove_user(self) finally: dbsession.close() BaseNamespace.disconnect(self, *args, **kwargs)
def __init__(self, *args, **kwargs): BaseNamespace.__init__(self, *args, **kwargs) BroadcastMixin.__init__(self) self.disconnected = False
def initialize(self, *args, **kwargs): self.headers = {} self.cache_lock = Semaphore() return BaseNamespace.initialize(self, *args, **kwargs)
def __init__(self, *args, **kwargs): if self.name is None: raise Exception('Socket endpoint name is not set') BaseNamespace.__init__(self, *args, **kwargs)
def __init__(self, environ, ns_name, request=None): BaseNamespace.__init__(self, environ, ns_name, request)
def emit(self, *args, **kwargs): if len(args) == 2: args = (args[0], convert_to_jsonable(args[1])) if self not in self.sockets: self.sockets.append(self) BaseNamespace.emit(self, *args, **kwargs)
def setUp(self): self.environ = {} self.environ['socketio'] = MockSocket() self.ns = BaseNamespace(self.environ, '/woot')
def __init__(self, context, env, *args, **kwargs): BaseNamespace.__init__(self, env, *args, **kwargs) BroadcastMixin.__init__(self) self.context = context self.env = env self.gate = None
def disconnect(self, silent=False): if self in self.sockets: self.sockets.remove(self) BaseNamespace.disconnect(self, silent)
def recv_disconnect(self): # print self.socket self.log('client disconnected..') SubscribeTable().discard_all_subs(self) BaseNamespace.recv_disconnect(self)
def setUp(self): server = MockSocketIOServer() self.environ = {} self.environ['socketio'] = MockSocket(server) self.ns = BaseNamespace(self.environ, '/woot')
def disconnect(self, silent): self._exit = True BaseNamespace.disconnect(self, silent)
def disconnect(self, silent = False): if self in self.sockets: self.sockets.remove(self) BaseNamespace.disconnect(self, silent)
def recv_disconnect(self): main_loop.unsubscribe(self) self.players.remove(self.player) self.broadcast_event_not_me('player_left', self.player.id) BaseNamespace.recv_disconnect(self)
class TestBaseNamespace(TestCase): def setUp(self): self.environ = {} self.environ['socketio'] = MockSocket() self.ns = BaseNamespace(self.environ, '/woot') def test_process_packet_disconnect(self): pkt = {'type': 'disconnect', 'endpoint': '/woot' } self.ns.process_packet(pkt) def test_process_packet_connect(self): """processing a connection packet """ pkt = {'type': 'connect', 'endpoint': '/tobi', 'qs': '' } self.ns.process_packet(pkt) # processing a connection packet with query string pkt = {'type': 'connect', 'endpoint': '/test', 'qs': '?test=1' } self.ns.process_packet(pkt) def test_process_packet_heartbeat(self): """processing a heartbeat packet """ pkt = {'type': 'heartbeat', 'endpoint': '' } self.ns.process_packet(pkt) def test_process_packet_message(self): """processing a message packet """ pkt = {'type': 'message', 'endpoint': '', 'data': 'woot'} data = self.ns.process_packet(pkt) self.assertEqual(data, pkt['data']) # processing a message packet with id and endpoint pkt = {'type': 'message', 'id': 5, 'ack': True, 'endpoint': '/tobi', 'data': ''} data = self.ns.process_packet(pkt) self.assertEqual(data, pkt['data']) def test_process_packet_json(self): """processing json packet """ pkt = {'type': 'json', 'endpoint': '', 'data': '2'} data = self.ns.process_packet(pkt) self.assertEqual(data, pkt['data']) # processing json packet with message id and ack data pkt = {'type': 'json', 'id': 1, 'endpoint': '', 'ack': 'data', 'data': {u'a': u'b'}} data = self.ns.process_packet(pkt) self.assertEqual(data, pkt['data']) def test_process_packet_event(self): """processing an event packet """ pkt = {'type': 'event', 'name': 'woot', 'endpoint': '', 'args': []} self.ns.process_packet(pkt) # processing an event packet with message id and ack pkt = {'type': 'event', 'id': 1, 'ack': 'data', 'name': 'tobi', 'endpoint': '', 'args': []} self.ns.process_packet(pkt) def test_process_packet_ack(self): """processing a ack packet """ pkt = {'type': 'ack', 'ackId': 140, 'endpoint': '', 'args': []} self.ns.process_packet(pkt) def test_process_packet_error(self): """processing error packet """ pkt = {'type': 'error', 'reason': '', 'advice': '', 'endpoint': ''} self.ns.process_packet(pkt) pkt = {'type': 'error', 'reason': 'transport not supported', 'advice': '', 'endpoint': ''} self.ns.process_packet(pkt) # processing error packet with reason and advice pkt = {'type': 'error', 'reason': 'unauthorized', 'advice': 'reconnect', 'endpoint': ''} self.ns.process_packet(pkt) # processing error packet with endpoint pkt = {'type': 'error', 'reason': '', 'advice': '', 'endpoint': '/woot'} self.ns.process_packet(pkt) def test_process_packet_message_with_new_line(self): """processing a newline in a message""" pkt = {'type': 'message', 'data': '\n', 'endpoint': ''} self.ns.process_packet(pkt)
class TestBaseNamespace(TestCase): def setUp(self): server = MockSocketIOServer() self.environ = {} self.environ['socketio'] = MockSocket(server) self.ns = BaseNamespace(self.environ, '/woot') def test_process_packet_disconnect(self): pkt = {'type': 'disconnect', 'endpoint': '/woot'} self.ns.process_packet(pkt) def test_process_packet_connect(self): """processing a connection packet """ pkt = {'type': 'connect', 'endpoint': '/tobi', 'qs': ''} self.ns.process_packet(pkt) # processing a connection packet with query string pkt = {'type': 'connect', 'endpoint': '/test', 'qs': '?test=1'} self.ns.process_packet(pkt) def test_process_packet_heartbeat(self): """processing a heartbeat packet """ pkt = {'type': 'heartbeat', 'endpoint': ''} self.ns.process_packet(pkt) def test_process_packet_message(self): """processing a message packet """ pkt = {'type': 'message', 'endpoint': '', 'data': 'woot'} data = self.ns.process_packet(pkt) self.assertEqual(data, pkt['data']) # processing a message packet with id and endpoint pkt = { 'type': 'message', 'id': 5, 'ack': True, 'endpoint': '/tobi', 'data': '' } data = self.ns.process_packet(pkt) self.assertEqual(data, pkt['data']) def test_process_packet_json(self): """processing json packet """ pkt = {'type': 'json', 'endpoint': '', 'data': '2'} data = self.ns.process_packet(pkt) self.assertEqual(data, pkt['data']) # processing json packet with message id and ack data pkt = { 'type': 'json', 'id': 1, 'endpoint': '', 'ack': 'data', 'data': { u'a': u'b' } } data = self.ns.process_packet(pkt) self.assertEqual(data, pkt['data']) def test_process_packet_event(self): """processing an event packet """ pkt = {'type': 'event', 'name': 'woot', 'endpoint': '', 'args': []} self.ns.process_packet(pkt) # processing an event packet with message id and ack pkt = { 'type': 'event', 'id': 1, 'ack': 'data', 'name': 'tobi', 'endpoint': '', 'args': [] } self.ns.process_packet(pkt) def test_process_packet_ack(self): """processing a ack packet """ pkt = {'type': 'ack', 'ackId': 140, 'endpoint': '', 'args': []} self.ns.process_packet(pkt) def test_process_packet_error(self): """processing error packet """ pkt = {'type': 'error', 'reason': '', 'advice': '', 'endpoint': ''} self.ns.process_packet(pkt) pkt = { 'type': 'error', 'reason': 'transport not supported', 'advice': '', 'endpoint': '' } self.ns.process_packet(pkt) # processing error packet with reason and advice pkt = { 'type': 'error', 'reason': 'unauthorized', 'advice': 'reconnect', 'endpoint': '' } self.ns.process_packet(pkt) # processing error packet with endpoint pkt = { 'type': 'error', 'reason': '', 'advice': '', 'endpoint': '/woot' } self.ns.process_packet(pkt) def test_process_packet_message_with_new_line(self): """processing a newline in a message""" pkt = {'type': 'message', 'data': '\n', 'endpoint': ''} self.ns.process_packet(pkt)