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


Python error.ConnectionRefusedError方法代碼示例

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


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

示例1: test_updateMetadata_retry

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def test_updateMetadata_retry(self):
        """
        Updating the broker metadata of the client changes the destination of
        the next connection attempt. Any outstanding connections remain until
        then.
        """
        d = self.brokerClient.makeRequest(1, METADATA_REQUEST_1)
        self.assertNoResult(d)
        self.assertEqual([('host', 1234)], self.connections.calls)

        self.brokerClient.updateMetadata(BrokerMetadata(node_id=1, host='other', port=2345))
        self.assertEqual('other', self.brokerClient.host)
        self.assertEqual(2345, self.brokerClient.port)
        # A connection to the new host was *not* triggered.
        self.assertEqual([('host', 1234)], self.connections.calls)

        # Fail the pending connection:
        self.connections.fail('host', ConnectionRefusedError("Nope."))
        # Trigger retry attempt, which happens after a delay:
        self.reactor.advance(self.retryDelay)

        # The retry attempt was made to the new host.
        self.assertEqual([('host', 1234), ('other', 2345)], self.connections.calls) 
開發者ID:ciena,項目名稱:afkak,代碼行數:25,代碼來源:test_brokerclient.py

示例2: test_onlyRetryIfNoResponseReceived

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def test_onlyRetryIfNoResponseReceived(self):
        """
        Only L{RequestNotSent}, L{RequestTransmissionFailed} and
        L{ResponseNeverReceived} exceptions cause a retry.
        """
        pool = client.HTTPConnectionPool(None)
        connection = client._RetryingHTTP11ClientProtocol(None, pool)
        self.assertTrue(connection._shouldRetry(
            b"GET", RequestNotSent(), None))
        self.assertTrue(connection._shouldRetry(
            b"GET", RequestTransmissionFailed([]), None))
        self.assertTrue(connection._shouldRetry(
            b"GET", ResponseNeverReceived([]),None))
        self.assertFalse(connection._shouldRetry(
            b"GET", ResponseFailed([]), None))
        self.assertFalse(connection._shouldRetry(
            b"GET", ConnectionRefusedError(), None)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_agent.py

示例3: test_directConnectionLostCall

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def test_directConnectionLostCall(self):
        """
        If C{connectionLost} is called directly on a port object, it succeeds
        (and doesn't expect the presence of a C{deferred} attribute).

        C{connectionLost} is called by L{reactor.disconnectAll} at shutdown.
        """
        serverFactory = MyServerFactory()
        port = reactor.listenTCP(0, serverFactory, interface="127.0.0.1")
        portNumber = port.getHost().port
        port.connectionLost(None)

        client = MyClientFactory()
        serverFactory.protocolConnectionMade = defer.Deferred()
        client.protocolConnectionMade = defer.Deferred()
        reactor.connectTCP("127.0.0.1", portNumber, client)
        def check(ign):
            client.reason.trap(error.ConnectionRefusedError)
        return client.failDeferred.addCallback(check) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:21,代碼來源:test_tcp.py

示例4: test_connectionFailed

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def test_connectionFailed(self):
        """
        If a connection cannot be established, the L{Deferred} returned by
        L{SSHCommandClientEndpoint.connect} fires with a L{Failure}
        representing the reason for the connection setup failure.
        """
        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)

        factory = self.reactor.tcpClients[0][2]
        factory.clientConnectionFailed(None, Failure(ConnectionRefusedError()))

        self.failureResultOf(d).trap(ConnectionRefusedError) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:20,代碼來源:test_endpoints.py

示例5: setUp

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def setUp(self):
        """
        Setup fake hook-up between pods
        """
        @inlineCallbacks
        def _fakeSubmitRequest(iself, ssl, host, port, request):

            if self.refuseConnection:
                raise MultiFailure((Failure(ConnectionRefusedError()),))
            else:
                pod = (port - 8008) / 100
                inbox = IScheduleInboxResource(self.site.resource, self.theStoreUnderTest(pod), podding=True)
                response = yield inbox.http_POST(SimpleRequest(
                    self.site,
                    "POST",
                    "http://{host}:{port}/podding".format(host=host, port=port),
                    request.headers,
                    request.stream.mem,
                ))
                returnValue(response)

        self.refuseConnection = False
        self.patch(IScheduleRequest, "_submitRequest", _fakeSubmitRequest)
        yield super(TestCrossPodScheduling, self).setUp() 
