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


Python Failure.request方法代码示例

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


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

示例1: process_response

# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import request [as 别名]
    def process_response(self, response):
        '''Passes response (Response or Failure object) received from
        Downloader thought pipeline middlewares.

        Return value is either Request, Response or Failure object.
        '''
        # we can be sure that response.request is set from the downloader
        request = response.request

        for name, enabled_setting, pr, pf in self._process_response:
            # skip disabled mw through meta
            if not request.meta.get(enabled_setting, True):
                continue
            method = pr if isinstance(response, Response) else pf
            try:
                response = method(response)
            except:
                response = Failure()
            assert response is None or isinstance(response, (Request, Response, Failure)), \
                'Middleware %s.process_request must return None, Response, Request or Failure, got %s' % \
                (method.im_self.__class__.__name__, type(response))
            if response is None:
                method_name = 'process_response()' if method is pr else 'process_failure()'
                failure = Failure(DropRequest(
                    '`%s` pipeline middleware dropped the request in `%s` method' %
                    (name, method_name)))
                failure.request = request
                return failure
            if not isinstance(response, (Response, Failure)):
                return response

            # make sure, request attribute is always set
            response.request = request
        return response
开发者ID:Mimino666,项目名称:crawlmi,代码行数:36,代码来源:pipeline_manager.py

示例2: _test_retry_exception

# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import request [as 别名]
    def _test_retry_exception(self, req, exception):
        failure = Failure(exception)

        # first retry
        failure.request = req
        req = self.mw.process_failure(failure)
        self.assertIsInstance(req, Request)
        self.assertEqual(req.meta['retry_times'], 1)

        # second retry
        failure.request = req
        req = self.mw.process_failure(failure)
        self.assertIsInstance(req, Request)
        self.assertEqual(req.meta['retry_times'], 2)

        # discard it
        failure.request = req
        req = self.mw.process_failure(failure)
        self.assertIs(req, failure)
开发者ID:Mimino666,项目名称:crawlmi,代码行数:21,代码来源:test_pipelines_retry.py

示例3: test_processing

# 需要导入模块: from twisted.python.failure import Failure [as 别名]
# 或者: from twisted.python.failure.Failure import request [as 别名]
    def test_processing(self):
        self.engine.start()
        del self.sp.received[:]

        # normal behavior
        req = Request("http://github.com/")
        resp = Response("", request=req)
        self.engine.response_queue.push(resp)
        self.clock.pump([self.engine.QUEUE_CHECK_FREQUENCY, 0])
        self.check_signals([signals.response_downloaded, signals.response_received])

        # download error
        fail = Failure(Exception())
        fail.request = req
        self.engine.response_queue.push(fail)
        self.clock.pump([self.engine.QUEUE_CHECK_FREQUENCY, 0, 0, 0])
        self.check_signals([signals.failure_received, signals.spider_error])

        # pipeline None
        self.pipeline.resp = lambda req: None
        self.engine.response_queue.push(resp)
        self.clock.pump([self.engine.QUEUE_CHECK_FREQUENCY, 0, 0])
        self.check_signals([signals.response_downloaded, signals.failure_received, signals.spider_error])

        # pipeline request
        self.pipeline.resp = lambda req: Request("http://github.com/")
        self.engine.response_queue.push(resp)
        self.clock.pump([self.engine.QUEUE_CHECK_FREQUENCY, 0, 0])
        self.check_signals([signals.response_downloaded, signals.request_received])
        self.assertEqual(len(self.engine.request_queue), 1)
        self.engine.request_queue.pop()

        # pipeline failure
        self.pipeline.resp = lambda req: Failure(Exception())
        self.engine.response_queue.push(resp)
        self.clock.pump([self.engine.QUEUE_CHECK_FREQUENCY, 0, 0])
        self.check_signals([signals.response_downloaded, signals.failure_received, signals.spider_error])
开发者ID:Mimino666,项目名称:crawlmi,代码行数:39,代码来源:test_engine.py


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