Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

ís_cached fix

samus_c9851d8ec91d
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"""