def test02_logout(self): """test02_logout test logout, isLogged, and __str__ methods""" user = User(4815162342) self.assertEquals(user.isLogged(), True) user.name = "Joe" user.url = "http://example.org/" user.outfit = "naked" user.privilege = User.ADMIN self.assertEquals(user.isLogged(), True) # Test __str__ self.assertEquals( "%s" % user, "serial = 4815162342, name = Joe, url = http://example.org/, outfit = naked, privilege = %d" % User.ADMIN, ) user.logout() self.assertEquals(user.isLogged(), False) self.assertEquals(user.serial, 0) self.assertEquals(user.name, "anonymous") self.assertEquals(user.url, "") self.assertEquals(user.outfit, "") self.assertEquals(user.privilege, None)
def __init__(self): self._ping_timer = None self.user = User() self.bufferized_packets = [] UGAMEProtocol.__init__(self) self._ping_delay = 5 self.connection_lost_deferred = defer.Deferred()
def __init__(self): self.log = UGAMEClientProtocol.log.get_instance( self, refs=[('User', self, lambda x: x.user.serial if x.user.serial > 0 else None)]) self.user = User() UGAMEProtocol.__init__(self) self._keepalive_delay = 5 self.connection_lost_deferred = defer.Deferred()
def test01_init(self): """test01_init test initialization of object""" user = User(4815162342) self.assertEquals(user.isLogged(), True) self.assertEquals(user.serial, 4815162342) self.assertEquals(user.name, 'anonymous') self.assertEquals(user.url, '') self.assertEquals(user.outfit, '') self.assertEquals(user.privilege, None)
def test01_init(self): """test01_init test initialization of object""" user = User(4815162342) self.assertEquals(user.isLogged(), True) self.assertEquals(user.serial, 4815162342) self.assertEquals(user.name, "anonymous") self.assertEquals(user.url, "") self.assertEquals(user.outfit, "") self.assertEquals(user.privilege, None)
def __init__(self): self.log = UGAMEClientProtocol.log.get_instance( self, refs=[('User', self, lambda x: x.user.serial if x.user.serial > 0 else None)]) self._ping_timer = None self.user = User() self.bufferized_packets = [] UGAMEProtocol.__init__(self) self._ping_delay = 5 self.connection_lost_deferred = defer.Deferred()
def __init__(self): self.log = UGAMEClientProtocol.log.get_instance(self, refs=[ ('User', self, lambda x: x.user.serial if x.user.serial > 0 else None) ]) self.user = User() UGAMEProtocol.__init__(self) self._keepalive_delay = 5 self.connection_lost_deferred = defer.Deferred()
class UGAMEClientProtocol(UGAMEProtocol): """ """ log = log.get_child('UGAMEClientProtocol') def __init__(self): self.log = UGAMEClientProtocol.log.get_instance( self, refs=[('User', self, lambda x: x.user.serial if x.user.serial > 0 else None)]) self.user = User() UGAMEProtocol.__init__(self) self._keepalive_delay = 5 self.connection_lost_deferred = defer.Deferred() def getSerial(self): return self.user.serial def getName(self): return self.user.name def getUrl(self): return self.user.url def getOutfit(self): return self.user.outfit def isLogged(self): return self.user.isLogged() def packetReceived(self, packet): pass def protocolEstablished(self): d = self.factory.established_deferred self.factory.established_deferred = None d.callback(self) self.factory.established_deferred = defer.Deferred() def protocolInvalid(self, server, client): # FIXME: I am not completely sure this method makes sense. You'll # note in ClientServer.test09 in test-clientserver.py.in where I # cover this code, it seems that 'server' and 'client' arguments # are something different entirely. This is because the code that # calls protocolInvalid() in protocol.connectionLost() and # protocol._handleVersion() send strings as 'server' and 'client'. # The test assumes this is the case, but I think someone should # reexamine this code at some point and make sure it is doing what # we really expect. -- bkuhn, 2008-10-13 if not self.factory.established_deferred.called: self.factory.established_deferred.errback((self, server, client), ) def connectionLost(self, reason): self.factory.protocol_instance = None UGAMEProtocol.connectionLost(self, reason) d = self.connection_lost_deferred self.connection_lost_deferred = None d.callback(self) self.connection_lost_deferred = defer.Deferred()
class UGAMEClientProtocol(UGAMEProtocol): """ """ log = log.get_child('UGAMEClientProtocol') def __init__(self): self.log = UGAMEClientProtocol.log.get_instance(self, refs=[ ('User', self, lambda x: x.user.serial if x.user.serial > 0 else None) ]) self.user = User() UGAMEProtocol.__init__(self) self._keepalive_delay = 5 self.connection_lost_deferred = defer.Deferred() def getSerial(self): return self.user.serial def getName(self): return self.user.name def getUrl(self): return self.user.url def getOutfit(self): return self.user.outfit def isLogged(self): return self.user.isLogged() def packetReceived(self, packet): pass def protocolEstablished(self): d = self.factory.established_deferred self.factory.established_deferred = None d.callback(self) self.factory.established_deferred = defer.Deferred() def protocolInvalid(self, server, client): # FIXME: I am not completely sure this method makes sense. You'll # note in ClientServer.test09 in test-clientserver.py.in where I # cover this code, it seems that 'server' and 'client' arguments # are something different entirely. This is because the code that # calls protocolInvalid() in protocol.connectionLost() and # protocol._handleVersion() send strings as 'server' and 'client'. # The test assumes this is the case, but I think someone should # reexamine this code at some point and make sure it is doing what # we really expect. -- bkuhn, 2008-10-13 if not self.factory.established_deferred.called: self.factory.established_deferred.errback((self, server, client),) def connectionLost(self, reason): self.factory.protocol_instance = None UGAMEProtocol.connectionLost(self, reason) d = self.connection_lost_deferred self.connection_lost_deferred = None d.callback(self) self.connection_lost_deferred = defer.Deferred()
def __init__(self): self.log = UGAMEClientProtocol.log.get_instance(self, refs=[ ('User', self, lambda x: x.user.serial if x.user.serial > 0 else None) ]) self._ping_timer = None self.user = User() self.bufferized_packets = [] UGAMEProtocol.__init__(self) self._ping_delay = 5 self.connection_lost_deferred = defer.Deferred()
def __init__(self): self.log = log.getChild( self.__class__.__name__, refs=[("User", self, lambda x: x.user.serial if x.user.serial > 0 else None)] ) self._ping_timer = None self.user = User() self.bufferized_packets = [] UGAMEProtocol.__init__(self) self._ping_delay = 5 self.connection_lost_deferred = defer.Deferred()
def test03_hasPrivilege(self): """test03_hasPrivilege test hasPrivilege method""" user = User(4815162342) self.assertEquals(user.hasPrivilege(None), True) self.assertEquals(user.hasPrivilege(User.ADMIN), False) self.assertEquals(user.hasPrivilege(User.REGULAR), False) user.privilege = User.REGULAR self.assertEquals(user.hasPrivilege(None), True) self.assertEquals(user.hasPrivilege(User.ADMIN), False) self.assertEquals(user.hasPrivilege(User.REGULAR), True) user.privilege = User.ADMIN self.assertEquals(user.hasPrivilege(None), True) self.assertEquals(user.hasPrivilege(User.ADMIN), True) self.assertEquals(user.hasPrivilege(User.REGULAR), True) user.logout() self.assertEquals(user.hasPrivilege(None), True) self.assertEquals(user.hasPrivilege(User.ADMIN), False) self.assertEquals(user.hasPrivilege(User.REGULAR), False)
def test02_logout(self): """test02_logout test logout, isLogged, and __str__ methods""" user = User(4815162342) self.assertEquals(user.isLogged(), True) user.name = "Joe" user.url = "http://example.org/" user.outfit = "naked" user.privilege = User.ADMIN self.assertEquals(user.isLogged(), True) # Test __str__ self.assertEquals( "%s" % user, 'serial = 4815162342, name = Joe, url = http://example.org/, outfit = naked, privilege = %d' % User.ADMIN) user.logout() self.assertEquals(user.isLogged(), False) self.assertEquals(user.serial, 0) self.assertEquals(user.name, 'anonymous') self.assertEquals(user.url, '') self.assertEquals(user.outfit, '') self.assertEquals(user.privilege, None)
class UGAMEClientProtocol(UGAMEProtocol): """ """ log = log.get_child('UGAMEClientProtocol') def __init__(self): self.log = UGAMEClientProtocol.log.get_instance(self, refs=[ ('User', self, lambda x: x.user.serial if x.user.serial > 0 else None) ]) self._ping_timer = None self.user = User() self.bufferized_packets = [] UGAMEProtocol.__init__(self) self._ping_delay = 5 self.connection_lost_deferred = defer.Deferred() def getSerial(self): return self.user.serial def getName(self): return self.user.name def getUrl(self): return self.user.url def getOutfit(self): return self.user.outfit def isLogged(self): return self.user.isLogged() def sendPacket(self, packet): if self.established != 0: self.ping() self.log.debug("sendPacket: %s", packet) self.dataWrite(packet.pack()) else: self.log.debug("sendPacket bufferized %s", packet) self.bufferized_packets.append(packet) def ping(self): if not hasattr(self, "_ping_timer") or not self._ping_timer: return if self._ping_timer.active(): self._ping_timer.reset(self._ping_delay) else: self.log.debug("send ping") self.dataWrite(PacketPing().pack()) self._ping_timer = reactor.callLater(self._ping_delay, self.ping) def protocolEstablished(self): self._ping_timer = reactor.callLater(self._ping_delay, self.ping) d = self.factory.established_deferred self.factory.established_deferred = None d.callback(self) for packet in self.bufferized_packets: self.sendPacket(packet) self.bufferized_packets = [] self.factory.established_deferred = defer.Deferred() def protocolInvalid(self, server, client): # FIXME: I am not completely sure this method makes sense. You'll # note in ClientServer.test09 in test-clientserver.py.in where I # cover this code, it seems that 'server' and 'client' arguments # are something different entirely. This is because the code that # calls protocolInvalid() in protocol.connectionLost() and # protocol._handleVersion() send strings as 'server' and 'client'. # The test assumes this is the case, but I think someone should # reexamine this code at some point and make sure it is doing what # we really expect. -- bkuhn, 2008-10-13 if not self.factory.established_deferred.called: self.factory.established_deferred.errback((self, server, client),) def connectionLost(self, reason): if hasattr(self, "_ping_timer") and self._ping_timer and self._ping_timer.active(): self._ping_timer.cancel() self._ping_timer = None self.factory.protocol_instance = None UGAMEProtocol.connectionLost(self, reason) if not reason.check(error.ConnectionDone): self.log.debug("connectionLost: %s", reason) d = self.connection_lost_deferred self.connection_lost_deferred = None d.callback(self) self.connection_lost_deferred = defer.Deferred()
class UGAMEClientProtocol(UGAMEProtocol): """ """ def __init__(self): self._ping_timer = None self.user = User() self.bufferized_packets = [] UGAMEProtocol.__init__(self) self._ping_delay = 5 self.connection_lost_deferred = defer.Deferred() def getSerial(self): return self.user.serial def getName(self): return self.user.name def getUrl(self): return self.user.url def getOutfit(self): return self.user.outfit def isLogged(self): return self.user.isLogged() def sendPacket(self, packet): if self.established != 0: self.ping() if self.factory.verbose > 2: self.message("%ssendPacket(%d) %s " % ( self._prefix, self.user.serial, packet )) self.dataWrite(packet.pack()) else: if self.factory.verbose > 2: self.message("%ssendPacket bufferized %s " % ( self._prefix, packet )) self.bufferized_packets.append(packet) def ping(self): if not hasattr(self, "_ping_timer") or not self._ping_timer: return if self._ping_timer.active(): self._ping_timer.reset(self._ping_delay) else: if self.factory.verbose > 6: self.message("%ssend ping" % self._prefix) self.dataWrite(PacketPing().pack()) self._ping_timer = reactor.callLater(self._ping_delay, self.ping) def protocolEstablished(self): self._ping_timer = reactor.callLater(self._ping_delay, self.ping) d = self.factory.established_deferred self.factory.established_deferred = None d.callback(self) for packet in self.bufferized_packets: self.sendPacket(packet) self.bufferized_packets = [] self.factory.established_deferred = defer.Deferred() def protocolInvalid(self, server, client): # FIXME: I am not completely sure this method makes sense. You'll # note in ClientServer.test09 in test-clientserver.py.in where I # cover this code, it seems that 'server' and 'client' arguments # are something different entirely. This is because the code that # calls protocolInvalid() in protocol.connectionLost() and # protocol._handleVersion() send strings as 'server' and 'client'. # The test assumes this is the case, but I think someone should # reexamine this code at some point and make sure it is doing what # we really expect. -- bkuhn, 2008-10-13 if not self.factory.established_deferred.called: self.factory.established_deferred.errback((self, server, client),) def connectionLost(self, reason): if hasattr(self, "_ping_timer") and self._ping_timer and self._ping_timer.active(): self._ping_timer.cancel() self._ping_timer = None self.factory.protocol_instance = None UGAMEProtocol.connectionLost(self, reason) if not reason.check(error.ConnectionDone) and self.factory.verbose > 3: self.message("UGAMEClient.connectionLost %s" % reason) d = self.connection_lost_deferred self.connection_lost_deferred = None d.callback(self) self.connection_lost_deferred = defer.Deferred()