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


Python failure.trap方法代码示例

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


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

示例1: ftp_PORT

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def ftp_PORT(self, address):
        addr = tuple(map(int, address.split(',')))
        ip = '%d.%d.%d.%d' % tuple(addr[:4])
        port = addr[4] << 8 | addr[5]

        # if we have a DTP port set up, lose it.
        if self.dtpFactory is not None:
            self.cleanupDTP()

        self.dtpFactory = DTPFactory(pi=self, peerHost=self.transport.getPeer().host)
        self.dtpFactory.setTimeout(self.dtpTimeout)
        self.dtpPort = reactor.connectTCP(ip, port, self.dtpFactory)

        def connected(ignored):
            return ENTERING_PORT_MODE
        def connFailed(err):
            err.trap(PortConnectionError)
            return CANT_OPEN_DATA_CNX
        return self.dtpFactory.deferred.addCallbacks(connected, connFailed) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:ftp.py

示例2: testFailedStartTLS

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def testFailedStartTLS(self):
        failures = []
        def breakServerTLS(ign):
            self.server.canStartTLS = False

        self.connected.addCallback(breakServerTLS)
        self.connected.addCallback(lambda ign: self.client.startTLS())
        self.connected.addErrback(
            lambda err: failures.append(err.trap(imap4.IMAP4Exception)))
        self.connected.addCallback(self._cbStopClient)
        self.connected.addErrback(self._ebGeneral)

        def check(ignored):
            self.assertTrue(failures)
            self.assertIdentical(failures[0], imap4.IMAP4Exception)
        return self.loopback().addCallback(check) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_imap.py

