Scrapy, a fast high-level web crawling & scraping framework for Python.
added support for unknown file extensions to ResponseTypes.from_filename
Pablo Hoffman134b867abe67
diff --git a/scrapy/trunk/scrapy/core/downloader/responsetypes.py b/scrapy/trunk/scrapy/core/downloader/responsetypes.pyindex 0e2868aec..539198422 100644--- a/scrapy/trunk/scrapy/core/downloader/responsetypes.py+++ b/scrapy/trunk/scrapy/core/downloader/responsetypes.py@@ -57,7 +57,10 @@ class ResponseTypes(object):def from_filename(self, filename):"""Return the most appropiate Response class from a file name"""mimetype, encoding = mimetypes.guess_type(filename)- return self.from_mimetype(mimetype) if encoding is None else Response+ if mimetype and not encoding:+ return self.from_mimetype(mimetype)+ else:+ return Responsedef from_url(self, url):"""Return the most appropiate Response class from a URL"""diff --git a/scrapy/trunk/scrapy/tests/test_responsetypes.py b/scrapy/trunk/scrapy/tests/test_responsetypes.pyindex b956320b9..4941314ee 100644--- a/scrapy/trunk/scrapy/tests/test_responsetypes.py+++ b/scrapy/trunk/scrapy/tests/test_responsetypes.py@@ -12,6 +12,7 @@ class ResponseTypesTest(unittest.TestCase):('file.xml.gz', Response),('file.xml', XmlResponse),('file.html', HtmlResponse),+ ('file.unknownext', Response),]for source, cls in mappings:retcls = responsetypes.from_filename(source)@@ -57,5 +58,6 @@ class ResponseTypesTest(unittest.TestCase):source = Headers(source)retcls = responsetypes.from_headers(source)assert retcls is cls, "%s ==> %s != %s" % (source, retcls, cls)+if __name__ == "__main__":unittest.main()