本文整理汇总了Python中twisted.internet.protocol.Factory.buildProtocol方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.buildProtocol方法的具体用法?Python Factory.buildProtocol怎么用?Python Factory.buildProtocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.Factory
的用法示例。
在下文中一共展示了Factory.buildProtocol方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connectedServerAndClient
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def connectedServerAndClient(self, serverFactory, clientFactory):
"""
Set up an in-memory connection between protocols created by
C{serverFactory} and C{clientFactory}.
@return: A three-tuple. The first element is the protocol created by
C{serverFactory}. The second element is the protocol created by
C{clientFactory}. The third element is the L{IOPump} connecting
them.
"""
clientProtocol = clientFactory.buildProtocol(None)
serverProtocol = serverFactory.buildProtocol(None)
clientTransport = AbortableFakeTransport(
clientProtocol, isServer=False, hostAddress=self.clientAddress,
peerAddress=self.serverAddress)
serverTransport = AbortableFakeTransport(
serverProtocol, isServer=True, hostAddress=self.serverAddress,
peerAddress=self.clientAddress)
pump = connect(
serverProtocol, serverTransport, clientProtocol, clientTransport)
return serverProtocol, clientProtocol, pump
示例2: test_buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def test_buildProtocol(self):
"""
Once the necessary SSH actions have completed successfully,
L{SSHCommandClientEndpoint.connect} uses the factory passed to it to
construct a protocol instance by calling its C{buildProtocol} method
with an address object representing the SSH connection and command
executed.
"""
self.realm.channelLookup[b'session'] = WorkingExecSession
endpoint = self.create()
factory = AddressSpyFactory()
factory.protocol = Protocol
endpoint.connect(factory)
server, client, pump = self.finishConnection()
self.assertIsInstance(factory.address, SSHCommandAddress)
self.assertEqual(server.transport.getHost(), factory.address.server)
self.assertEqual(self.user, factory.address.username)
self.assertEqual(b"/bin/ls -l", factory.address.command)
示例3: test_connectionClosedBeforeSecure
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def test_connectionClosedBeforeSecure(self):
"""
If the connection closes at any point before the SSH transport layer
has finished key exchange (ie, gotten to the point where we may attempt
to authenticate), the L{Deferred} returned by
L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
the reason for the lost connection.
"""
endpoint = SSHCommandClientEndpoint.newConnection(
self.reactor, b"/bin/ls -l", b"dummy user",
self.hostname, self.port, knownHosts=self.knownHosts,
ui=FixedResponseUI(False))
factory = Factory()
factory.protocol = Protocol
d = endpoint.connect(factory)
transport = StringTransport()
factory = self.reactor.tcpClients[0][2]
client = factory.buildProtocol(None)
client.makeConnection(transport)
client.connectionLost(Failure(ConnectionDone()))
self.failureResultOf(d).trap(ConnectionDone)
示例4: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, address):
self.address = address
return Factory.buildProtocol(self, address)
示例5: connect
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def connect(self, factory):
if self.pump is not None:
raise Exception("SingleUseMemoryEndpoint was already used")
try:
protocol = factory.buildProtocol(MemoryAddress())
except:
return fail()
else:
self.pump = connect(
self._server, AbortableFakeTransport(
self._server, isServer=True),
protocol, AbortableFakeTransport(protocol, isServer=False))
return succeed(protocol)
示例6: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
if addr.host not in self.only_ip and "0.0.0.0" not in self.only_ip:
return
return Factory.buildProtocol(self, addr)
示例7: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
if self.status in ("starting up", "generating GUID") and self.only_ip != ["127.0.0.1"]:
return
if addr.host not in self.only_ip and "0.0.0.0" not in self.only_ip:
return
return Factory.buildProtocol(self, addr)
示例8: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
"""
Implement L{Factory.buildProtocol} to return a wrapper protocol that
will capture C{connectionLost} notifications.
@return: a L{Protocol}.
"""
return _WrappedProtocol(self.legacyFactory.buildProtocol(addr), self)
示例9: buildProtocol
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import buildProtocol [as 别名]
def buildProtocol(self, addr):
p = Factory.buildProtocol(self, addr)
p.command_cb = self.command_cb
return p