當前位置: 首頁>>代碼示例>>Python>>正文


Python proto_helpers.StringTransportWithDisconnection方法代碼示例

本文整理匯總了Python中twisted.test.proto_helpers.StringTransportWithDisconnection方法的典型用法代碼示例。如果您正苦於以下問題:Python proto_helpers.StringTransportWithDisconnection方法的具體用法?Python proto_helpers.StringTransportWithDisconnection怎麽用?Python proto_helpers.StringTransportWithDisconnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.test.proto_helpers的用法示例。


在下文中一共展示了proto_helpers.StringTransportWithDisconnection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_processWithPort

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def test_processWithPort(self):
        """
        Check that L{ProxyRequest.process} correctly parse port in the incoming
        URL, and create an outgoing connection with this port.
        """
        transport = StringTransportWithDisconnection()
        channel = DummyChannel(transport)
        reactor = MemoryReactor()
        request = ProxyRequest(channel, False, reactor)
        request.gotLength(0)
        request.requestReceived(b'GET', b'http://example.com:1234/foo/bar',
                                b'HTTP/1.0')

        # That should create one connection, with the port parsed from the URL
        self.assertEqual(len(reactor.tcpClients), 1)
        self.assertEqual(reactor.tcpClients[0][0], u"example.com")
        self.assertEqual(reactor.tcpClients[0][1], 1234) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_proxy.py

示例2: test_process

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def test_process(self):
        """
        L{ReverseProxyRequest.process} should create a connection to its
        factory host/port, using a L{ProxyClientFactory} instantiated with the
        correct parameters, and particularly set the B{host} header to the
        factory host.
        """
        transport = StringTransportWithDisconnection()
        channel = DummyChannel(transport)
        reactor = MemoryReactor()
        request = ReverseProxyRequest(channel, False, reactor)
        request.factory = DummyFactory(u"example.com", 1234)
        request.gotLength(0)
        request.requestReceived(b'GET', b'/foo/bar', b'HTTP/1.0')

        # Check that one connection has been created, to the good host/port
        self.assertEqual(len(reactor.tcpClients), 1)
        self.assertEqual(reactor.tcpClients[0][0], u"example.com")
        self.assertEqual(reactor.tcpClients[0][1], 1234)

        # Check the factory passed to the connect, and its headers
        factory = reactor.tcpClients[0][2]
        self.assertIsInstance(factory, ProxyClientFactory)
        self.assertEqual(factory.headers, {b'host': b'example.com'}) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:26,代碼來源:test_proxy.py

示例3: setUp

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def setUp(self):
        """
        Set up XmlStream and several observers.
        """
        self.gotStreamStart = False
        self.gotStreamEnd = False
        self.gotStreamError = False
        xs = xmlstream.XmlStream(xmlstream.Authenticator())
        xs.addObserver('//event/stream/start', self.onStreamStart)
        xs.addObserver('//event/stream/end', self.onStreamEnd)
        xs.addObserver('//event/stream/error', self.onStreamError)
        xs.makeConnection(proto_helpers.StringTransportWithDisconnection())
        xs.transport.protocol = xs
        xs.namespace = 'testns'
        xs.version = (1, 0)
        self.xmlstream = xs 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:test_jabberxmlstream.py

示例4: test_validUNIXHeaderResolves_getPeerHost

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def test_validUNIXHeaderResolves_getPeerHost(self):
        """
        Test if UNIX headers result in the correct host and peer data.
        """
        factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
        proto = factory.buildProtocol(
            address.UNIXAddress(b'/home/test/sockets/server.sock'),
        )
        transport = StringTransportWithDisconnection()
        proto.makeConnection(transport)
        proto.dataReceived(self.UNIXHEADER)
        self.assertEqual(proto.getPeer().name, b'/home/tests/mysockets/sock')
        self.assertEqual(
            proto.wrappedProtocol.transport.getPeer().name,
            b'/home/tests/mysockets/sock',
        )
        self.assertEqual(proto.getHost().name, b'/home/tests/mysockets/sock')
        self.assertEqual(
            proto.wrappedProtocol.transport.getHost().name,
            b'/home/tests/mysockets/sock',
        ) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:23,代碼來源:test_wrapper.py

