From c9851d8ec91d5f6ef047814e23b93098ee5f4a91 Mon Sep 17 00:00:00 2001 From: samus_ Date: Tue, 22 Jul 2008 16:11:57 +0000 Subject: [PATCH] =?UTF-8?q?=C3=ADs=5Fcached=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%4086 --- scrapy/trunk/scrapy/contrib/downloadermiddleware/cache.py | 6 +++--- scrapy/trunk/scrapy/xpath/selector.py | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scrapy/trunk/scrapy/contrib/downloadermiddleware/cache.py b/scrapy/trunk/scrapy/contrib/downloadermiddleware/cache.py index 0211b15dc..d478fbe4b 100644 --- a/scrapy/trunk/scrapy/contrib/downloadermiddleware/cache.py +++ b/scrapy/trunk/scrapy/contrib/downloadermiddleware/cache.py @@ -112,7 +112,7 @@ class Cache(object): def is_cached(self, domain, key): pickled_meta = os.path.join(self.requestpath(domain, key), 'pickled_meta') - if os.path.exists(requestpath): + if os.path.exists(pickled_meta): with open(pickled_meta) as f: metadata = cPickle.load(f) if datetime.datetime.utcnow() <= metadata['timestamp'] + datetime.timedelta(seconds=settings.getint('CACHE2_EXPIRATION_SECS')): @@ -128,10 +128,10 @@ class Cache(object): Return response dictionary if request has correspondent cache record; return None if not. """ - requestpath = self.requestpath(domain, key) - if not os.path.exists(requestpath): + if not self.is_cached(domain, key): return None # not cached + requestpath = self.requestpath(domain, key) metadata = responsebody = responseheaders = None with open(os.path.join(requestpath, 'pickled_meta')) as f: metadata = cPickle.load(f) diff --git a/scrapy/trunk/scrapy/xpath/selector.py b/scrapy/trunk/scrapy/xpath/selector.py index bdc30cf89..0081e2044 100644 --- a/scrapy/trunk/scrapy/xpath/selector.py +++ b/scrapy/trunk/scrapy/xpath/selector.py @@ -86,6 +86,10 @@ class XPathSelector(object): class XPathSelectorList(list): """List of XPathSelector objects""" + def __getitem__(self, i): + return '__getitem__' + #return XPathSelectorList(list.__getslice__(self, i, j)) + def x(self, xpath): """Perform the given XPath query on each XPathSelector of the list and return a new (flattened) XPathSelectorList of the results"""