示例3: test_serverTimeout

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def test_serverTimeout(self):
        """
        The *client* has a timeout mechanism which will close connections that
        are inactive for a period.
        """
        c = Clock()
        self.server.timeoutTest = True
        self.client.timeout = 5 #seconds
        self.client.callLater = c.callLater
        self.selectedArgs = None

        def login():
            d = self.client.login(b'testuser', b'password-test')
            c.advance(5)
            d.addErrback(timedOut)
            return d

        def timedOut(failure):
            self._cbStopClient(None)
            failure.trap(error.TimeoutError)

        d = self.connected.addCallback(strip(login))
        d.addErrback(self._ebGeneral)
        return defer.gatherResults([d, self.loopback()]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_imap.py

示例4: _ebRoundRobinBackoff

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def _ebRoundRobinBackoff(self, failure, fakeProto):
        failure.trap(defer.TimeoutError)

        # Assert that each server is tried with a particular timeout
        # before the timeout is increased and the attempts are repeated.

        for t in (1, 3, 11, 45):
            tries = fakeProto.queries[:len(self.testServers)]
            del fakeProto.queries[:len(self.testServers)]

            tries.sort()
            expected = list(self.testServers)
            expected.sort()

            for ((addr, query, timeout, id), expectedAddr) in zip(tries, expected):
                self.assertEqual(addr, (expectedAddr, 53))
                self.assertEqual(timeout, t)

        self.assertFalse(fakeProto.queries) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_client.py

示例5: test_errbackAddedBeforeTimeoutSuppressesCancellation

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def test_errbackAddedBeforeTimeoutSuppressesCancellation(self):
        """
        An errback added before a timeout is added errbacks with a
        L{defer.CancelledError} when the timeout fires.  If the
        errback suppresses the L{defer.CancelledError}, the deferred
        successfully completes.
        """
        clock = Clock()
        d = defer.Deferred()

        dErrbacked = [None]

        def errback(f):
            dErrbacked[0] = f
            f.trap(defer.CancelledError)

        d.addErrback(errback)
        d.addTimeout(10, clock)

        clock.advance(15)

        self.assertIsInstance(dErrbacked[0], failure.Failure)
        self.assertIsInstance(dErrbacked[0].value, defer.CancelledError)

        self.successResultOf(d) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:test_defer.py

示例6: test_waitUntilLockedWithTimeoutUnlocked

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def test_waitUntilLockedWithTimeoutUnlocked(self):
        """
        Test that a lock can be acquired while a lock is held
        but the lock is unlocked before our timeout.
        """
        def onTimeout(f):
            f.trap(defer.TimeoutError)
            self.fail("Should not have timed out")

        self.assertTrue(self.lock.lock())

        self.clock.callLater(1, self.lock.unlock)
        d = self.lock.deferUntilLocked(timeout=10)
        d.addErrback(onTimeout)

        self.clock.pump([1] * 10)

        return d 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:20,代码来源:test_defer.py

示例7: ftp_PORT

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def ftp_PORT(self, address):
        addr = map(int, address.split(','))
        ip = '%d.%d.%d.%d' % tuple(addr[:4])
        port = addr[4] << 8 | addr[5]

        # if we have a DTP port set up, lose it.
        if self.dtpFactory is not None:
            self.cleanupDTP()

        self.dtpFactory = DTPFactory(pi=self, peerHost=self.transport.getPeer().host)
        self.dtpFactory.setTimeout(self.dtpTimeout)
        self.dtpPort = reactor.connectTCP(ip, port, self.dtpFactory)

        def connected(ignored):
            return ENTERING_PORT_MODE
        def connFailed(err):
            err.trap(PortConnectionError)
            return CANT_OPEN_DATA_CNX
        return self.dtpFactory.deferred.addCallbacks(connected, connFailed) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:ftp.py

示例8: test_serverTimeout

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def test_serverTimeout(self):
        """
        The *client* has a timeout mechanism which will close connections that
        are inactive for a period.
        """
        c = Clock()
        self.server.timeoutTest = True
        self.client.timeout = 5 #seconds
        self.client.callLater = c.callLater
        self.selectedArgs = None

        def login():
            d = self.client.login('testuser', 'password-test')
            c.advance(5)
            d.addErrback(timedOut)
            return d

        def timedOut(failure):
            self._cbStopClient(None)
            failure.trap(error.TimeoutError)

        d = self.connected.addCallback(strip(login))
        d.addErrback(self._ebGeneral)
        return defer.gatherResults([d, self.loopback()]) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:26,代码来源:test_imap.py

示例9: testServerTimeout

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def testServerTimeout(self):
        self.server.timeoutTest = True
        self.client.timeout = 5 #seconds
        self.selectedArgs = None

        def login():
            d = self.client.login('testuser', 'password-test')
            d.addErrback(timedOut)
            return d

        def timedOut(failure):
            self._cbStopClient(None)
            failure.trap(error.TimeoutError)

        d = self.connected.addCallback(strip(login))
        d.addErrback(self._ebGeneral)
        self.loopback() 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:19,代码来源:test_imap.py

示例10: ftp_PASS

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def ftp_PASS(self, password):
        """
        Second part of login.  Get the password the peer wants to
        authenticate with.
        """
        if self.factory.allowAnonymous and self._user == self.factory.userAnonymous:
            # anonymous login
            creds = credentials.Anonymous()
            reply = GUEST_LOGGED_IN_PROCEED
        else:
            # user login
            creds = credentials.UsernamePassword(self._user, password)
            reply = USR_LOGGED_IN_PROCEED
        del self._user

        def _cbLogin(result):
            (interface, avatar, logout) = result
            assert interface is IFTPShell, "The realm is busted, jerk."
            self.shell = avatar
            self.logout = logout
            self.workingDirectory = []
            self.state = self.AUTHED
            return reply

        def _ebLogin(failure):
            failure.trap(cred_error.UnauthorizedLogin, cred_error.UnhandledCredentials)
            self.state = self.UNAUTH
            raise AuthorizationError

        d = self.portal.login(creds, None, IFTPShell)
        d.addCallbacks(_cbLogin, _ebLogin)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:34,代码来源:ftp.py

示例11: _unwrapFirstError

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def _unwrapFirstError(failure):
    failure.trap(defer.FirstError)
    return failure.value.subFailure 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:5,代码来源:ftp.py

示例12: _rcodeTest

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def _rcodeTest(self, rcode, exc):
        m = dns.Message(rCode=rcode)
        err = self.resolver.filterAnswers(m)
        err.trap(exc) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:test_client.py

示例13: test_circularChainException

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def test_circularChainException(self):
        """
        If the deprecation warning for circular deferred callbacks is
        configured to be an error, the exception will become the failure
        result of the Deferred.
        """
        self.addCleanup(setattr, warnings, "filters", warnings.filters)
        warnings.filterwarnings("error", category=DeprecationWarning)
        d = defer.Deferred()
        def circularCallback(result):
            return d
        d.addCallback(circularCallback)
        d.callback("foo")
        failure = self.failureResultOf(d)
        failure.trap(DeprecationWarning) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_defer.py

示例14: _check

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def _check(self):
        """
        Check the output of the log observer to see if the error is present.
        """
        c2 = self._loggedErrors()
        self.assertEqual(len(c2), 2)
        c2[1]["failure"].trap(ZeroDivisionError)
        self.flushLoggedErrors(ZeroDivisionError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_defer.py

示例15: test_chainedErrorCleanup

# 需要导入模块: from twisted.python import failure [as 别名]
# 或者: from twisted.python.failure import trap [as 别名]
def test_chainedErrorCleanup(self):
        """
        If one Deferred with an error result is returned from a callback on
        another Deferred, when the first Deferred is garbage collected it does
        not log its error.
        """
        d = defer.Deferred()
        d.addCallback(lambda ign: defer.fail(RuntimeError("zoop")))
        d.callback(None)

        # Sanity check - this isn't too interesting, but we do want the original
        # Deferred to have gotten the failure.
        results = []
        errors = []
        d.addCallbacks(results.append, errors.append)
        self.assertEqual(results, [])
        self.assertEqual(len(errors), 1)
        errors[0].trap(Exception)

        # Get rid of any references we might have to the inner Deferred (none of
        # these should really refer to it, but we're just being safe).
        del results, errors, d
        # Force a collection cycle so that there's a chance for an error to be
        # logged, if it's going to be logged.
        gc.collect()
        # And make sure it is not.
        self.assertEqual(self._loggedErrors(), []) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:29,代码来源:test_defer.py


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