示例5: test_idleClientDoesDisconnect

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def test_idleClientDoesDisconnect(self):
        """
        The *server* has a timeout mechanism which will close connections that
        are inactive for a period.
        """
        c = Clock()
        # Hook up our server protocol
        transport = StringTransportWithDisconnection()
        transport.protocol = self.server
        self.server.callLater = c.callLater
        self.server.makeConnection(transport)

        # Make sure we can notice when the connection goes away
        lost = []
        connLost = self.server.connectionLost
        self.server.connectionLost = lambda reason: (lost.append(None), connLost(reason))[1]

        # 2/3rds of the idle timeout elapses...
        c.pump([0.0] + [self.server.timeOut / 3.0] * 2)
        self.assertFalse(lost, lost)

        # Now some more
        c.pump([0.0, self.server.timeOut / 2.0])
        self.assertTrue(lost) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:26,代碼來源:test_imap.py

示例6: test_errbacksUponDisconnect

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def test_errbacksUponDisconnect(self):
        """
        Test the ftp command errbacks when a connection lost happens during
        the operation.
        """
        ftpClient = ftp.FTPClient()
        tr = proto_helpers.StringTransportWithDisconnection()
        ftpClient.makeConnection(tr)
        tr.protocol = ftpClient
        d = ftpClient.list('some path', Dummy())
        m = []
        def _eb(failure):
            m.append(failure)
            return None
        d.addErrback(_eb)
        from twisted.internet.main import CONNECTION_LOST
        ftpClient.connectionLost(failure.Failure(CONNECTION_LOST))
        self.assertTrue(m, m)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:21,代碼來源:test_ftp.py

示例7: test_breakReferenceCycle

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def test_breakReferenceCycle(self):
        """
        L{policies.ProtocolWrapper.connectionLost} sets C{wrappedProtocol} to
        C{None} in order to break reference cycle between wrapper and wrapped
        protocols.
        :return:
        """
        wrapper = policies.ProtocolWrapper(policies.WrappingFactory(Server()),
                                           protocol.Protocol())
        transport = StringTransportWithDisconnection()
        transport.protocol = wrapper
        wrapper.makeConnection(transport)

        self.assertIsNotNone(wrapper.wrappedProtocol)
        transport.loseConnection()
        self.assertIsNone(wrapper.wrappedProtocol) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:18,代碼來源:test_policies.py

示例8: getProtocolAndClock

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def getProtocolAndClock(self):
        """
        Helper to set up an already connected protocol to be tested.

        @return: A new protocol with its attached clock.
        @rtype: Tuple of (L{policies.TimeoutProtocol}, L{task.Clock})
        """
        clock = task.Clock()

        wrappedFactory = protocol.ServerFactory()
        wrappedFactory.protocol = SimpleProtocol

        factory = TestableTimeoutFactory(clock, wrappedFactory, None)

        proto = factory.buildProtocol(
            address.IPv4Address('TCP', '127.0.0.1', 12345))

        transport = StringTransportWithDisconnection()
        transport.protocol = proto
        proto.makeConnection(transport)

        return (proto, clock) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:24,代碼來源:test_policies.py

示例9: test_processWithPort

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def test_processWithPort(self):
        """
        Check that L{ProxyRequest.process} correctly parse port in the incoming
        URL, and create a outgoing connection with this port.
        """
        transport = StringTransportWithDisconnection()
        channel = DummyChannel(transport)
        reactor = MemoryReactor()
        request = ProxyRequest(channel, False, reactor)
        request.gotLength(0)
        request.requestReceived('GET', 'http://example.com:1234/foo/bar',
                                'HTTP/1.0')

        # That should create one connection, with the port parsed from the URL
        self.assertEquals(len(reactor.tcpClients), 1)
        self.assertEquals(reactor.tcpClients[0][0], "example.com")
        self.assertEquals(reactor.tcpClients[0][1], 1234) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:19,代碼來源:test_proxy.py

