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


Python Factory.forProtocol方法代碼示例

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


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

示例1: connect

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def connect(self, reconnecting=False):
        if self.connecting and not reconnecting:
            return
        self.connecting = True
        end_point = TCP4ClientEndpoint(reactor, self.host, self.port, 10)
        d = end_point.connect(Factory.forProtocol(GraphiteProtocol))

        def success(connection):
            self.connecting = False
            log.info('Connected to {replica}', replica=self)
            self.connection = connection

        def failed(error):
            log.error('Connect to {replica} failed: {error}', replica=self, error=error)
            reactor.callLater(10, self.connect, True)
        d.addCallbacks(success, failed) 
開發者ID:moira-alert,項目名稱:worker,代碼行數:18,代碼來源:graphite.py

示例2: test_deferBadEncodingToConnect

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def test_deferBadEncodingToConnect(self):
        """
        Since any client of L{IStreamClientEndpoint} needs to handle Deferred
        failures from C{connect}, L{HostnameEndpoint}'s constructor will not
        raise exceptions when given bad host names, instead deferring to
        returning a failing L{Deferred} from C{connect}.
        """
        endpoint = endpoints.HostnameEndpoint(
            deterministicResolvingReactor(MemoryReactor(), ['127.0.0.1']),
            b'\xff-garbage-\xff', 80
        )
        deferred = endpoint.connect(Factory.forProtocol(Protocol))
        err = self.failureResultOf(deferred, ValueError)
        self.assertIn("\\xff-garbage-\\xff", str(err))
        endpoint = endpoints.HostnameEndpoint(
            deterministicResolvingReactor(MemoryReactor(), ['127.0.0.1']),
            u'\u2ff0-garbage-\u2ff0', 80
        )
        deferred = endpoint.connect(Factory())
        err = self.failureResultOf(deferred, ValueError)
        self.assertIn("\\u2ff0-garbage-\\u2ff0", str(err)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:23,代碼來源:test_endpoints.py

示例3: test_validUNIXHeaderResolves_getPeerHost

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [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

示例4: connectableEndpoint

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def connectableEndpoint(debug=False):
    """
    Create an endpoint that can be fired on demand.

    @param debug: A flag; whether to dump output from the established
        connection to stdout.
    @type debug: L{bool}

    @return: A client endpoint, and an object that will cause one of the
        L{Deferred}s returned by that client endpoint.
    @rtype: 2-L{tuple} of (L{IStreamClientEndpoint}, L{ConnectionCompleter})
    """
    reactor = MemoryReactorClock()
    clientEndpoint = TCP4ClientEndpoint(reactor, "0.0.0.0", 4321)
    serverEndpoint = TCP4ServerEndpoint(reactor, 4321)
    serverEndpoint.listen(Factory.forProtocol(Protocol))
    return clientEndpoint, ConnectionCompleter(reactor) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:iosim.py

示例5: addCluster

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def addCluster(self, protocol):
        """Add a new stub cluster using the given `protocol`.

        The `protocol` should be an instance of `amp.AMP`.

        :return: py:class:`twisted.test.iosim.IOPump`
        """
        server_factory = Factory.forProtocol(RegionServer)
        server_factory.service = self.rpc
        server = server_factory.buildProtocol(addr=None)
        return iosim.connect(
            server,
            iosim.makeFakeServer(server),
            protocol,
            iosim.makeFakeClient(protocol),
            debug=False,  # Debugging is useful, but too noisy by default.
        ) 
開發者ID:maas,項目名稱:maas,代碼行數:19,代碼來源:fixtures.py

示例6: setUp

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def setUp(self):
        self.reactor = MemoryProcessReactor()
        self.endpoint = endpoints.ProcessEndpoint(self.reactor,
                                                  b'/bin/executable')
        protocol = self.successResultOf(
            self.endpoint.connect(Factory.forProtocol(Protocol))
        )
        self.process = self.reactor.processTransport
        self.endpointTransport = protocol.transport 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:test_endpoints.py

示例7: test_invalidHeaderDisconnects

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def test_invalidHeaderDisconnects(self):
        """
        Test if invalid headers result in connectionLost events.
        """
        factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
        proto = factory.buildProtocol(
            address.IPv4Address('TCP', b'127.1.1.1', 8080),
        )
        transport = StringTransportWithDisconnection()
        transport.protocol = proto
        proto.makeConnection(transport)
        proto.dataReceived(b'NOTPROXY anything can go here\r\n')
        self.assertFalse(transport.connected) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:15,代碼來源:test_wrapper.py

示例8: test_invalidPartialHeaderDisconnects

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def test_invalidPartialHeaderDisconnects(self):
        """
        Test if invalid headers result in connectionLost events.
        """
        factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
        proto = factory.buildProtocol(
            address.IPv4Address('TCP', b'127.1.1.1', 8080),
        )
        transport = StringTransportWithDisconnection()
        transport.protocol = proto
        proto.makeConnection(transport)
        proto.dataReceived(b'PROXY TCP4 1.1.1.1\r\n')
        proto.dataReceived(b'2.2.2.2 8080\r\n')
        self.assertFalse(transport.connected) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:16,代碼來源:test_wrapper.py

示例9: test_validIPv6HeaderResolves_getPeerHost

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def test_validIPv6HeaderResolves_getPeerHost(self):
        """
        Test if IPv6 headers result in the correct host and peer data.
        """
        factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
        proto = factory.buildProtocol(
            address.IPv6Address('TCP', b'::1', 8080),
        )
        transport = StringTransportWithDisconnection()
        proto.makeConnection(transport)
        proto.dataReceived(b'PROXY TCP6 ::1 ::2 8080 8888\r\n')
        self.assertEqual(proto.getPeer().host, b'::1')
        self.assertEqual(proto.getPeer().port, 8080)
        self.assertEqual(
            proto.wrappedProtocol.transport.getPeer().host,
            b'::1',
        )
        self.assertEqual(
            proto.wrappedProtocol.transport.getPeer().port,
            8080,
        )
        self.assertEqual(proto.getHost().host, b'::2')
        self.assertEqual(proto.getHost().port, 8888)
        self.assertEqual(
            proto.wrappedProtocol.transport.getHost().host,
            b'::2',
        )
        self.assertEqual(
            proto.wrappedProtocol.transport.getHost().port,
            8888,
        ) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:33,代碼來源:test_wrapper.py

示例10: test_overflowBytesSentToWrappedProtocol

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def test_overflowBytesSentToWrappedProtocol(self):
        """
        Test if non-header bytes are passed to the wrapped protocol.
        """
        factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
        proto = factory.buildProtocol(
            address.IPv6Address('TCP', b'::1', 8080),
        )
        transport = StringTransportWithDisconnection()
        proto.makeConnection(transport)
        proto.dataReceived(b'PROXY TCP6 ::1 ::2 8080 8888\r\nHTTP/1.1 / GET')
        self.assertEqual(proto.wrappedProtocol.data, b'HTTP/1.1 / GET') 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:14,代碼來源:test_wrapper.py

示例11: test_overflowBytesSentToWrappedProtocolChunks

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def test_overflowBytesSentToWrappedProtocolChunks(self):
        """
        Test if header streaming passes extra data appropriately.
        """
        factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
        proto = factory.buildProtocol(
            address.IPv6Address('TCP', b'::1', 8080),
        )
        transport = StringTransportWithDisconnection()
        proto.makeConnection(transport)
        proto.dataReceived(b'PROXY TCP6 ::1 ::2 ')
        proto.dataReceived(b'8080 8888\r\nHTTP/1.1 / GET')
        self.assertEqual(proto.wrappedProtocol.data, b'HTTP/1.1 / GET') 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:15,代碼來源:test_wrapper.py

示例12: test_overflowBytesSentToWrappedProtocolAfter

# 需要導入模塊: from twisted.internet.protocol import Factory [as 別名]
# 或者: from twisted.internet.protocol.Factory import forProtocol [as 別名]
def test_overflowBytesSentToWrappedProtocolAfter(self):
        """
        Test if wrapper writes all data to wrapped protocol after parsing.
        """
        factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol))
        proto = factory.buildProtocol(
            address.IPv6Address('TCP', b'::1', 8080),
        )
        transport = StringTransportWithDisconnection()
        proto.makeConnection(transport)
        proto.dataReceived(b'PROXY TCP6 ::1 ::2 ')
        proto.dataReceived(b'8080 8888\r\nHTTP/1.1 / GET')
        proto.dataReceived(b'\r\n\r\n')
        self.assertEqual(proto.wrappedProtocol.data, b'HTTP/1.1 / GET\r\n\r\n') 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:16,代碼來源:test_wrapper.py


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