Python twisted.internet.error.UserError() Examples

The following are 22 code examples of twisted.internet.error.UserError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted.internet.error , or try the search function .
Example #1
Source File: test_tcp.py    From BitTorrent with GNU General Public License v3.0 6 votes vote down vote up
def testUserFail(self):
        f = MyServerFactory()
        p = reactor.listenTCP(0, f, interface="127.0.0.1")
        n = p.getHost().port
        self.ports.append(p)

        def startedConnecting(connector):
            connector.stopConnecting()

        factory = ClientStartStopFactory()
        factory.startedConnecting = startedConnecting
        reactor.connectTCP("127.0.0.1", n, factory)

        d = loopUntil(lambda :factory.stopped)
        def check(ignored):
            self.assertEquals(factory.failed, 1)
            factory.reason.trap(error.UserError)
            return self.cleanPorts(*self.ports)
        return d.addCallback(check) 
Example #2
Source File: test_tcp.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def test_userFail(self):
        """
        Calling L{IConnector.stopConnecting} in C{Factory.startedConnecting}
        results in C{Factory.clientConnectionFailed} being called with
        L{error.UserError} as the reason.
        """
        serverFactory = MyServerFactory()
        tcpPort = reactor.listenTCP(0, serverFactory, interface="127.0.0.1")
        self.addCleanup(tcpPort.stopListening)
        portNumber = tcpPort.getHost().port

        def startedConnecting(connector):
            connector.stopConnecting()

        clientFactory = ClientStartStopFactory()
        clientFactory.startedConnecting = startedConnecting
        reactor.connectTCP("127.0.0.1", portNumber, clientFactory)

        d = loopUntil(lambda: clientFactory.stopped)
        def check(ignored):
            self.assertEquals(clientFactory.failed, 1)
            clientFactory.reason.trap(error.UserError)
        return d.addCallback(check) 
Example #3
Source File: tcp.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def stopConnecting(self):
        """
        Stop attempt to connect.
        """
        self.failIfNotConnected(error.UserError()) 
Example #4
Source File: gtk2util.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def _windowClosed(self, reason=None):
        if not self.deferredResult.called:
            self.deferredResult.errback(netError.UserError("Window closed.")) 
Example #5
Source File: base.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def stopConnecting(self):
        """Stop attempting to connect."""
        if self.state != "connecting":
            raise error.NotConnectingError, "we're not trying to connect"

        self.state = "disconnected"
        self.transport.failIfNotConnected(error.UserError())
        del self.transport 
Example #6
Source File: client.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def handle_connecting_stopConnecting(self):
        self.connectionFailed(failure.Failure(error.UserError())) 
Example #7
Source File: ConnectionRateLimitReactor.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def stopConnecting(self):
        if self._started:
            self.connector.stopConnecting()
            self._cleanup()
            return            
        self.reactor.drop_postponed(self)
        # for accuracy
        self.factory.startedConnecting(self)
        abort = failure.Failure(error.UserError(string="Connection preempted"))
        self.factory.clientConnectionFailed(self, abort)
        self._cleanup() 
Example #8
Source File: ConnectionRateLimitReactor.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def stopConnecting(self):
        if self._started:
            self.connector.stopConnecting()
            self._cleanup()
            return            
        self.reactor.drop_postponed(self)
        # for accuracy
        self.factory.startedConnecting(self)
        abort = failure.Failure(error.UserError(string="Connection preempted"))
        self.factory.clientConnectionFailed(self, abort)
        self._cleanup() 
Example #9
Source File: gtk2util.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def _cancelled(self):
        if not self.deferredResult.called:
            self.deferredResult.errback(netError.UserError("User hit Cancel."))
        self._loginDialog.destroy() 
Example #10
Source File: base.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def stopConnecting(self):
        """Stop attempting to connect."""
        if self.state != "connecting":
            raise error.NotConnectingError, "we're not trying to connect"

        self.state = "disconnected"
        self.transport.failIfNotConnected(error.UserError())
        del self.transport 
Example #11
Source File: tcp.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def stopConnecting(self):
        """Stop attempt to connect."""
        self.failIfNotConnected(error.UserError()) 