開發者ID:apple,項目名稱:ccs-calendarserver,代碼行數:26,代碼來源:test_cross_pod_scheduling.py

示例6: test_all_deferreds

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def test_all_deferreds(self):
        # point at a URL that will never connect
        port = allocate_tcp_port()
        w = wormhole.create(APPID, "ws://127.0.0.1:%d/v1" % port, reactor)
        # nothing is listening, but it will take a turn to discover that
        w.allocate_code()
        d1 = w.get_code()
        d2 = w.get_unverified_key()
        d3 = w.get_verifier()
        d4 = w.get_versions()
        d5 = w.get_message()
        yield self.assertSCE(d1, ConnectionRefusedError)
        yield self.assertSCE(d2, ConnectionRefusedError)
        yield self.assertSCE(d3, ConnectionRefusedError)
        yield self.assertSCE(d4, ConnectionRefusedError)
        yield self.assertSCE(d5, ConnectionRefusedError) 
開發者ID:warner,項目名稱:magic-wormhole,代碼行數:18,代碼來源:test_wormhole.py

示例7: test_reconnect

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def test_reconnect(self):
        """
        Calling L{IConnector.connect} in C{Factory.clientConnectionLost} causes
        a new connection attempt to be made.
        """
        serverFactory = ClosingFactory()
        tcpPort = reactor.listenTCP(0, serverFactory, interface="127.0.0.1")
        serverFactory.port = tcpPort
        self.addCleanup(serverFactory.cleanUp)
        portNumber = tcpPort.getHost().port

        clientFactory = MyClientFactory()

        def clientConnectionLost(connector, reason):
            connector.connect()
        clientFactory.clientConnectionLost = clientConnectionLost
        reactor.connectTCP("127.0.0.1", portNumber, clientFactory)

        d = loopUntil(lambda: clientFactory.failed)
        def reconnectFailed(ignored):
            p = clientFactory.protocol
            self.assertEqual((p.made, p.closed), (1, 1))
            clientFactory.reason.trap(error.ConnectionRefusedError)
            self.assertEqual(clientFactory.stopped, 1)
        return d.addCallback(reconnectFailed) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:27,代碼來源:test_tcp.py

示例8: testReconnect

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def testReconnect(self):
        f = ClosingFactory()
        p = reactor.listenTCP(0, f, interface="127.0.0.1")
        n = p.getHost().port
        self.ports.append(p)
        f.port = p

        factory = MyClientFactory()
        d = loopUntil(lambda :p.connected)
        def step1(ignored):
            def clientConnectionLost(c, reason):
                c.connect()
            factory.clientConnectionLost = clientConnectionLost
            reactor.connectTCP("127.0.0.1", n, factory)
            return loopUntil(lambda :factory.failed)

        def step2(ignored):
            p = factory.protocol
            self.assertEquals((p.made, p.closed), (1, 1))
            factory.reason.trap(error.ConnectionRefusedError)
            self.assertEquals(factory.stopped, 1)
            return self.cleanPorts(*self.ports)

        return d.addCallback(step1).addCallback(step2) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:26,代碼來源:test_tcp.py

示例9: test_update_connections_connect_error_is_logged_tersely

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def test_update_connections_connect_error_is_logged_tersely(self):
        service = ClusterClientService(Clock())
        _make_connection = self.patch(service, "_make_connection")
        _make_connection.side_effect = error.ConnectionRefusedError()

        logger = self.useFixture(TwistedLoggerFixture())

        eventloops = {"an-event-loop": [("127.0.0.1", 1234)]}
        yield service._update_connections(eventloops)

        self.assertThat(
            _make_connection,
            MockCalledOnceWith("an-event-loop", ("::ffff:127.0.0.1", 1234)),
        )

        self.assertEqual(
            "Making connections to event-loops: an-event-loop\n"
            "---\n"
            "Event-loop an-event-loop (::ffff:127.0.0.1:1234): Connection "
            "was refused by other side.",
            logger.dump(),
        ) 
開發者ID:maas,項目名稱:maas,代碼行數:24,代碼來源:test_clusterservice.py

