mirror of https://github.com/scrapy/scrapy.git
Simplify regex conditions
This commit is contained in:
parent
778f1cf84c
commit
962eb11c73
|
|
@ -50,13 +50,12 @@ def gunzip(data):
|
|||
raise
|
||||
return output
|
||||
|
||||
_is_gzipped_re = re.compile(br'^application/(x-)?gzip\b', re.I)
|
||||
_is_octetstream_re = re.compile(br'^(application|binary)/octet-stream\b', re.I)
|
||||
_is_gzipped = re.compile(br'^application/(x-)?gzip\b', re.I).search
|
||||
_is_octetstream = re.compile(br'^(application|binary)/octet-stream\b', re.I).search
|
||||
|
||||
def is_gzipped(response):
|
||||
"""Return True if the response is gzipped, or False otherwise"""
|
||||
ctype = response.headers.get('Content-Type', b'')
|
||||
cenc = response.headers.get('Content-Encoding', b'').lower()
|
||||
return (_is_gzipped_re.search(ctype) is not None or
|
||||
(_is_octetstream_re.search(ctype) is not None and
|
||||
cenc in (b'gzip', b'x-gzip')))
|
||||
return (_is_gzipped(ctype) or
|
||||
(_is_octetstream(ctype) and cenc in (b'gzip', b'x-gzip')))
|
||||
|
|
|
|||
Loading…
Reference in New Issue