python-download 0.0.2.2__tar.gz → 0.0.3__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_download-0.0.2.2 → python_download-0.0.3}/PKG-INFO +1 -1
- {python_download-0.0.2.2 → python_download-0.0.3}/download/__init__.py +19 -11
- {python_download-0.0.2.2 → python_download-0.0.3}/pyproject.toml +1 -1
- {python_download-0.0.2.2 → python_download-0.0.3}/LICENSE +0 -0
- {python_download-0.0.2.2 → python_download-0.0.3}/download/__main__.py +0 -0
- {python_download-0.0.2.2 → python_download-0.0.3}/download/py.typed +0 -0
- {python_download-0.0.2.2 → python_download-0.0.3}/readme.md +0 -0
|
@@ -62,6 +62,9 @@ class DownloadTaskStatus(IntEnum):
|
|
|
62
62
|
CANCELED = 4
|
|
63
63
|
FAILED = 5
|
|
64
64
|
|
|
65
|
+
def __str__(self, /) -> str:
|
|
66
|
+
return repr(self)
|
|
67
|
+
|
|
65
68
|
@classmethod
|
|
66
69
|
def of(cls, val, /) -> Self:
|
|
67
70
|
if isinstance(val, cls):
|
|
@@ -111,11 +114,9 @@ class BaseDownloadTask(ABC):
|
|
|
111
114
|
|
|
112
115
|
def __repr__(self, /) -> str:
|
|
113
116
|
name = type(self).__qualname__
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
case DownloadTaskStatus.FAILED:
|
|
118
|
-
return f"<{name} :: state={state!r} exception={self.exception()} progress={self.progress!r}>"
|
|
117
|
+
state = self.state
|
|
118
|
+
if state is DownloadTaskStatus.FAILED:
|
|
119
|
+
return f"<{name} :: state={state!r} progress={self.progress!r} exception={self.exception()}>"
|
|
119
120
|
return f"<{name} :: state={state!r} progress={self.progress!r}>"
|
|
120
121
|
|
|
121
122
|
@property
|
|
@@ -148,7 +149,7 @@ class BaseDownloadTask(ABC):
|
|
|
148
149
|
|
|
149
150
|
@property
|
|
150
151
|
def done(self, /) -> bool:
|
|
151
|
-
return self.state
|
|
152
|
+
return self.state in (DownloadTaskStatus.FINISHED, DownloadTaskStatus.CANCELED, DownloadTaskStatus.FAILED)
|
|
152
153
|
|
|
153
154
|
def cancel(self, /):
|
|
154
155
|
if not self.done:
|
|
@@ -336,9 +337,9 @@ class AsyncDownloadTask(BaseDownloadTask):
|
|
|
336
337
|
self.progress = await step()
|
|
337
338
|
except KeyboardInterrupt:
|
|
338
339
|
raise
|
|
339
|
-
except
|
|
340
|
+
except StopAsyncIteration as exc:
|
|
340
341
|
self.state = DownloadTaskStatus.FINISHED
|
|
341
|
-
self.set_result(
|
|
342
|
+
self.set_result(None)
|
|
342
343
|
except BaseException as exc:
|
|
343
344
|
self.state = DownloadTaskStatus.FAILED
|
|
344
345
|
self.set_exception(exc)
|
|
@@ -595,7 +596,10 @@ async def download_async_iter(
|
|
|
595
596
|
return
|
|
596
597
|
|
|
597
598
|
if filesize and is_range_request(resp):
|
|
598
|
-
|
|
599
|
+
if hasattr(resp, "aclose"):
|
|
600
|
+
await resp.aclose()
|
|
601
|
+
else:
|
|
602
|
+
await ensure_async(resp.close)()
|
|
599
603
|
resp = await urlopen(url, headers={**headers, "Range": "bytes=%d-" % filesize})
|
|
600
604
|
if not is_range_request(resp):
|
|
601
605
|
raise OSError(errno.EIO, f"range request failed: {url!r}")
|
|
@@ -621,7 +625,10 @@ async def download_async_iter(
|
|
|
621
625
|
length_downloaded += downlen
|
|
622
626
|
yield DownloadProgress(length or (length_skipped + length_downloaded), length_downloaded, length_skipped, downlen, extra)
|
|
623
627
|
finally:
|
|
624
|
-
|
|
628
|
+
if hasattr(resp, "aclose"):
|
|
629
|
+
await resp.aclose()
|
|
630
|
+
else:
|
|
631
|
+
await ensure_async(resp.close)()
|
|
625
632
|
if file_async_close:
|
|
626
633
|
await file_async_close()
|
|
627
634
|
|
|
@@ -635,7 +642,7 @@ async def download_async(
|
|
|
635
642
|
urlopen: Callable = urlopen,
|
|
636
643
|
iter_bytes: Callable = DEFAULT_ASYNC_ITER_BYTES,
|
|
637
644
|
make_reporthook: None | Callable[[None | int], Callable[[int], Any] | Generator[int, Any, Any] | AsyncGenerator[int, Any]] = None,
|
|
638
|
-
):
|
|
645
|
+
) -> DownloadProgress:
|
|
639
646
|
"""
|
|
640
647
|
"""
|
|
641
648
|
update: None | Callable = None
|
|
@@ -671,6 +678,7 @@ async def download_async(
|
|
|
671
678
|
else:
|
|
672
679
|
async for progress in download_gen:
|
|
673
680
|
await update(progress.last_increment)
|
|
681
|
+
return progress
|
|
674
682
|
finally:
|
|
675
683
|
await download_gen.aclose()
|
|
676
684
|
if close is not None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|