Example #12
Source File: test_client.py    From afkak with Apache License 2.0 5 votes vote down vote up
def test_client_close(self):
        """
        close() terminates any outstanding broker connections, ignoring any
        errors.
        """
        reactor, connections, client = self.client_with_metadata(brokers=[
            BrokerMetadata(1, 'kafka0', 9092),
            BrokerMetadata(2, 'kafka2', 9092),
        ])

        request_d = client.load_metadata_for_topics()
        conn1 = connections.accept('kafka*')
        reactor.advance(client.timeout)  # Time out first attempt, try second broker.
        self.assertNoResult(request_d)
        conn2 = connections.accept('kafka*')
        conn2.client.transport.disconnectReason = UserError()

        close_d = client.close()
        self.assertNoResult(close_d)  # Waiting for connection shutdown.

        connections.flush()  # Complete connection shutdown.
        self.assertIs(None, self.successResultOf(close_d))
        self.assertTrue(conn1.server.transport.disconnected)
        self.assertTrue(conn2.server.transport.disconnected)
        # FIXME Afkak #71: The bootstrap retry loop leaves delayed calls (for timeouts)
        # in the reactor.
        self.assertEqual([], reactor.getDelayedCalls()) 
Example #13
Source File: test_endpoints.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_endpointConnectingCancelled(self):
        """
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} is errbacked with an expected
        L{ConnectingCancelledError} exception.
        """
        mreactor = MemoryReactor()
        clientFactory = protocol.Factory()
        clientFactory.protocol = protocol.Protocol

        ep, ignoredArgs, address = self.createClientEndpoint(
            deterministicResolvingReactor(mreactor, ['127.0.0.1']),
            clientFactory
        )

        d = ep.connect(clientFactory)
        d.cancel()
        # When canceled, the connector will immediately notify its factory that
        # the connection attempt has failed due to a UserError.
        attemptFactory = self.retrieveConnectedFactory(mreactor)
        attemptFactory.clientConnectionFailed(None, Failure(error.UserError()))
        # This should be a feature of MemoryReactor: <http://tm.tl/5630>.

        failure = self.failureResultOf(d)

        self.assertIsInstance(failure.value, error.ConnectingCancelledError)
        self.assertEqual(failure.value.address, address)
        self.assertTrue(mreactor.tcpClients[0][2]._connector.stoppedConnecting)
        self.assertEqual([], mreactor.getDelayedCalls()) 
Example #14
Source File: test_endpoints.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_endpointConnectingCancelled(self, advance=None):
        """
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} will cause it to be errbacked with a
        L{ConnectingCancelledError} exception.
        """
        mreactor = MemoryReactor()

        clientFactory = protocol.Factory()
        clientFactory.protocol = protocol.Protocol

        ep, ignoredArgs, address = self.createClientEndpoint(
            mreactor, clientFactory)

        d = ep.connect(clientFactory)
        if advance is not None:
            mreactor.advance(advance)
        d.cancel()
        # When canceled, the connector will immediately notify its factory that
        # the connection attempt has failed due to a UserError.
        attemptFactory = self.retrieveConnectedFactory(mreactor)
        attemptFactory.clientConnectionFailed(None, Failure(error.UserError()))
        # This should be a feature of MemoryReactor: <http://tm.tl/5630>.

        failure = self.failureResultOf(d)

        self.assertIsInstance(failure.value, error.ConnectingCancelledError)
        self.assertEqual(failure.value.address, address)
        self.assertTrue(mreactor.tcpClients[0][2]._connector.stoppedConnecting)
        self.assertEqual([], mreactor.getDelayedCalls()) 
Example #15
Source File: test_endpoints.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_endpointConnectingCancelled(self):
        """
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} is errbacked with an expected
        L{ConnectingCancelledError} exception.
        """
        mreactor = MemoryReactor()

        clientFactory = object()

        ep, ignoredArgs, address = self.createClientEndpoint(
            mreactor, clientFactory)

        d = ep.connect(clientFactory)

        receivedFailures = []

        def checkFailure(f):
            receivedFailures.append(f)

        d.addErrback(checkFailure)

        d.cancel()
        # When canceled, the connector will immediately notify its factory that
        # the connection attempt has failed due to a UserError.
        attemptFactory = self.retrieveConnectedFactory(mreactor)
        attemptFactory.clientConnectionFailed(None, Failure(error.UserError()))
        # This should be a feature of MemoryReactor: <http://tm.tl/5630>.

        self.assertEqual(len(receivedFailures), 1)

        failure = receivedFailures[0]

        self.assertIsInstance(failure.value, error.ConnectingCancelledError)
        self.assertEqual(failure.value.address, address) 
