def classWebSocket(clsName, name): """ Websocket for an instance of the classes Game, Player or Tournament -> used to get the a json with informations about this object """ # should be a websocket wsock = request.environ.get('wsgi.websocket') if not wsock: abort(400, 'Expected Websocket request.') # check if that instance exists if clsName not in wsCls: abort(400, 'Invalid class %s is not in %s' % (clsName, wsCls.keys())) cls = wsCls[clsName] obj = cls.getFromName(name) if obj is None: abort(400, 'Invalid name (%s) for class %s' % (name, clsName)) # register this websocket obj.registerWebSocket(wsock) # send to this websocket obj.sendUpdateToWebSocket(wsock) # loop until the end of this websocket while True: try: wsock.receive() except WebSocketError: BaseClass.removeLoIWebSocket(wsock) break
def __init__(self, name, address, socket): """ Regular Player constructor Parameters: - name: (string) name of the player - address: (string) network address (used once for logging) - socket: (PlayerSocket) PlayerSocket object associated """ # call the Player constructor Player.__init__(self) # waitGame event self._waitingGame = Event() self._waitingGame.clear() # Tournament self._tournament = None # PlayerSocket self._socket = socket # and last, call the BaseClass constructor BaseClass.__init__(self, name) self.logger.info("=================================") self.logger.info(name + " just log in (from " + address + ".")
def test_init(self): b = BaseClass() b.regEvt('add', self.method1) b.exeEvt('add', 4, 2) self.assertTrue(self.method1_called) b.regEvt('str', self.method2) b.exeEvt('str', 0, "string1", "string2") self.assertTrue(self.method2_called)
def classWebSocket(): """ Websocket for the list of instances of the classes Game, Player and Tournament -> used to get the a json with the list of instances of theses classes """ # should be a websocket wsock = request.environ.get('wsgi.websocket') if not wsock: abort(400, 'Expected Websocket request.') # register this websocket BaseClass.registerLoIWebSocket(wsock) # send to this websocket BaseClass.sendListofInstances(wsock) # loop until the end of this websocket while True: try: wsock.receive() except WebSocketError: BaseClass.removeLoIWebSocket(wsock) break
def __init__(self, a): self.a = a BaseClass.__init__(self) self.reset_p()
def __init__(self, a): self.a = a BaseClass.__init__(self) self.playing = False self.reset_p()