mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-26 17:04:07 +00:00
removed Request.context attribute (use Request.meta instead)
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40740
This commit is contained in:
parent
7e640da433
commit
8ecc6808e0
@ -21,7 +21,7 @@ generated the request.
|
||||
Request objects
|
||||
===============
|
||||
|
||||
.. class:: Request(url, callback=None, context=None, method='GET', body=None, headers=None, cookies=None, url_encoding='utf-8', dont_filter=None)
|
||||
.. class:: Request(url, callback=None, method='GET', body=None, headers=None, cookies=None, url_encoding='utf-8', dont_filter=None)
|
||||
|
||||
A :class:`Request` object represents an HTTP request, which is usually
|
||||
generated in the Spider and executed by the Downloader, and thus generating
|
||||
@ -32,9 +32,6 @@ Request objects
|
||||
``callback`` is a function that will be called with the response of this
|
||||
request (once its downloaded) as its first parameter
|
||||
|
||||
``context`` can be a dict which will be accessible in the callback function
|
||||
in ``response.request.context`` in the callback function
|
||||
|
||||
``method`` is a string with the HTTP method of this request
|
||||
|
||||
``body`` is a string containing the request body or None if the request
|
||||
|
@ -31,10 +31,10 @@ class HistoryMiddleware(object):
|
||||
d = datetime.now() - last_checked
|
||||
if d.days < self.MIN_CHECK_DAYS:
|
||||
raise IgnoreRequest("Not scraping %s (scraped %s ago)" % (request.url, d))
|
||||
request.context['history_response_version'] = version
|
||||
request.meta['history_response_version'] = version
|
||||
|
||||
def process_response(self, request, response, spider):
|
||||
version = request.context.get('history_response_version')
|
||||
version = request.meta.get('history_response_version')
|
||||
if version == self.get_version(response):
|
||||
del request.content['history_response_version']
|
||||
hist = self.historydata.version_info(domain, version)
|
||||
|
@ -17,7 +17,7 @@ from scrapy.utils.defer import chain_deferred
|
||||
|
||||
class Request(object):
|
||||
|
||||
def __init__(self, url, callback=None, context=None, method='GET',
|
||||
def __init__(self, url, callback=None, method='GET',
|
||||
body=None, headers=None, cookies=None,
|
||||
url_encoding='utf-8', dont_filter=None, domain=None):
|
||||
|
||||
@ -40,8 +40,6 @@ class Request(object):
|
||||
self.cookies = cookies or {}
|
||||
# request headers
|
||||
self.headers = Headers(headers or {}, encoding=url_encoding)
|
||||
# persistent context across requests
|
||||
self.context = context or {}
|
||||
# dont_filter be filtered by scheduler
|
||||
self.dont_filter = dont_filter
|
||||
#allows to directly specify the spider for the request
|
||||
@ -75,20 +73,18 @@ class Request(object):
|
||||
'headers': self.headers,
|
||||
'cookies': self.cookies,
|
||||
'body': self.body,
|
||||
'context': self.context
|
||||
}
|
||||
return "%s(%s)" % (self.__class__.__name__, repr(d))
|
||||
|
||||
def copy(self):
|
||||
"""Clone request except `context` attribute"""
|
||||
"""Return a new request cloned from this one"""
|
||||
new = copy.copy(self)
|
||||
new.cache = {}
|
||||
for att in self.__dict__:
|
||||
if att not in ['cache', 'context', 'url', 'deferred']:
|
||||
if att not in ['cache', 'url', 'deferred']:
|
||||
value = getattr(self, att)
|
||||
setattr(new, att, copy.copy(value))
|
||||
new.deferred = defer.Deferred()
|
||||
new.context = self.context # requests shares same context dictionary
|
||||
return new
|
||||
|
||||
def httprepr(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user