Example #16
Source File: base.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def stopConnecting(self):
        """Stop attempting to connect."""
        if self.state != "connecting":
            raise error.NotConnectingError("we're not trying to connect")

        self.state = "disconnected"
        self.transport.failIfNotConnected(error.UserError())
        del self.transport 
Example #17
Source File: tcp.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def stopConnecting(self):
        """
        If a connection attempt is still outstanding (i.e.  no connection is
        yet established), immediately stop attempting to connect.
        """
        self.failIfNotConnected(error.UserError()) 
Example #18
Source File: test_endpoints.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_endpointConnectingCancelled(self):
        """
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} is errbacked with an expected
        L{ConnectingCancelledError} exception.
        """
        mreactor = MemoryReactor()
        clientFactory = protocol.Factory()
        clientFactory.protocol = protocol.Protocol

        ep, ignoredArgs, address = self.createClientEndpoint(
            deterministicResolvingReactor(mreactor, ['127.0.0.1']),
            clientFactory
        )

        d = ep.connect(clientFactory)
        d.cancel()
        # When canceled, the connector will immediately notify its factory that
        # the connection attempt has failed due to a UserError.
        attemptFactory = self.retrieveConnectedFactory(mreactor)
        attemptFactory.clientConnectionFailed(None, Failure(error.UserError()))
        # This should be a feature of MemoryReactor: <http://tm.tl/5630>.

        failure = self.failureResultOf(d)

        self.assertIsInstance(failure.value, error.ConnectingCancelledError)
        self.assertEqual(failure.value.address, address)
        self.assertTrue(mreactor.tcpClients[0][2]._connector.stoppedConnecting)
        self.assertEqual([], mreactor.getDelayedCalls()) 
Example #19
Source File: test_endpoints.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_endpointConnectingCancelled(self, advance=None):
        """
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} will cause it to be errbacked with a
        L{ConnectingCancelledError} exception.
        """
        mreactor = MemoryReactor()

        clientFactory = protocol.Factory()
        clientFactory.protocol = protocol.Protocol

        ep, ignoredArgs, address = self.createClientEndpoint(
            mreactor, clientFactory)

        d = ep.connect(clientFactory)
        if advance is not None:
            mreactor.advance(advance)
        d.cancel()
        # When canceled, the connector will immediately notify its factory that
        # the connection attempt has failed due to a UserError.
        attemptFactory = self.retrieveConnectedFactory(mreactor)
        attemptFactory.clientConnectionFailed(None, Failure(error.UserError()))
        # This should be a feature of MemoryReactor: <http://tm.tl/5630>.

        failure = self.failureResultOf(d)

        self.assertIsInstance(failure.value, error.ConnectingCancelledError)
        self.assertEqual(failure.value.address, address)
        self.assertTrue(mreactor.tcpClients[0][2]._connector.stoppedConnecting)
        self.assertEqual([], mreactor.getDelayedCalls()) 
Example #20
Source File: test_endpoints.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_endpointConnectingCancelled(self):
        """
        Calling L{Deferred.cancel} on the L{Deferred} returned from
        L{IStreamClientEndpoint.connect} is errbacked with an expected
        L{ConnectingCancelledError} exception.
        """
        mreactor = MemoryReactor()

        clientFactory = object()

        ep, ignoredArgs, address = self.createClientEndpoint(
            mreactor, clientFactory)

        d = ep.connect(clientFactory)

        receivedFailures = []

        def checkFailure(f):
            receivedFailures.append(f)

        d.addErrback(checkFailure)

        d.cancel()
        # When canceled, the connector will immediately notify its factory that
        # the connection attempt has failed due to a UserError.
        attemptFactory = self.retrieveConnectedFactory(mreactor)
        attemptFactory.clientConnectionFailed(None, Failure(error.UserError()))
        # This should be a feature of MemoryReactor: <http://tm.tl/5630>.

        self.assertEqual(len(receivedFailures), 1)

        failure = receivedFailures[0]

        self.assertIsInstance(failure.value, error.ConnectingCancelledError)
        self.assertEqual(failure.value.address, address) 
Example #21
Source File: base.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def stopConnecting(self):
        """Stop attempting to connect."""
        if self.state != "connecting":
            raise error.NotConnectingError("we're not trying to connect")

        self.state = "disconnected"
        self.transport.failIfNotConnected(error.UserError())
        del self.transport 
Example #22
Source File: tcp.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def stopConnecting(self):
        """
        If a connection attempt is still outstanding (i.e.  no connection is
        yet established), immediately stop attempting to connect.
        """
        self.failIfNotConnected(error.UserError())