1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-23 06:04:07 +00:00

added support for unknown file extensions to ResponseTypes.from_filename

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40786
This commit is contained in:
Pablo Hoffman 2009-01-27 13:08:07 +00:00
parent 14e67d59c2
commit 134b867abe
2 changed files with 6 additions and 1 deletions

View File

@ -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 Response
def from_url(self, url):
"""Return the most appropiate Response class from a URL"""

View File

@ -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()