本文整理汇总了Python中twisted.protocols.portforward.ProxyFactory方法的典型用法代码示例。如果您正苦于以下问题:Python portforward.ProxyFactory方法的具体用法?Python portforward.ProxyFactory怎么用?Python portforward.ProxyFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.protocols.portforward
的用法示例。
在下文中一共展示了portforward.ProxyFactory方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vtproxy
# 需要导入模块: from twisted.protocols import portforward [as 别名]
# 或者: from twisted.protocols.portforward import ProxyFactory [as 别名]
def vtproxy():
reactor.listenTCP(lport, portforward.ProxyFactory(dhost, dport))
reactor.run()
示例2: makeService
# 需要导入模块: from twisted.protocols import portforward [as 别名]
# 或者: from twisted.protocols.portforward import ProxyFactory [as 别名]
def makeService(config):
f = portforward.ProxyFactory(config['host'], int(config['dest_port']))
return strports.service(config['port'], f)
示例3: buildProtocol
# 需要导入模块: from twisted.protocols import portforward [as 别名]
# 或者: from twisted.protocols.portforward import ProxyFactory [as 别名]
def buildProtocol(self, addr):
"""
Create the protocol instance, keeps track of it, and makes it use
C{clientFactoryInstance} as client factory.
"""
proto = portforward.ProxyFactory.buildProtocol(self, addr)
self.clientFactoryInstance = TestableProxyClientFactory()
# Force the use of this specific instance
proto.clientProtocolFactory = lambda: self.clientFactoryInstance
self.protoInstance = proto
return proto
示例4: test_registerProducers
# 需要导入模块: from twisted.protocols import portforward [as 别名]
# 或者: from twisted.protocols.portforward import ProxyFactory [as 别名]
def test_registerProducers(self):
"""
The proxy client registers itself as a producer of the proxy server and
vice versa.
"""
# create a ProxyServer instance
addr = address.IPv4Address('TCP', '127.0.0.1', 0)
server = portforward.ProxyFactory('127.0.0.1', 0).buildProtocol(addr)
# set the reactor for this test
reactor = proto_helpers.MemoryReactor()
server.reactor = reactor
# make the connection
serverTransport = proto_helpers.StringTransport()
server.makeConnection(serverTransport)
# check that the ProxyClientFactory is connecting to the backend
self.assertEqual(len(reactor.tcpClients), 1)
# get the factory instance and check it's the one we expect
host, port, clientFactory, timeout, _ = reactor.tcpClients[0]
self.assertIsInstance(clientFactory, portforward.ProxyClientFactory)
# Connect it
client = clientFactory.buildProtocol(addr)
clientTransport = proto_helpers.StringTransport()
client.makeConnection(clientTransport)
# check that the producers are registered
self.assertIs(clientTransport.producer, serverTransport)
self.assertIs(serverTransport.producer, clientTransport)
# check the streaming attribute in both transports
self.assertTrue(clientTransport.streaming)
self.assertTrue(serverTransport.streaming)
示例5: starttcpproxy
# 需要导入模块: from twisted.protocols import portforward [as 别名]
# 或者: from twisted.protocols.portforward import ProxyFactory [as 别名]
def starttcpproxy():
reactor.listenTCP(localport, portforward.ProxyFactory(desthost, destport))
reactor.run()
示例6: testPortforward
# 需要导入模块: from twisted.protocols import portforward [as 别名]
# 或者: from twisted.protocols.portforward import ProxyFactory [as 别名]
def testPortforward(self):
serverProtocol = wire.Echo()
realServerFactory = protocol.ServerFactory()
realServerFactory.protocol = lambda: serverProtocol
realServerPort = reactor.listenTCP(0, realServerFactory,
interface='127.0.0.1')
proxyServerFactory = portforward.ProxyFactory('127.0.0.1',
realServerPort.getHost().port)
proxyServerPort = reactor.listenTCP(0, proxyServerFactory,
interface='127.0.0.1')
nBytes = 1000
received = []
clientProtocol = protocol.Protocol()
clientProtocol.dataReceived = received.extend
clientProtocol.connectionMade = lambda: clientProtocol.transport.write('x' * nBytes)
clientFactory = protocol.ClientFactory()
clientFactory.protocol = lambda: clientProtocol
reactor.connectTCP('127.0.0.1', proxyServerPort.getHost().port,
clientFactory)
c = 0
while len(received) < nBytes and c < 100:
reactor.iterate(0.01)
c += 1
self.assertEquals(''.join(received), 'x' * nBytes)
clientProtocol.transport.loseConnection()
serverProtocol.transport.loseConnection()
return defer.gatherResults([
defer.maybeDeferred(realServerPort.stopListening),
defer.maybeDeferred(proxyServerPort.stopListening)])