示例10: test_process

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def test_process(self):
        """
        L{ReverseProxyRequest.process} should create a connection to its
        factory host/port, using a L{ProxyClientFactory} instantiated with the
        correct parameters, and particulary set the B{host} header to the
        factory host.
        """
        transport = StringTransportWithDisconnection()
        channel = DummyChannel(transport)
        reactor = MemoryReactor()
        request = ReverseProxyRequest(channel, False, reactor)
        request.factory = DummyFactory("example.com", 1234)
        request.gotLength(0)
        request.requestReceived('GET', '/foo/bar', 'HTTP/1.0')

        # Check that one connection has been created, to the good host/port
        self.assertEquals(len(reactor.tcpClients), 1)
        self.assertEquals(reactor.tcpClients[0][0], "example.com")
        self.assertEquals(reactor.tcpClients[0][1], 1234)

        # Check the factory passed to the connect, and its headers
        factory = reactor.tcpClients[0][2]
        self.assertIsInstance(factory, ProxyClientFactory)
        self.assertEquals(factory.headers, {'host': 'example.com'}) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:26,代碼來源:test_proxy.py

示例11: test_idleClientDoesDisconnect

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def test_idleClientDoesDisconnect(self):
        """
        The *server* has a timeout mechanism which will close connections that
        are inactive for a period.
        """
        c = Clock()
        # Hook up our server protocol
        transport = StringTransportWithDisconnection()
        transport.protocol = self.server
        self.server.callLater = c.callLater
        self.server.makeConnection(transport)

        # Make sure we can notice when the connection goes away
        lost = []
        connLost = self.server.connectionLost
        self.server.connectionLost = lambda reason: (lost.append(None), connLost(reason))[1]

        # 2/3rds of the idle timeout elapses...
        c.pump([0.0] + [self.server.timeOut / 3.0] * 2)
        self.failIf(lost, lost)

        # Now some more
        c.pump([0.0, self.server.timeOut / 2.0])
        self.failUnless(lost) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:26,代碼來源:test_imap.py

示例12: setUp

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def setUp(self):
        factory = socks5.SOCKSv5Factory()
        self.proto = factory.buildProtocol(('127.0.0.1', 0))
        self.tr = proto_helpers.StringTransportWithDisconnection()
        self.tr.protocol = self.proto
        self.proto.makeConnection(self.tr) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:8,代碼來源:test_socks5.py

示例13: _testRender

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def _testRender(self, uri, expectedURI):
        """
        Check that a request pointing at C{uri} produce a new proxy connection,
        with the path of this request pointing at C{expectedURI}.
        """
        root = Resource()
        reactor = MemoryReactor()
        resource = ReverseProxyResource(u"127.0.0.1", 1234, b"/path", reactor)
        root.putChild(b'index', resource)
        site = Site(root)

        transport = StringTransportWithDisconnection()
        channel = site.buildProtocol(None)
        channel.makeConnection(transport)
        # Clear the timeout if the tests failed
        self.addCleanup(channel.connectionLost, None)

        channel.dataReceived(b"GET " +
                             uri +
                             b" HTTP/1.1\r\nAccept: text/html\r\n\r\n")

        # Check that one connection has been created, to the good host/port
        self.assertEqual(len(reactor.tcpClients), 1)
        self.assertEqual(reactor.tcpClients[0][0], u"127.0.0.1")
        self.assertEqual(reactor.tcpClients[0][1], 1234)

        # Check the factory passed to the connect, and its given path
        factory = reactor.tcpClients[0][2]
        self.assertIsInstance(factory, ProxyClientFactory)
        self.assertEqual(factory.rest, expectedURI)
        self.assertEqual(factory.headers[b"host"], b"127.0.0.1:1234") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:33,代碼來源:test_proxy.py

示例14: connectProxy

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def connectProxy(self, proxyClient):
        """
        Connect a proxy client to a L{StringTransportWithDisconnection}.

        @param proxyClient: A L{ProxyClient}.
        @return: The L{StringTransportWithDisconnection}.
        """
        clientTransport = StringTransportWithDisconnection()
        clientTransport.protocol = proxyClient
        proxyClient.makeConnection(clientTransport)
        return clientTransport 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:test_proxy.py

示例15: __init__

# 需要導入模塊: from twisted.test import proto_helpers [as 別名]
# 或者: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 別名]
def __init__(self, user, realm, factory, address=address.IPv4Address('TCP', '127.0.0.1', 54321)):
        self.user = user
        self.transport = proto_helpers.StringTransportWithDisconnection()
        self.protocol = factory.buildProtocol(address)
        self.transport.protocol = self.protocol
        self.user.mind = self.protocol
        self.protocol.makeConnection(self.transport) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:9,代碼來源:test_service.py


注:本文中的twisted.test.proto_helpers.StringTransportWithDisconnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。