From bcf6e5476b13ecaecd0ca2f4f91874798217880d Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Fri, 30 Jan 2009 11:14:08 +0000 Subject: [PATCH] added one more case to responsetypes --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40801 --- .../trunk/scrapy/core/downloader/responsetypes/__init__.py | 5 ++++- scrapy/trunk/scrapy/tests/test_responsetypes.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/scrapy/trunk/scrapy/core/downloader/responsetypes/__init__.py b/scrapy/trunk/scrapy/core/downloader/responsetypes/__init__.py index 89a39fe8b..32550ad3f 100644 --- a/scrapy/trunk/scrapy/core/downloader/responsetypes/__init__.py +++ b/scrapy/trunk/scrapy/core/downloader/responsetypes/__init__.py @@ -31,7 +31,10 @@ class ResponseTypes(object): def from_mimetype(self, mimetype): """Return the most appropiate Response class for the given mimetype""" - return self.classes.get(mimetype, self.classes.get(mimetype.split('/')[0], Response)) + if mimetype is not None: + return self.classes.get(mimetype, self.classes.get(mimetype.split('/')[0], Response)) + else: + return Response def from_content_type(self, content_type): """Return the most appropiate Response class from an HTTP Content-Type diff --git a/scrapy/trunk/scrapy/tests/test_responsetypes.py b/scrapy/trunk/scrapy/tests/test_responsetypes.py index 5a7fd66e8..76c4e7822 100644 --- a/scrapy/trunk/scrapy/tests/test_responsetypes.py +++ b/scrapy/trunk/scrapy/tests/test_responsetypes.py @@ -65,6 +65,9 @@ class ResponseTypesTest(unittest.TestCase): ({'url': 'http://www.example.com/data.csv'}, TextResponse), # headers takes precedence over url ({'headers': Headers({'Content-Type': ['text/html; charset=utf-8']}), 'url': 'http://www.example.com/item/'}, HtmlResponse), + ({'headers': Headers({'Content-Disposition': ['attachment; filename="data.xml.gz"']}), 'url': 'http://www.example.com/page/'}, Response), + + ] for source, cls in mappings: retcls = responsetypes.from_args(**source)