Python twisted.internet.protocol.ReconnectingClientFactory() Examples
The following are 30
code examples of twisted.internet.protocol.ReconnectingClientFactory().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.internet.protocol
, or try the search function
.
Example #1
Source File: test_factories.py From learn_python3_spider with MIT License | 6 votes |
def test_stopTryingWhenConnected(self): """ If a L{ReconnectingClientFactory} has C{stopTrying} called while it is connected, it does not subsequently attempt to reconnect if the connection is later lost. """ class NoConnectConnector(object): def stopConnecting(self): raise RuntimeError("Shouldn't be called, we're connected.") def connect(self): raise RuntimeError("Shouldn't be reconnecting.") c = ReconnectingClientFactory() c.protocol = Protocol # Let's pretend we've connected: c.buildProtocol(None) # Now we stop trying, then disconnect: c.stopTrying() c.clientConnectionLost(NoConnectConnector(), None) self.assertFalse(c.continueTrying)
Example #2
Source File: test_factories.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def testStopTrying(self): f = Factory() f.protocol = In f.connections = 0 f.allMessages = [] f.goal = 2 f.d = defer.Deferred() c = ReconnectingClientFactory() c.initialDelay = c.delay = 0.2 c.protocol = Out c.howManyTimes = 2 port = self.port = reactor.listenTCP(0, f) PORT = port.getHost().port reactor.connectTCP('127.0.0.1', PORT, c) f.d.addCallback(self._testStopTrying_1, f, c) return f.d
Example #3
Source File: test_factories.py From python-for-android with Apache License 2.0 | 6 votes |
def test_deserializationResetsParameters(self): """ A L{ReconnectingClientFactory} which is unpickled does not have an L{IConnector} and has its reconnecting timing parameters reset to their initial values. """ factory = ReconnectingClientFactory() factory.clientConnectionFailed(FakeConnector(), None) self.addCleanup(factory.stopTrying) serialized = pickle.dumps(factory) unserialized = pickle.loads(serialized) self.assertEqual(unserialized.connector, None) self.assertEqual(unserialized._callID, None) self.assertEqual(unserialized.retries, 0) self.assertEqual(unserialized.delay, factory.initialDelay) self.assertEqual(unserialized.continueTrying, True)
Example #4
Source File: test_factories.py From python-for-android with Apache License 2.0 | 6 votes |
def testStopTrying(self): f = Factory() f.protocol = In f.connections = 0 f.allMessages = [] f.goal = 2 f.d = defer.Deferred() c = ReconnectingClientFactory() c.initialDelay = c.delay = 0.2 c.protocol = Out c.howManyTimes = 2 port = reactor.listenTCP(0, f) self.addCleanup(port.stopListening) PORT = port.getHost().port reactor.connectTCP('127.0.0.1', PORT, c) f.d.addCallback(self._testStopTrying_1, f, c) return f.d
Example #5
Source File: test_factories.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_stopTryingWhenConnected(self): """ If a L{ReconnectingClientFactory} has C{stopTrying} called while it is connected, it does not subsequently attempt to reconnect if the connection is later lost. """ class NoConnectConnector(object): def stopConnecting(self): raise RuntimeError("Shouldn't be called, we're connected.") def connect(self): raise RuntimeError("Shouldn't be reconnecting.") c = ReconnectingClientFactory() c.protocol = Protocol # Let's pretend we've connected: c.buildProtocol(None) # Now we stop trying, then disconnect: c.stopTrying() c.clientConnectionLost(NoConnectConnector(), None) self.assertFalse(c.continueTrying)
Example #6
Source File: test_factories.py From python-for-android with Apache License 2.0 | 5 votes |
def test_serializeWithClock(self): """ The clock attribute of L{ReconnectingClientFactory} is not serialized, and the restored value sets it to the default value, the reactor. """ clock = Clock() original = ReconnectingClientFactory() original.clock = clock reconstituted = pickle.loads(pickle.dumps(original)) self.assertIdentical(reconstituted.clock, None)
Example #7
Source File: test_factories.py From learn_python3_spider with MIT License | 5 votes |
def test_parametrizedClock(self): """ The clock used by L{ReconnectingClientFactory} can be parametrized, so that one can cleanly test reconnections. """ clock = Clock() factory = ReconnectingClientFactory() factory.clock = clock factory.clientConnectionLost(FakeConnector(), None) self.assertEqual(len(clock.calls), 1)
Example #8
Source File: riemann.py From tensor with MIT License | 5 votes |
def clientConnectionLost(self, connector, reason): log.msg('Lost connection. Reason:' + str(reason)) self.proto = None self._do_failover(connector) log.msg('Reconnecting to Riemann on %s:%s' % (connector.host, connector.port)) protocol.ReconnectingClientFactory.clientConnectionLost( self, connector, reason)
Example #9
Source File: riemann.py From tensor with MIT License | 5 votes |
def clientConnectionFailed(self, connector, reason): log.msg('Connection failed. Reason:' + str(reason)) self.proto = None self._do_failover(connector) log.msg('Reconnecting to Riemann on %s:%s' % (connector.host, connector.port)) protocol.ReconnectingClientFactory.clientConnectionFailed( self, connector, reason)
Example #10
Source File: factory.py From yabmp with Apache License 2.0 | 5 votes |
def clientConnectionLost(self, connector, reason): LOG.info('Lost connection. Reason: %s', reason.getErrorMessage()) protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason.getErrorMessage())
Example #11
Source File: factory.py From yabmp with Apache License 2.0 | 5 votes |
def clientConnectionFailed(self, connector, reason): LOG.info('Connection failed. Reason: %s', reason.getErrorMessage()) protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason.getErrorMessage())
Example #12
Source File: xmlstream.py From python-for-android with Apache License 2.0 | 5 votes |
def buildProtocol(self, addr): """ Create a protocol instance. Overrides L{XmlStreamFactoryMixin.buildProtocol} to work with a L{ReconnectingClientFactory}. As this is called upon having an connection established, we are resetting the delay for reconnection attempts when the connection is lost again. """ self.resetDelay() return XmlStreamFactoryMixin.buildProtocol(self, addr)
Example #13
Source File: test_factories.py From python-for-android with Apache License 2.0 | 5 votes |
def test_serializeUnused(self): """ A L{ReconnectingClientFactory} which hasn't been used for anything can be pickled and unpickled and end up with the same state. """ original = ReconnectingClientFactory() reconstituted = pickle.loads(pickle.dumps(original)) self.assertEqual(original.__dict__, reconstituted.__dict__)
Example #14
Source File: highFiveBot.py From IRCBots with MIT License | 5 votes |
def main(): f = protocol.ReconnectingClientFactory() f.protocol = HighFiveBot reactor.connectTCP(serv_ip, serv_port, f) reactor.run()
Example #15
Source File: protocol.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def buildProtocol(self, addr): prot = protocol.ReconnectingClientFactory.buildProtocol(self, addr) # decorate the protocol with a delay reset prot.connectionMade = decorate_func(self.resetDelay, prot.connectionMade) return prot
Example #16
Source File: protocol.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def buildProtocol(self, addr): prot = protocol.ReconnectingClientFactory.buildProtocol(self, addr) # decorate the protocol with a delay reset prot.connectionMade = decorate_func(self.resetDelay, prot.connectionMade) return prot
Example #17
Source File: irc.py From joinmarket-clientserver with GNU General Public License v3.0 | 5 votes |
def clientConnectionLost(self, connector, reason): log.debug('IRC connection lost: ' + str(reason)) if not self.wrapper.give_up: if reactor.running: log.info('Attempting to reconnect...') protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
Example #18
Source File: irc.py From joinmarket-clientserver with GNU General Public License v3.0 | 5 votes |
def clientConnectionFailed(self, connector, reason): log.info('IRC connection failed') if not self.wrapper.give_up: if reactor.running: log.info('Attempting to reconnect...') protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
Example #19
Source File: channels.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def clientConnectionLost(self, connector, reason): print "WARNING: Redis Subscription Connection Lost. Probably dropping messages!" self.dispatch.redis = DisconnectedRedis() protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
Example #20
Source File: channels.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def clientConnectionFailed(self, connector, reason): print "WARNING: Redis Subscription Failed to Reconnect. Probably still dropping messages!" protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
Example #21
Source File: unreal.py From dtella with GNU General Public License v2.0 | 5 votes |
def handleCmd_SERVER(self, prefix, args): if prefix: # Not from our connected server return if self.server_name: # Could be a dupe? Ignore it. return # We got a reply from the our connected IRC server, so our password # was just accepted. Send the Dtella state information into IRC. # Save server name CHECK(args[0]) self.server_name = args[0] LOG.info("IRC Server Name: %s" % self.server_name) # Tell the ReconnectingClientFactory that we're cool self.factory.resetDelay() # This isn't very correct, because the Dtella nicks # haven't been sent yet, but it's the best we can practically do. scfg = getServiceConfig() cloak_checksum = scfg.hostmasker.getChecksum() self.sendLine("NETINFO 0 %d 0 %s 0 0 0 :%s" % (time.time(), cloak_checksum, scfg.network_name)) self.sendLine(":%s EOS" % scfg.my_host)
Example #22
Source File: test_factories.py From learn_python3_spider with MIT License | 5 votes |
def test_serializeUnused(self): """ A L{ReconnectingClientFactory} which hasn't been used for anything can be pickled and unpickled and end up with the same state. """ original = ReconnectingClientFactory() reconstituted = pickle.loads(pickle.dumps(original)) self.assertEqual(original.__dict__, reconstituted.__dict__)
Example #23
Source File: doge.py From IRCBots with MIT License | 5 votes |
def main(): f = protocol.ReconnectingClientFactory() f.protocol = Doge reactor.connectTCP(serv_ip, serv_port, f) reactor.run()
Example #24
Source File: tom.py From IRCBots with MIT License | 5 votes |
def main(): f = protocol.ReconnectingClientFactory() f.protocol = ChiefExecBot reactor.connectTCP(serv_ip, serv_port, f) reactor.run()
Example #25
Source File: burnBot.py From IRCBots with MIT License | 5 votes |
def main(self): f = protocol.ReconnectingClientFactory() f.protocol = burnBot serv_ip, serv_port = self.get_server_info() reactor.connectTCP(serv_ip, serv_port, f) reactor.run()
Example #26
Source File: lurkBot.py From IRCBots with MIT License | 5 votes |
def main(): f = protocol.ReconnectingClientFactory() f.protocol = LurkBot reactor.connectTCP(serv_ip, serv_port, f) reactor.run()
Example #27
Source File: pointBot.py From IRCBots with MIT License | 5 votes |
def main(): serv_ip = 'coop.test.adtran.com' serv_port = 6667 f = protocol.ReconnectingClientFactory() f.protocol = pointBot reactor.connectTCP(serv_ip, serv_port, f) reactor.run()
Example #28
Source File: gooseBot.py From IRCBots with MIT License | 5 votes |
def main(): f = protocol.ReconnectingClientFactory() f.protocol = gooseBot reactor.connectTCP(serv_ip, serv_port, f) reactor.run()
Example #29
Source File: niceBot.py From IRCBots with MIT License | 5 votes |
def main(): f = protocol.ReconnectingClientFactory() f.protocol = complimentBot reactor.connectTCP(serv_ip, serv_port, f) reactor.run()
Example #30
Source File: hangman_bot.py From IRCBots with MIT License | 5 votes |
def main(): f = protocol.ReconnectingClientFactory() f.protocol = hangman reactor.connectTCP("coop.test.adtran.com", 6667, f) reactor.run()