Scrapy, a fast high-level web crawling & scraping framework for Python.
Added response type recognition to local file urls
elpolillabc4fcbeab7a9
diff --git a/scrapy/trunk/scrapy/core/downloader/handlers.py b/scrapy/trunk/scrapy/core/downloader/handlers.pyindex cdbc1b95e..f53f62dc2 100644--- a/scrapy/trunk/scrapy/core/downloader/handlers.py+++ b/scrapy/trunk/scrapy/core/downloader/handlers.py@@ -104,5 +104,9 @@ def download_file(request, spider) :"""Return a deferred for a file download."""filepath = request.url.split("file://")[1]with open(filepath) as f:- response = Response(url=request.url, body=f.read())+ body = f.read()+ respcls = responsetypes.from_filename(filepath)+ respcls = responsetypes.from_body(body) if respcls is Response else respcls+ response = respcls(url=request.url, body=body)+return defer_succeed(response)diff --git a/scrapy/trunk/scrapy/core/downloader/responsetypes.py b/scrapy/trunk/scrapy/core/downloader/responsetypes.pyindex 539198422..697a0217f 100644--- a/scrapy/trunk/scrapy/core/downloader/responsetypes.py+++ b/scrapy/trunk/scrapy/core/downloader/responsetypes.py@@ -67,13 +67,10 @@ class ResponseTypes(object):return self.from_mimetype(mimetypes.guess_type(url)[0])def from_body(self, body):- """Try to guess the appropiate response based on the body content.-+ """Try to guess the appropiate response based on the body content.This method is a bit magic and could be improved in the future, butit's not meant to be used except for special cases where response types- cannot be guess using more straightforward methods.-- """+ cannot be guess using more straightforward methods."""chunk = body[:5000]if isbinarytext(chunk):return self.from_mimetype('application/octet-stream')