Esempio n. 1
0
 def retrieve_response(self, spider, request):
     """Return response if present in cache, or None otherwise."""
     metadata = self._read_meta(spider, request)
     if metadata is None:
         return # not cached
     rpath = self._get_request_path(spider, request)
     with open(join(rpath, 'response_body'), 'rb') as f:
         body = f.read()
     with open(join(rpath, 'response_headers'), 'rb') as f:
         rawheaders = f.read()
     url = metadata['url']
     status = metadata['status']
     headers = Headers(headers_raw_to_dict(rawheaders))
     respcls = responsetypes.from_args(headers=headers, url=url)
     response = respcls(url=url, headers=headers, status=status, body=body)
     return response
Esempio n. 2
0
 def retrieve_response(self, spider, request):
     """Return response if present in cache, or None otherwise."""
     metadata = self._read_meta(spider, request)
     if metadata is None:
         return  # not cached
     rpath = self._get_request_path(spider, request)
     with open(join(rpath, 'response_body'), 'rb') as f:
         body = f.read()
     with open(join(rpath, 'response_headers'), 'rb') as f:
         rawheaders = f.read()
     # We failback to metadata['url'] to support old generated caches. TODO: remove for Scrapy 0.11
     url = metadata.get('response_url') or metadata['url']
     status = metadata['status']
     headers = Headers(headers_raw_to_dict(rawheaders))
     respcls = responsetypes.from_args(headers=headers, url=url)
     response = respcls(url=url, headers=headers, status=status, body=body)
     return response
Esempio n. 3
0
 def retrieve_response(self, spider, request):
     """Return response if present in cache, or None otherwise."""
     metadata = self._read_meta(spider, request)
     if metadata is None:
         return # not cached
     rpath = self._get_request_path(spider, request)
     with open(join(rpath, 'response_body'), 'rb') as f:
         body = f.read()
     with open(join(rpath, 'response_headers'), 'rb') as f:
         rawheaders = f.read()
     # We failback to metadata['url'] to support old generated caches. TODO: remove for Scrapy 0.11
     url = metadata.get('response_url') or metadata['url']
     status = metadata['status']
     headers = Headers(headers_raw_to_dict(rawheaders))
     respcls = responsetypes.from_args(headers=headers, url=url)
     response = respcls(url=url, headers=headers, status=status, body=body)
     return response