dcicutils 8.8.4.1b16__py3-none-any.whl → 8.8.4.1b17__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- dcicutils/http_utils.py +13 -2
- {dcicutils-8.8.4.1b16.dist-info → dcicutils-8.8.4.1b17.dist-info}/METADATA +1 -1
- {dcicutils-8.8.4.1b16.dist-info → dcicutils-8.8.4.1b17.dist-info}/RECORD +6 -6
- {dcicutils-8.8.4.1b16.dist-info → dcicutils-8.8.4.1b17.dist-info}/LICENSE.txt +0 -0
- {dcicutils-8.8.4.1b16.dist-info → dcicutils-8.8.4.1b17.dist-info}/WHEEL +0 -0
- {dcicutils-8.8.4.1b16.dist-info → dcicutils-8.8.4.1b17.dist-info}/entry_points.txt +0 -0
dcicutils/http_utils.py
CHANGED
@@ -1,20 +1,31 @@
|
|
1
1
|
from contextlib import contextmanager
|
2
2
|
import requests
|
3
|
-
from typing import Optional
|
3
|
+
from typing import Callable, Optional
|
4
4
|
from dcicutils.tmpfile_utils import temporary_file
|
5
5
|
|
6
6
|
|
7
7
|
@contextmanager
|
8
|
-
def download(url: str, suffix: Optional[str] = None, binary: bool = True
|
8
|
+
def download(url: str, suffix: Optional[str] = None, binary: bool = True,
|
9
|
+
progress: Optional[Callable] = None) -> Optional[str]:
|
9
10
|
"""
|
10
11
|
Context manager to ownload the given URL into a temporary file and yields the file
|
11
12
|
path to it. An optional file suffix may be specified. Defaults to binary file mode;
|
12
13
|
if this is not desired then pass False as the binary argument.
|
13
14
|
"""
|
15
|
+
if not callable(progress):
|
16
|
+
progress = None
|
14
17
|
with temporary_file(suffix=suffix) as file:
|
15
18
|
response = requests.get(url, stream=True)
|
19
|
+
if progress:
|
20
|
+
nbytes = 0
|
21
|
+
nbytes_total = None
|
22
|
+
if isinstance(content_length := response.headers.get("Content-Length"), str) and content_length.isdigit():
|
23
|
+
nbytes_total = int(content_length)
|
16
24
|
with open(file, "wb" if binary is True else "w") as f:
|
17
25
|
for chunk in response.iter_content(chunk_size=8192):
|
18
26
|
if chunk:
|
19
27
|
f.write(chunk)
|
28
|
+
if progress:
|
29
|
+
nbytes += len(chunk)
|
30
|
+
progress(nbytes, nbytes_total)
|
20
31
|
yield file
|
@@ -31,7 +31,7 @@ dcicutils/ff_utils.py,sha256=oIhuZPnGtfwj6bWyCc1u23JbMB_6InPp01ZqUOljd8M,73123
|
|
31
31
|
dcicutils/file_utils.py,sha256=msxA3fFTtK09Qc_I3-r9Y5Pp5WVJRPPpLlFYv3Rju-E,8697
|
32
32
|
dcicutils/function_cache_decorator.py,sha256=XMyiEGODVr2WoAQ68vcoX_9_Xb9p8pZXdXl7keU8i2g,10026
|
33
33
|
dcicutils/glacier_utils.py,sha256=Q4CVXsZCbP-SoZIsZ5NMcawDfelOLzbQnIlQn-GdlTo,34149
|
34
|
-
dcicutils/http_utils.py,sha256=
|
34
|
+
dcicutils/http_utils.py,sha256=Je5ErNjR5e6lfSXGRncK_lcR_-zP38PIpmHjApy9Wi4,1289
|
35
35
|
dcicutils/jh_utils.py,sha256=Gpsxb9XEzggF_-Eq3ukjKvTnuyb9V1SCSUXkXsES4Kg,11502
|
36
36
|
dcicutils/kibana/dashboards.json,sha256=wHMB_mpJ8OaYhRRgvpZuihaB2lmSF64ADt_8hkBWgQg,16225
|
37
37
|
dcicutils/kibana/readme.md,sha256=3KmHF9FH6A6xwYsNxRFLw27q0XzHYnjZOlYUnn3VkQQ,2164
|
@@ -73,8 +73,8 @@ dcicutils/trace_utils.py,sha256=g8kwV4ebEy5kXW6oOrEAUsurBcCROvwtZqz9fczsGRE,1769
|
|
73
73
|
dcicutils/validation_utils.py,sha256=cMZIU2cY98FYtzK52z5WUYck7urH6JcqOuz9jkXpqzg,14797
|
74
74
|
dcicutils/variant_utils.py,sha256=2H9azNx3xAj-MySg-uZ2SFqbWs4kZvf61JnK6b-h4Qw,4343
|
75
75
|
dcicutils/zip_utils.py,sha256=_Y9EmL3D2dUZhxucxHvrtmmlbZmK4FpSsHEb7rGSJLU,3265
|
76
|
-
dcicutils-8.8.4.
|
77
|
-
dcicutils-8.8.4.
|
78
|
-
dcicutils-8.8.4.
|
79
|
-
dcicutils-8.8.4.
|
80
|
-
dcicutils-8.8.4.
|
76
|
+
dcicutils-8.8.4.1b17.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
|
77
|
+
dcicutils-8.8.4.1b17.dist-info/METADATA,sha256=KLVzlNXL2JHkY6n3bL-fbnoVa1kNKAnIbK7bRluuxlM,3440
|
78
|
+
dcicutils-8.8.4.1b17.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
79
|
+
dcicutils-8.8.4.1b17.dist-info/entry_points.txt,sha256=51Q4F_2V10L0282W7HFjP4jdzW4K8lnWDARJQVFy_hw,270
|
80
|
+
dcicutils-8.8.4.1b17.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|