mirror of https://github.com/scrapy/scrapy.git
small ResponseTypes cleanup
This commit is contained in:
parent
06b91da943
commit
02b5182608
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue