python-urlopen 0.0.1.3__tar.gz → 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_urlopen-0.0.1.3 → python_urlopen-0.0.2}/PKG-INFO +1 -1
- {python_urlopen-0.0.1.3 → python_urlopen-0.0.2}/pyproject.toml +1 -1
- {python_urlopen-0.0.1.3 → python_urlopen-0.0.2}/urlopen/__init__.py +1 -1
- {python_urlopen-0.0.1.3 → python_urlopen-0.0.2}/urlopen/__main__.py +29 -19
- {python_urlopen-0.0.1.3 → python_urlopen-0.0.2}/LICENSE +0 -0
- {python_urlopen-0.0.1.3 → python_urlopen-0.0.2}/readme.md +0 -0
- {python_urlopen-0.0.1.3 → python_urlopen-0.0.2}/urlopen/py.typed +0 -0
|
@@ -2,29 +2,33 @@
|
|
|
2
2
|
# coding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__doc__ = "python
|
|
5
|
+
__doc__ = "python urlopen"
|
|
6
6
|
|
|
7
7
|
from argparse import ArgumentParser, RawTextHelpFormatter
|
|
8
|
-
|
|
9
|
-
parser = ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)
|
|
10
|
-
parser.add_argument("url", nargs="?", help="URL to be downloaded")
|
|
11
|
-
parser.add_argument("-o", "--output-file", help="file path to be downloaded, if omitted, print into stdout")
|
|
12
|
-
parser.add_argument("-r", "--resume", action="store_true", help="skip downloaded data")
|
|
13
|
-
parser.add_argument("-hs", "--headers", help="dictionary of HTTP Headers to send with")
|
|
14
|
-
parser.add_argument("-v", "--version", action="store_true", help="print the current version")
|
|
15
|
-
args = parser.parse_args()
|
|
16
|
-
if args.version:
|
|
17
|
-
from urlopen import __version__
|
|
18
|
-
print(".".join(map(str, __version__)))
|
|
19
|
-
raise SystemExit(0)
|
|
20
|
-
url = args.url
|
|
21
|
-
if not url:
|
|
22
|
-
parser.parse_args(["-h"])
|
|
23
|
-
|
|
24
8
|
from collections import deque
|
|
25
9
|
from time import perf_counter
|
|
26
10
|
|
|
27
|
-
from
|
|
11
|
+
from . import download, __version__
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def parse_args():
|
|
15
|
+
parser = ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)
|
|
16
|
+
|
|
17
|
+
parser.add_argument("url", nargs="?", help="URL to be downloaded")
|
|
18
|
+
parser.add_argument("-o", "--output-file", help="file path to be downloaded, if omitted, print into stdout")
|
|
19
|
+
parser.add_argument("-r", "--resume", action="store_true", help="skip downloaded data")
|
|
20
|
+
parser.add_argument("-hs", "--headers", help="dictionary of HTTP Headers to send with")
|
|
21
|
+
parser.add_argument("-v", "--version", action="store_true", help="print the current version")
|
|
22
|
+
|
|
23
|
+
args = parser.parse_args()
|
|
24
|
+
|
|
25
|
+
if args.version:
|
|
26
|
+
print(".".join(map(str, __version__)))
|
|
27
|
+
raise SystemExit(0)
|
|
28
|
+
|
|
29
|
+
if not args.url:
|
|
30
|
+
parser.parse_args(["-h"])
|
|
31
|
+
|
|
28
32
|
|
|
29
33
|
def headers_str_to_dict(headers: str, /) -> dict[str, str]:
|
|
30
34
|
return dict(
|
|
@@ -32,6 +36,7 @@ def headers_str_to_dict(headers: str, /) -> dict[str, str]:
|
|
|
32
36
|
for header in headers.strip("\n").split("\n")
|
|
33
37
|
)
|
|
34
38
|
|
|
39
|
+
|
|
35
40
|
def progress(total=None):
|
|
36
41
|
dq: deque[tuple[int, float]] = deque(maxlen=64)
|
|
37
42
|
read_num = 0
|
|
@@ -47,7 +52,11 @@ def progress(total=None):
|
|
|
47
52
|
print(f"\r\x1b[K{read_num} | {speed:.2f} MB/s", end="", flush=True)
|
|
48
53
|
dq.append((read_num, cur_t))
|
|
49
54
|
|
|
55
|
+
|
|
50
56
|
def main():
|
|
57
|
+
args = parse_args()
|
|
58
|
+
url = args.url
|
|
59
|
+
|
|
51
60
|
headers = args.headers
|
|
52
61
|
if headers is not None:
|
|
53
62
|
headers = headers_str_to_dict(headers)
|
|
@@ -72,10 +81,11 @@ def main():
|
|
|
72
81
|
|
|
73
82
|
download(
|
|
74
83
|
url,
|
|
75
|
-
stdout,
|
|
84
|
+
stdout.buffer,
|
|
76
85
|
headers=headers,
|
|
77
86
|
)
|
|
78
87
|
|
|
88
|
+
|
|
79
89
|
if __name__ == "__main__":
|
|
80
90
|
main()
|
|
81
91
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|