示例10: handleCmdConnectFailure

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def handleCmdConnectFailure(self, failure):
        log.error("CMD CONNECT: %s" % failure.getErrorMessage())

        # Map common twisted errors to SOCKS error codes
        if failure.type == error.NoRouteError:
            self.sendReply(SOCKSv5Reply.NetworkUnreachable)
        elif failure.type == error.ConnectionRefusedError:
            self.sendReply(SOCKSv5Reply.ConnectionRefused)
        elif failure.type == error.TCPTimedOutError or failure.type == error.TimeoutError:
            self.sendReply(SOCKSv5Reply.TTLExpired)
        elif failure.type == error.UnsupportedAddressFamily:
            self.sendReply(SOCKSv5Reply.AddressTypeNotSupported)
        elif failure.type == error.ConnectError:
            # Twisted doesn't have a exception defined for EHOSTUNREACH,
            # so the failure is a ConnectError.  Try to catch this case
            # and send a better reply, but fall back to a GeneralFailure.
            reply = SOCKSv5Reply.GeneralFailure
            try:
                import errno
                if hasattr(errno, "EHOSTUNREACH"):
                    if failure.value.osError == errno.EHOSTUNREACH:
                        reply = SOCKSv5Reply.HostUnreachable
                if hasattr(errno, "WSAEHOSTUNREACH"):
                    if failure.value.osError == errno.WSAEHOSTUNREACH:
                        reply = SOCKSv5Reply.HostUnreachable
            except Exception:
                pass
            self.sendReply(reply)
        else:
            self.sendReply(SOCKSv5Reply.GeneralFailure)

        failure.trap(error.NoRouteError, error.ConnectionRefusedError,
                     error.TCPTimedOutError, error.TimeoutError,
                     error.UnsupportedAddressFamily, error.ConnectError) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:36,代碼來源:socks5.py

示例11: test_CmdConnectErrback

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def test_CmdConnectErrback(self):
        """
        Test Unsuccessful Request with a IPv4 CONNECT.
        """

        self.proto.connectClass = self._connectClassIPv4

        # VER = 05, CMD = 01, RSV = 00, ATYPE = 01, DST.ADDR = 127.0.0.1, DST.PORT = 9050
        self._sendMsg("050100017f000001235a")
        self.connectDeferred.errback(Failure(error.ConnectionRefusedError("Foo")))

        self._recvFailureResponse(socks5.SOCKSv5Reply.ConnectionRefused)
        self.assertFalse(self.tr.connected) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:15,代碼來源:test_socks5.py

示例12: test_connectionFailed

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def test_connectionFailed(self):
        """
        The L{Deferred} returned by L{Agent.request} fires with a L{Failure} if
        the TCP connection attempt fails.
        """
        result = self.agent.request(b'GET', b'http://foo/')
        # Cause the connection to be refused
        host, port, factory = self.reactor.tcpClients.pop()[:3]
        factory.clientConnectionFailed(None, Failure(ConnectionRefusedError()))
        self.reactor.advance(10)
        # ^ https://twistedmatrix.com/trac/ticket/8202
        self.failureResultOf(result, ConnectionRefusedError) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:14,代碼來源:test_agent.py

示例13: test_errno

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def test_errno(self):
        """
        L{error.getConnectError} converts based on errno for C{socket.error}.
        """
        self.assertErrnoException(errno.ENETUNREACH, error.NoRouteError)
        self.assertErrnoException(errno.ECONNREFUSED, error.ConnectionRefusedError)
        self.assertErrnoException(errno.ETIMEDOUT, error.TCPTimedOutError)
        if platformType == "win32":
            self.assertErrnoException(errno.WSAECONNREFUSED, error.ConnectionRefusedError)
            self.assertErrnoException(errno.WSAENETUNREACH, error.NoRouteError) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:12,代碼來源:test_error.py

示例14: testFailing

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def testFailing(self):
        clientF = MyClientFactory()
        # XXX we assume no one is listening on TCP port 69
        reactor.connectTCP("127.0.0.1", 69, clientF, timeout=5)
        def check(ignored):
            clientF.reason.trap(error.ConnectionRefusedError)
        return clientF.failDeferred.addCallback(check) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:9,代碼來源:test_tcp.py

示例15: connectionRefused

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ConnectionRefusedError [as 別名]
def connectionRefused(self):
        if self.startedDeferred is not None:
            d, self.startedDeferred = self.startedDeferred, None
            d.errback(error.ConnectionRefusedError("yup"))
        self.refused = 1 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:test_udp.py


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