本文整理汇总了Python中twisted.test.proto_helpers.StringTransport.protocol方法的典型用法代码示例。如果您正苦于以下问题:Python StringTransport.protocol方法的具体用法?Python StringTransport.protocol怎么用?Python StringTransport.protocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.test.proto_helpers.StringTransport
的用法示例。
在下文中一共展示了StringTransport.protocol方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_data_cancels_timeout
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import protocol [as 别名]
def test_data_cancels_timeout(self):
"""
When data is received, the timeout is canceled
"""
clock = Clock()
protocol = HangCheckProtocol(Protocol(), reactor=clock)
transport = StringTransport()
transport.protocol = protocol
protocol.makeConnection(transport)
protocol.dataReceived('some-data')
assert_clock_idle(self, clock)
示例2: test_transport
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import protocol [as 别名]
def test_transport(self):
"""
The transport passed to the underlying protocol is
the underlying transport.
"""
clock = Clock()
wrapped_protocol = Protocol()
protocol = HangCheckProtocol(wrapped_protocol, reactor=clock)
transport = StringTransport()
transport.protocol = protocol
protocol.makeConnection(transport)
self.assertIdentical(wrapped_protocol.transport, transport)
示例3: test_forwards_data
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import protocol [as 别名]
def test_forwards_data(self):
"""
Data received by the protocol gets passed to the wrapped
protocol.
"""
clock = Clock()
wrapped_protocol = AccumulatingProtocol()
protocol = HangCheckProtocol(wrapped_protocol, reactor=clock)
transport = StringTransport()
transport.protocol = protocol
protocol.makeConnection(transport)
protocol.dataReceived('some-data')
self.assertEqual(wrapped_protocol.data, "some-data")
示例4: connect
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import protocol [as 别名]
def connect(self, factory):
"""
Connect the given L{IProtocolFactory} to a L{StringTransport} and
return a fired L{Deferred}.
@param factory: see L{IStreamClientEndpoint}
@return: see L{IStreamClientEndpoint}
"""
protocol = factory.buildProtocol(None)
transport = StringTransport()
transport.protocol = protocol
protocol.makeConnection(transport)
self.transports.append(transport)
return succeed(protocol)
示例5: test_disconnects
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import protocol [as 别名]
def test_disconnects(self):
"""
When connecting to a server that doesn't send any data,
the protocol disconnects after the timeout.
"""
clock = Clock()
protocol = HangCheckProtocol(Protocol(), reactor=clock)
transport = StringTransport()
transport.protocol = protocol
protocol.makeConnection(transport)
clock.advance(120)
self.assertTrue(transport.disconnecting)
assert_clock_idle(self, clock)
示例6: test_disconnect_cancels_timeout
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import protocol [as 别名]
def test_disconnect_cancels_timeout(self):
"""
If the connection is closed, the hang check is cancelled.
"""
clock = Clock()
protocol = HangCheckProtocol(
Protocol(),
reactor=clock,
)
transport = StringTransport()
transport.protocol = protocol
protocol.makeConnection(transport)
protocol.connectionLost(
Failure(ConnectionDone("Bye."))
)
assert_clock_idle(self, clock)
示例7: test_data_and_disconnect
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import protocol [as 别名]
def test_data_and_disconnect(self):
"""
If the connection receives data and then is closed, no error results.
"""
clock = Clock()
protocol = HangCheckProtocol(
Protocol(),
reactor=clock,
)
transport = StringTransport()
transport.protocol = protocol
protocol.makeConnection(transport)
protocol.dataReceived("some-data")
protocol.connectionLost(
Failure(ConnectionDone("Bye."))
)
assert_clock_idle(self, clock)
示例8: test_calls_callback
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import protocol [as 别名]
def test_calls_callback(self):
"""
When connecting to a server that doesn't send any data,
the protocol calls the hung callback.
"""
results = []
clock = Clock()
protocol = HangCheckProtocol(
Protocol(),
hung_callback=lambda: results.append(True),
reactor=clock,
)
transport = StringTransport()
transport.protocol = protocol
protocol.makeConnection(transport)
clock.advance(120)
self.assertEqual(results, [True])
assert_clock_idle(self, clock)
示例9: _timeoutTest
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import protocol [as 别名]
def _timeoutTest(self, onDone, clientFactory):
"""
Connect the clientFactory, and check the timeout on the request.
"""
clock = task.Clock()
client = clientFactory.buildProtocol(
address.IPv4Address('TCP', 'example.net', 25))
client.callLater = clock.callLater
t = StringTransport()
client.makeConnection(t)
t.protocol = client
def check(ign):
self.assertEquals(clock.seconds(), 0.5)
d = self.assertFailure(onDone, smtp.SMTPTimeoutError
).addCallback(check)
# The first call should not trigger the timeout
clock.advance(0.1)
# But this one should
clock.advance(0.4)
return d
示例10: test_disconnect_forwarded
# 需要导入模块: from twisted.test.proto_helpers import StringTransport [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransport import protocol [as 别名]
def test_disconnect_forwarded(self):
"""
If the connection is closed, the underlying protocol is informed.
"""
clock = Clock()
wrapped_protocol = AccumulatingProtocol()
protocol = HangCheckProtocol(wrapped_protocol, reactor=clock)
transport = StringTransport()
transport.protocol = protocol
protocol.makeConnection(transport)
reason = ConnectionDone("Bye.")
protocol.connectionLost(
Failure(reason)
)
self.assertTrue(wrapped_protocol.closed)
self.assertEqual(
wrapped_protocol.closedReason.value,
reason,
)