本文整理汇总了Python中twisted.internet.protocol.ReconnectingClientFactory.protocol方法的典型用法代码示例。如果您正苦于以下问题:Python ReconnectingClientFactory.protocol方法的具体用法?Python ReconnectingClientFactory.protocol怎么用?Python ReconnectingClientFactory.protocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.ReconnectingClientFactory
的用法示例。
在下文中一共展示了ReconnectingClientFactory.protocol方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testStopTrying
# 需要导入模块: from twisted.internet.protocol import ReconnectingClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ReconnectingClientFactory import protocol [as 别名]
def testStopTrying(self):
f = Factory()
f.protocol = In
f.connections = 0
f.allMessages = []
c = ReconnectingClientFactory()
c.initialDelay = c.delay = 0.2
c.protocol = Out
c.howManyTimes = 2
port = reactor.listenTCP(0, f)
PORT = port.getHost().port
reactor.connectTCP('127.0.0.1', PORT, c)
now = time.time()
while len(f.allMessages) != 2 and (time.time() < now + 10):
reactor.iterate(0.1)
util.wait(defer.maybeDeferred(port.stopListening))
self.assertEquals(len(f.allMessages), 2,
"not enough messages -- %s" % f.allMessages)
self.assertEquals(f.connections, 2,
"Number of successful connections incorrect %d" %
f.connections)
self.assertEquals(f.allMessages, [Out.msgs] * 2)
self.failIf(c.continueTrying, "stopTrying never called or ineffective")
示例2: run
# 需要导入模块: from twisted.internet.protocol import ReconnectingClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ReconnectingClientFactory import protocol [as 别名]
def run(config):
factory = ReconnectingClientFactory()
factory.protocol = RelayToIRC
factory.config = config
reactor.connectTCP(
config["irc"]["host"],
config["irc"]["port"],
factory
)
reactor.run()
示例3: test_stopTryingWhenConnected
# 需要导入模块: from twisted.internet.protocol import ReconnectingClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ReconnectingClientFactory import protocol [as 别名]
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)
示例4: xmlparse
# 需要导入模块: from twisted.internet.protocol import ReconnectingClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ReconnectingClientFactory import protocol [as 别名]
except IOError:
data = ""
return xmlparse(StringIO(data))
def get_last_revision(self):
tree = self.svn("info")
revision = tree.find("//commit").get("revision")
return int(revision)
def revision_info(self, revision):
tree = self.svn("log", "-r", str(revision))
author = tree.find("//author").text
comment = tree.find("//msg").text
return author, comment
if __name__ == "__main__":
from twisted.internet import reactor
from twisted.internet.task import LoopingCall
factory = ReconnectingClientFactory()
factory.protocol = IRCClient
reactor.connectTCP("irc.mycompany.com", 6667, factory)
poller = SVNPoller("http://svn.mycompany.com", "bugs", "carrot")
task = LoopingCall(poller.check)
task.start(1)
reactor.run()
示例5: signedOn
# 需要导入模块: from twisted.internet.protocol import ReconnectingClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ReconnectingClientFactory import protocol [as 别名]
def signedOn(self):
self.factory.instance = self
self.join(self.channel)
print "signed on"
def joined(self, channel):
print "Joined %s" % channel
def say_channel(self, message):
self.say(self.channel, message)
class Remote(xmlrpc.XMLRPC):
def xmlrpc_say(self, message):
if factory.instance:
factory.instance.say_channel(message.encode("utf-8"))
return True
else:
return False
if __name__ == '__main__':
factory = ReconnectingClientFactory()
factory.protocol = RustBot
r = Remote()
from twisted.internet import reactor
reactor.connectTCP('irc.homelien.no',6667,factory)
reactor.listenTCP(5656, server.Site(r), interface="127.0.0.1")
reactor.run()