当前位置: 首页>>代码示例>>Python>>正文


Python endpoints.TCP4ClientEndpoint方法代码示例

本文整理汇总了Python中twisted.internet.endpoints.TCP4ClientEndpoint方法的典型用法代码示例。如果您正苦于以下问题:Python endpoints.TCP4ClientEndpoint方法的具体用法?Python endpoints.TCP4ClientEndpoint怎么用?Python endpoints.TCP4ClientEndpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.endpoints的用法示例。


在下文中一共展示了endpoints.TCP4ClientEndpoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: connect

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [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: createClientEndpoint

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def createClientEndpoint(self, reactor, clientFactory, **connectArgs):
        """
        Create an L{TCP4ClientEndpoint} and return the values needed to verify
        its behavior.

        @param reactor: A fake L{IReactorTCP} that L{TCP4ClientEndpoint} can
            call L{IReactorTCP.connectTCP} on.
        @param clientFactory: The thing that we expect to be passed to our
            L{IStreamClientEndpoint.connect} implementation.
        @param connectArgs: Optional dictionary of arguments to
            L{IReactorTCP.connectTCP}
        """
        address = IPv4Address("TCP", "localhost", 80)

        return (endpoints.TCP4ClientEndpoint(reactor,
                                             address.host,
                                             address.port,
                                             **connectArgs),
                (address.host, address.port, clientFactory,
                 connectArgs.get('timeout', 30),
                 connectArgs.get('bindAddress', None)),
                address) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_endpoints.py

示例3: test_tcp

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def test_tcp(self):
        """
        When passed a TCP strports description, L{endpoints.clientFromString}
        returns a L{TCP4ClientEndpoint} instance initialized with the values
        from the string.
        """
        reactor = object()
        client = endpoints.clientFromString(
            reactor,
            "tcp:host=example.com:port=1234:timeout=7:bindAddress=10.0.0.2")
        self.assertIsInstance(client, endpoints.TCP4ClientEndpoint)
        self.assertIs(client._reactor, reactor)
        self.assertEqual(client._host, "example.com")
        self.assertEqual(client._port, 1234)
        self.assertEqual(client._timeout, 7)
        self.assertEqual(client._bindAddress, ("10.0.0.2", 0)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_endpoints.py

示例4: test_tcpPositionalArgs

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def test_tcpPositionalArgs(self):
        """
        When passed a TCP strports description using positional arguments,
        L{endpoints.clientFromString} returns a L{TCP4ClientEndpoint} instance
        initialized with the values from the string.
        """
        reactor = object()
        client = endpoints.clientFromString(
            reactor,
            "tcp:example.com:1234:timeout=7:bindAddress=10.0.0.2")
        self.assertIsInstance(client, endpoints.TCP4ClientEndpoint)
        self.assertIs(client._reactor, reactor)
        self.assertEqual(client._host, "example.com")
        self.assertEqual(client._port, 1234)
        self.assertEqual(client._timeout, 7)
        self.assertEqual(client._bindAddress, ("10.0.0.2", 0)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_endpoints.py

示例5: test_connectProtocolCreatesFactory

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def test_connectProtocolCreatesFactory(self):
        """
        C{endpoints.connectProtocol} calls the given endpoint's C{connect()}
        method with a factory that will build the given protocol.
        """
        reactor = MemoryReactor()
        endpoint = endpoints.TCP4ClientEndpoint(reactor, "127.0.0.1", 0)
        theProtocol = object()
        endpoints.connectProtocol(endpoint, theProtocol)

        # A TCP connection was made via the given endpoint:
        self.assertEqual(len(reactor.tcpClients), 1)
        # TCP4ClientEndpoint uses a _WrapperFactory around the underlying
        # factory, so we need to unwrap it:
        factory = reactor.tcpClients[0][2]._wrappedFactory
        self.assertIsInstance(factory, protocol.Factory)
        self.assertIs(factory.buildProtocol(None), theProtocol) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_endpoints.py

示例6: secureConnection

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def secureConnection(self):
        """
        Create and return a new SSH connection which has been secured and on
        which authentication has already happened.

        @return: A L{Deferred} which fires with the ready-to-use connection or
            with a failure if something prevents the connection from being
            setup, secured, or authenticated.
        """
        protocol = _CommandTransport(self)
        ready = protocol.connectionReady

        sshClient = TCP4ClientEndpoint(
            self.reactor, nativeString(self.hostname), self.port)

        d = connectProtocol(sshClient, protocol)
        d.addCallback(lambda ignored: ready)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:endpoints.py

示例7: connectableEndpoint

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [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

示例8: broadcast

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def broadcast(small_dir, data):
    d_list = []
    responses = []
    # d = defer.Deferred()

    def gotProtocol(p):
        p.sendLine(data)

    for (kid, ip, port) in small_dir:
        _stats[ip] += 1
        point = TCP4ClientEndpoint(reactor, ip, int(port), timeout=10)
        f = RSCfactory()

        d = point.connect(f)
        d.addCallback(gotProtocol)
        d.addErrback(f.d.errback)
        # f.d.errback

        d_list += [ f.d ]

    d_all = defer.gatherResults(d_list)
    return d_all 
开发者ID:gdanezis,项目名称:rscoin,代码行数:24,代码来源:rsc.py

示例9: endpoint_from_hint_obj

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def endpoint_from_hint_obj(hint, tor, reactor):
    if tor:
        if isinstance(hint, (DirectTCPV1Hint, TorTCPV1Hint)):
            # this Tor object will throw ValueError for non-public IPv4
            # addresses and any IPv6 address
            try:
                return tor.stream_via(hint.hostname, hint.port)
            except ValueError:
                return None
        return None
    if isinstance(hint, DirectTCPV1Hint):
        # avoid DNS lookup unless necessary
        if isIPAddress(hint.hostname):
            return TCP4ClientEndpoint(reactor, hint.hostname, hint.port)
        if isIPv6Address(hint.hostname):
            return TCP6ClientEndpoint(reactor, hint.hostname, hint.port)
        return HostnameEndpoint(reactor, hint.hostname, hint.port)
    return None 
开发者ID:warner,项目名称:magic-wormhole,代码行数:20,代码来源:_hints.py

示例10: test_tcp

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def test_tcp(self):
        """
        When passed a TCP strports description, L{endpointClient} returns a
        L{TCP4ClientEndpoint} instance initialized with the values from the
        string.
        """
        reactor = object()
        client = endpoints.clientFromString(
            reactor,
            "tcp:host=example.com:port=1234:timeout=7:bindAddress=10.0.0.2")
        self.assertIsInstance(client, endpoints.TCP4ClientEndpoint)
        self.assertIdentical(client._reactor, reactor)
        self.assertEquals(client._host, "example.com")
        self.assertEquals(client._port, 1234)
        self.assertEquals(client._timeout, 7)
        self.assertEquals(client._bindAddress, "10.0.0.2") 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:test_endpoints.py

示例11: _create_client_service

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def _create_client_service(self, nodeurl, api_token):
        url = parse(nodeurl)
        wsurl = url.replace(scheme="ws").child("private", "logs", "v1")

        factory = WebSocketClientFactory(
            url=wsurl.to_uri().to_text(),
            headers={
                "Authorization": "{} {}".format("tahoe-lafs", api_token),
            },
        )
        factory.protocol = TahoeLogReader
        factory.streamedlogs = self

        endpoint = TCP4ClientEndpoint(self._reactor, url.host, url.port)
        client_service = ClientService(endpoint, factory, clock=self._reactor)
        return client_service 
开发者ID:gridsync,项目名称:gridsync,代码行数:18,代码来源:streamedlogs.py

示例12: connect_to_log_endpoint

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def connect_to_log_endpoint(reactor, tahoe, real_reactor, protocolClass):
    server_port = fake_log_server(protocolClass)
    server_addr = server_port.getHost()

    # Make sure the streamed logs websocket client can compute the correct ws
    # url.  If it doesn't match the server, the handshake fails.
    tahoe.nodeurl = "http://{}:{}".format(server_addr.host, server_addr.port)
    tahoe.streamedlogs.start(tahoe.nodeurl, tahoe.api_token)
    _, _, client_factory = reactor.connectTCP.call_args[0]

    endpoint = TCP4ClientEndpoint(
        real_reactor,
        # Windows doesn't like to connect to 0.0.0.0.
        "127.0.0.1" if server_addr.host == "0.0.0.0" else server_addr.host,
        server_addr.port,
    )
    return endpoint.connect(client_factory) 
开发者ID:gridsync,项目名称:gridsync,代码行数:19,代码来源:test_streamedlogs.py

示例13: test_binary_messages_dropped

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def test_binary_messages_dropped(reactor, tahoe):
    from twisted.internet import reactor as real_reactor

    server = BinaryMessageServerProtocol()

    client = yield connect_to_log_endpoint(
        reactor, tahoe, real_reactor, lambda: server,
    )
    # client is a _WrappingProtocol because the implementation uses
    # TCP4ClientEndpoint which puts a _WrappingFactory into the reactor.  Then
    # connect_to_log_endpoint takes the _WrappingFactory out of the _mock_
    # reactor it supplied and puts it into a new TCP4ClientEndpoint and uses
    # that against a real reactor.  The connection gets set up and the
    # _WrappingFactory creates a _WrappingProtocol which the new
    # TCP4ClientEndpoint happily hands back to us.
    #
    # Sadly, this hack makes us dependent on the implementation of endpoints,
    # the use of endpoints in streamedlogs.py, and the use of endpoints in
    # connect_to_log_endpoint.
    #
    # Maybe it would be good to try to use twisted.test.iosim instead?  Or
    # build something like RequestTraversalAgent but for Autobahn/WebSocket.
    yield client._wrappedProtocol.is_closed

    assert tahoe.streamedlogs.get_streamed_log_messages() == [] 
开发者ID:gridsync,项目名称:gridsync,代码行数:27,代码来源:test_streamedlogs.py

示例14: connect

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def connect(self):
        log.info('Connecting')
        factory = MQTTFactory(profile=MQTTFactory.PUBLISHER | MQTTFactory.SUBSCRIBER)
        point   = TCP4ClientEndpoint(reactor, self.broker_host, self.broker_port)
        d = point.connect(factory).addCallback(self.gotProtocol)
        d.addErrback(self.on_error) 
开发者ID:daq-tools,项目名称:kotori,代码行数:8,代码来源:twisted.py

示例15: client

# 需要导入模块: from twisted.internet import endpoints [as 别名]
# 或者: from twisted.internet.endpoints import TCP4ClientEndpoint [as 别名]
def client(self, reactor, serverAddress):
        """
        Create a client end point that will connect to the given address.

        @type serverAddress: L{IPv4Address}
        """
        return TCP4ClientEndpoint(reactor, self.interface, serverAddress.port) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_tcp.py


注:本文中的twisted.internet.endpoints.TCP4ClientEndpoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。