Skip to content

Commit

Permalink
pylint related change
Browse files Browse the repository at this point in the history
  • Loading branch information
heorhiikorzh committed Nov 13, 2023
1 parent 123c8ab commit fcbc7fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
25 changes: 12 additions & 13 deletions scrapy/downloadermiddlewares/httpcompression.py
Expand Up @@ -91,19 +91,18 @@ def process_response(

return response

def _raise_unsupported_compressors(self, request):
if isinstance(request, Request):
encodings = request.headers.getlist("Accept-Encoding")
unsupported = [key for key in encodings if key not in ACCEPTED_ENCODINGS]
if len(unsupported):
unsupported = [
unsupp for unsupp in unsupported if isinstance(unsupp, bytes)
]
unsupported_msg = b", ".join(unsupported) if len(unsupported) else "-"
raise NotSupported(
"Request is configured with Accept-Encoding header "
"with unsupported encoding(s): %s" % unsupported_msg
)
def _raise_unsupported_compressors(self, request: Request):
encodings = request.headers.getlist("Accept-Encoding")
unsupported = [key for key in encodings if key not in ACCEPTED_ENCODINGS]
if len(unsupported):
unsupported = [
unsupp for unsupp in unsupported if isinstance(unsupp, bytes)
]
unsupported_msg = b", ".join(unsupported) if len(unsupported) else "-"
raise NotSupported(
f"Request is configured with Accept-Encoding header with unsupported encoding(s): "
f"{unsupported_msg}"
)

def _decode(self, body: bytes, encoding: bytes) -> bytes:
if encoding == b"gzip" or encoding == b"x-gzip":
Expand Down
1 change: 0 additions & 1 deletion tests/test_downloadermiddleware_httpcompression.py
Expand Up @@ -109,7 +109,6 @@ def test_process_request_checks_encodings(self):
request = Request("http://scrapytest.org", headers={"Accept-Encoding": b"bro"})
self.mw.process_request(request, self.spider)
"""Expecting no Exception raised here as `bro` encoding is forced to be allowed."""
self.assertTrue(True)

ACCEPTED_ENCODINGS.pop()
self.assertRaises(NotSupported, self.mw.process_request, request, self.spider)
Expand Down

0 comments on commit fcbc7fa

Please sign in to comment.