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


Python _newclient.ResponseNeverReceived方法代码示例

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


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

示例1: test_onlyRetryIfNoResponseReceived

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

示例2: test_someResponseButNotAll

# 需要导入模块: from twisted.web import _newclient [as 别名]
# 或者: from twisted.web._newclient import ResponseNeverReceived [as 别名]
def test_someResponseButNotAll(self):
        """
        If a partial response was received and the connection is lost, the
        resulting error is L{ResponseFailed}, but not
        L{ResponseNeverReceived}.
        """
        protocol = HTTPClientParser(
            Request(b'HEAD', b'/', _boringHeaders, None),
            lambda ign: None)
        d = protocol._responseDeferred

        protocol.makeConnection(StringTransport())
        protocol.dataReceived(b'2')
        protocol.connectionLost(ConnectionLost())
        return self.assertFailure(d, ResponseFailed).addCallback(
            self.assertIsInstance, ResponseFailed) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_newclient.py

示例3: test_dontRetryIfFailedDueToCancel

# 需要导入模块: from twisted.web import _newclient [as 别名]
# 或者: from twisted.web._newclient import ResponseNeverReceived [as 别名]
def test_dontRetryIfFailedDueToCancel(self):
        """
        If a request failed due to the operation being cancelled,
        C{_shouldRetry} returns C{False} to indicate the request should not be
        retried.
        """
        pool = client.HTTPConnectionPool(None)
        connection = client._RetryingHTTP11ClientProtocol(None, pool)
        exception = ResponseNeverReceived([Failure(defer.CancelledError())])
        self.assertFalse(connection._shouldRetry(b"GET", exception, None)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_agent.py

示例4: test_retryIfFailedDueToNonCancelException

# 需要导入模块: from twisted.web import _newclient [as 别名]
# 或者: from twisted.web._newclient import ResponseNeverReceived [as 别名]
def test_retryIfFailedDueToNonCancelException(self):
        """
        If a request failed with L{ResponseNeverReceived} due to some
        arbitrary exception, C{_shouldRetry} returns C{True} to indicate the
        request should be retried.
        """
        pool = client.HTTPConnectionPool(None)
        connection = client._RetryingHTTP11ClientProtocol(None, pool)
        self.assertTrue(connection._shouldRetry(
            b"GET", ResponseNeverReceived([Failure(Exception())]), None)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_agent.py

示例5: retryAttempt

# 需要导入模块: from twisted.web import _newclient [as 别名]
# 或者: from twisted.web._newclient import ResponseNeverReceived [as 别名]
def retryAttempt(self, willWeRetry):
        """
        Fail a first request, possibly retrying depending on argument.
        """
        protocols = []
        def newProtocol():
            protocol = StubHTTPProtocol()
            protocols.append(protocol)
            return defer.succeed(protocol)

        bodyProducer = object()
        request = client.Request(b"FOO", b"/", client.Headers(), bodyProducer,
                                 persistent=True)
        newProtocol()
        protocol = protocols[0]
        retrier = client._RetryingHTTP11ClientProtocol(protocol, newProtocol)

        def _shouldRetry(m, e, bp):
            self.assertEqual(m, b"FOO")
            self.assertIdentical(bp, bodyProducer)
            self.assertIsInstance(e, (RequestNotSent, ResponseNeverReceived))
            return willWeRetry
        retrier._shouldRetry = _shouldRetry

        d = retrier.request(request)

        # So far, one request made:
        self.assertEqual(len(protocols), 1)
        self.assertEqual(len(protocols[0].requests), 1)

        # Fail the first request:
        protocol.requests[0][1].errback(RequestNotSent())
        return d, protocols 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:35,代码来源:test_agent.py

示例6: test_onlyRetryOnce

# 需要导入模块: from twisted.web import _newclient [as 别名]
# 或者: from twisted.web._newclient import ResponseNeverReceived [as 别名]
def test_onlyRetryOnce(self):
        """
        If a L{client._RetryingHTTP11ClientProtocol} fails more than once on
        an idempotent query before a response is received, it will not retry.
        """
        d, protocols = self.retryAttempt(True)
        self.assertEqual(len(protocols), 2)
        # Fail the second request too:
        protocols[1].requests[0][1].errback(ResponseNeverReceived([]))
        # We didn't retry again:
        self.assertEqual(len(protocols), 2)
        return self.assertFailure(d, ResponseNeverReceived) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_agent.py

示例7: test_cancelBeforeResponse

# 需要导入模块: from twisted.web import _newclient [as 别名]
# 或者: from twisted.web._newclient import ResponseNeverReceived [as 别名]
def test_cancelBeforeResponse(self):
        """
        The L{Deferred} returned by L{HTTP11ClientProtocol.request} will fire
        with a L{ResponseNeverReceived} failure containing a L{CancelledError}
        exception if the request was cancelled before any response headers were
        received.
        """
        transport = StringTransport()
        protocol = HTTP11ClientProtocol()
        protocol.makeConnection(transport)
        result = protocol.request(Request(b'GET', b'/', _boringHeaders, None))
        result.cancel()
        self.assertTrue(transport.aborting)
        return assertWrapperExceptionTypes(
            self, result, ResponseNeverReceived, [CancelledError]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_newclient.py

示例8: errback_catcher

# 需要导入模块: from twisted.web import _newclient [as 别名]
# 或者: from twisted.web._newclient import ResponseNeverReceived [as 别名]
def errback_catcher(self, failure):
            # catch all errback failures,
            self.logger.error(repr(failure))

            if failure.check(ResponseNeverReceived):
                request = failure.request
                url= request.meta['current_url']
                father = request.meta['father']

                self.logger.error('Splash, ResponseNeverReceived for %s, retry in 10s ...', url)
                time.sleep(10)
                if response:
                    response_root_key = response.meta['root_key']
                else:
                    response_root_key = None
                yield SplashRequest(
                    url,
                    self.parse,
                    errback=self.errback_catcher,
                    endpoint='execute',
                    cache_args=['lua_source'],
                    meta={'father': father, 'current_url': url},
                    args=self.build_request_arg(response.cookiejar)
                )

            else:
                print('failure')
                #print(failure)
                print(failure.type) 
开发者ID:CIRCL,项目名称:AIL-framework,代码行数:31,代码来源:TorSplashCrawler.py


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