Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_internal/network/utils.py @ 1:64071f2a4cf0 draft default tip
Deleted selected files
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:55:49 -0400 |
parents | 9e54283cc701 |
children |
comparison
equal
deleted
inserted
replaced
0:9e54283cc701 | 1:64071f2a4cf0 |
---|---|
1 from pip._vendor.requests.models import CONTENT_CHUNK_SIZE, Response | |
2 | |
3 from pip._internal.utils.typing import MYPY_CHECK_RUNNING | |
4 | |
5 if MYPY_CHECK_RUNNING: | |
6 from typing import Iterator | |
7 | |
8 | |
9 def response_chunks(response, chunk_size=CONTENT_CHUNK_SIZE): | |
10 # type: (Response, int) -> Iterator[bytes] | |
11 """Given a requests Response, provide the data chunks. | |
12 """ | |
13 try: | |
14 # Special case for urllib3. | |
15 for chunk in response.raw.stream( | |
16 chunk_size, | |
17 # We use decode_content=False here because we don't | |
18 # want urllib3 to mess with the raw bytes we get | |
19 # from the server. If we decompress inside of | |
20 # urllib3 then we cannot verify the checksum | |
21 # because the checksum will be of the compressed | |
22 # file. This breakage will only occur if the | |
23 # server adds a Content-Encoding header, which | |
24 # depends on how the server was configured: | |
25 # - Some servers will notice that the file isn't a | |
26 # compressible file and will leave the file alone | |
27 # and with an empty Content-Encoding | |
28 # - Some servers will notice that the file is | |
29 # already compressed and will leave the file | |
30 # alone and will add a Content-Encoding: gzip | |
31 # header | |
32 # - Some servers won't notice anything at all and | |
33 # will take a file that's already been compressed | |
34 # and compress it again and set the | |
35 # Content-Encoding: gzip header | |
36 # | |
37 # By setting this not to decode automatically we | |
38 # hope to eliminate problems with the second case. | |
39 decode_content=False, | |
40 ): | |
41 yield chunk | |
42 except AttributeError: | |
43 # Standard file-like object. | |
44 while True: | |
45 chunk = response.raw.read(chunk_size) | |
46 if not chunk: | |
47 break | |
48 yield chunk |