Skip to content

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

small ResponseTypes cleanup

Mikhail Korobov02b5182608bb
diff --git a/scrapy/responsetypes.py b/scrapy/responsetypes.py
index b519c56d3..4880cc7b9 100644
--- a/scrapy/responsetypes.py
+++ b/scrapy/responsetypes.py
@@ -1,9 +1,8 @@
"""
This module implements a class which returns the appropriate Response class
based on different criteria.
-
"""
-
+from __future__ import absolute_import
from mimetypes import MimeTypes
from pkgutil import get_data
from io import StringIO
@@ -13,6 +12,7 @@ from scrapy.http import Response
from scrapy.utils.misc import load_object
from scrapy.utils.python import isbinarytext, to_bytes, to_native_str
+
class ResponseTypes(object):
CLASSES = {
@@ -69,11 +69,13 @@ class ResponseTypes(object):
"""Return the most appropriate Response class by looking at the HTTP
headers"""
cls = Response
- if 'Content-Type' in headers:
- cls = self.from_content_type(headers['Content-type'], \
- headers.get('Content-Encoding'))
- if cls is Response and 'Content-Disposition' in headers:
- cls = self.from_content_disposition(headers['Content-Disposition'])
+ if b'Content-Type' in headers:
+ cls = self.from_content_type(
+ content_type=headers[b'Content-type'],
+ content_encoding=headers.get(b'Content-Encoding')
+ )
+ if cls is Response and b'Content-Disposition' in headers:
+ cls = self.from_content_disposition(headers[b'Content-Disposition'])
return cls
def from_filename(self, filename):
@@ -101,7 +103,8 @@ class ResponseTypes(object):
return self.from_mimetype('text')
def from_args(self, headers=None, url=None, filename=None, body=None):
- """Guess the most appropriate Response class based on the given arguments"""
+ """Guess the most appropriate Response class based on
+ the given arguments."""
cls = Response
if headers is not None:
cls = self.from_headers(headers)
diff --git a/tests/py3-ignores.txt b/tests/py3-ignores.txt
index 47abd8004..c51bc5981 100644
--- a/tests/py3-ignores.txt
+++ b/tests/py3-ignores.txt
@@ -30,7 +30,6 @@ tests/test_mail.py
tests/test_pipeline_files.py
tests/test_pipeline_images.py
tests/test_proxy_connect.py
-
tests/test_selector_csstranslator.py
tests/test_selector_lxmldocument.py
tests/test_selector.py