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


Python error.UserError方法代码示例

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


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

示例1: test_userFail

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
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) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:25,代码来源:test_tcp.py

示例2: testUserFail

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
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) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:21,代码来源:test_tcp.py

示例3: test_client_close

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
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()) 
开发者ID:ciena,项目名称:afkak,代码行数:29,代码来源:test_client.py

示例4: stopConnecting

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
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()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:tcp.py

示例5: stopConnecting

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:base.py

示例6: test_endpointConnectingCancelled

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:37,代码来源:test_endpoints.py

示例7: stopConnecting

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def stopConnecting(self):
        """
        Stop attempt to connect.
        """
        self.failIfNotConnected(error.UserError()) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:7,代码来源:tcp.py

示例8: stopConnecting

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def stopConnecting(self):
        """Stop attempt to connect."""
        self.failIfNotConnected(error.UserError()) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:5,代码来源:tcp.py

示例9: stopConnecting

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
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 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:10,代码来源:base.py

示例10: _cancelled

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def _cancelled(self):
        if not self.deferredResult.called:
            self.deferredResult.errback(netError.UserError("User hit Cancel."))
        self._loginDialog.destroy() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:6,代码来源:gtk2util.py

示例11: stopConnecting

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
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() 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:13,代码来源:ConnectionRateLimitReactor.py

示例12: handle_connecting_stopConnecting

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def handle_connecting_stopConnecting(self):
        self.connectionFailed(failure.Failure(error.UserError())) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:4,代码来源:client.py

示例13: _windowClosed

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import UserError [as 别名]
def _windowClosed(self, reason=None):
        if not self.deferredResult.called:
            self.deferredResult.errback(netError.UserError("Window closed.")) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:5,代码来源:gtk2util.py


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