From 8ecc6808e01ffd7338bd22a9c2999b972bbd4d56 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Sat, 17 Jan 2009 23:09:53 +0000 Subject: [PATCH] removed Request.context attribute (use Request.meta instead) --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40740 --- scrapy/trunk/docs/ref/request-response.rst | 5 +---- scrapy/trunk/scrapy/contrib/history/middleware.py | 4 ++-- scrapy/trunk/scrapy/http/request.py | 10 +++------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/scrapy/trunk/docs/ref/request-response.rst b/scrapy/trunk/docs/ref/request-response.rst index 49806c3a5..0a9846d24 100644 --- a/scrapy/trunk/docs/ref/request-response.rst +++ b/scrapy/trunk/docs/ref/request-response.rst @@ -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 diff --git a/scrapy/trunk/scrapy/contrib/history/middleware.py b/scrapy/trunk/scrapy/contrib/history/middleware.py index 18c1ec4a0..1cc3fe0cc 100644 --- a/scrapy/trunk/scrapy/contrib/history/middleware.py +++ b/scrapy/trunk/scrapy/contrib/history/middleware.py @@ -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) diff --git a/scrapy/trunk/scrapy/http/request.py b/scrapy/trunk/scrapy/http/request.py index 850a4772f..c0982c11c 100644 --- a/scrapy/trunk/scrapy/http/request.py +++ b/scrapy/trunk/scrapy/http/request.py @@ -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):