本文整理汇总了Python中twisted.internet.task.Clock.connectTCP方法的典型用法代码示例。如果您正苦于以下问题:Python Clock.connectTCP方法的具体用法?Python Clock.connectTCP怎么用?Python Clock.connectTCP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.task.Clock
的用法示例。
在下文中一共展示了Clock.connectTCP方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_successful_proxy_connect
# 需要导入模块: from twisted.internet.task import Clock [as 别名]
# 或者: from twisted.internet.task.Clock import connectTCP [as 别名]
def test_successful_proxy_connect(self, fake_sleep):
endpoint = Mock()
directlyProvides(endpoint, IStreamClientEndpoint)
component = Component(
transports={
u"type": u"websocket",
u"url": u"ws://127.0.0.1/ws",
u"endpoint": endpoint,
u"proxy": {
u"host": u"10.0.0.0",
u"port": 65000,
},
u"max_retries": 0,
},
is_fatal=lambda _: True,
)
@component.on_join
def joined(session, details):
return session.leave()
def connect(factory, **kw):
return succeed(Mock())
endpoint.connect = connect
# XXX it would actually be nicer if we *could* support
# passing a reactor in here, but the _batched_timer =
# make_batched_timer() stuff (slash txaio in general)
# makes this "hard".
reactor = Clock()
got_proxy_connect = Deferred()
def _tcp(host, port, factory, **kw):
self.assertEqual("10.0.0.0", host)
self.assertEqual(port, 65000)
got_proxy_connect.callback(None)
return endpoint.connect(factory._wrappedFactory)
reactor.connectTCP = _tcp
with replace_loop(reactor):
d = component.start(reactor=reactor)
def done(x):
if not got_proxy_connect.called:
got_proxy_connect.callback(x)
# make sure we fire all our time-outs
d.addCallbacks(done, done)
reactor.advance(3600)
return got_proxy_connect