예제 #1
0
    def test_503(self):
        req = Request('http://www.scrapytest.org/503')
        rsp = Response('http://www.scrapytest.org/503', body='', status=503, request=req)

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

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

        # discard it
        rsp.request = req
        self.assertIs(self.mw.process_response(rsp), rsp)
예제 #2
0
    def test_503(self):
        req = Request('http://www.scrapytest.org/503')
        rsp = Response('http://www.scrapytest.org/503',
                       body='',
                       status=503,
                       request=req)

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

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

        # discard it
        rsp.request = req
        self.assertIs(self.mw.process_response(rsp), rsp)
    def _getresponse(self, coding):
        if coding not in FORMAT:
            raise ValueError()

        sample_file, content_encoding = FORMAT[coding]
        with open(join(SAMPLE_DIR, sample_file), "rb") as sample:
            body = sample.read()

        headers = {
            "Server": "Yaws/1.49 Yet Another Web Server",
            "Date": "Sun, 08 Mar 2009 00:41:03 GMT",
            "Content-Length": len(body),
            "Content-Type": "text/html",
            "Content-Encoding": content_encoding,
        }

        response = Response("http://github.com/", body=body, headers=headers)
        response.request = Request("http://github.com/", headers={"Accept-Encoding": "gzip,deflate"})
        return response
    def _getresponse(self, coding):
        if coding not in FORMAT:
            raise ValueError()

        sample_file, content_encoding = FORMAT[coding]
        with open(join(SAMPLE_DIR, sample_file), 'rb') as sample:
            body = sample.read()

        headers = {
            'Server': 'Yaws/1.49 Yet Another Web Server',
            'Date': 'Sun, 08 Mar 2009 00:41:03 GMT',
            'Content-Length': len(body),
            'Content-Type': 'text/html',
            'Content-Encoding': content_encoding,
        }

        response = Response('http://github.com/', body=body, headers=headers)
        response.request = Request('http://github.com/', headers={'Accept-Encoding': 'gzip,deflate'})
        return response
    def _getresponse(self, coding):
        if coding not in FORMAT:
            raise ValueError()

        sample_file, content_encoding = FORMAT[coding]
        with open(join(SAMPLE_DIR, sample_file), 'rb') as sample:
            body = sample.read()

        headers = {
            'Server': 'Yaws/1.49 Yet Another Web Server',
            'Date': 'Sun, 08 Mar 2009 00:41:03 GMT',
            'Content-Length': len(body),
            'Content-Type': 'text/html',
            'Content-Encoding': content_encoding,
        }

        response = Response('http://github.com/', body=body, headers=headers)
        response.request = Request('http://github.com/',
                                   headers={'Accept-Encoding': 'gzip,deflate'})
        return response