python-filewrap 0.1.1__tar.gz → 0.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-filewrap
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Python file wrappers.
5
5
  Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-filewrap
6
6
  License: MIT
@@ -2,7 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  __author__ = "ChenyangGao <https://chenyanggao.github.io>"
5
- __version__ = (0, 1, 1)
5
+ __version__ = (0, 1, 2)
6
6
  __all__ = [
7
7
  "Buffer", "SupportsRead", "SupportsReadinto",
8
8
  "SupportsWrite", "SupportsSeek",
@@ -22,7 +22,7 @@ from inspect import isawaitable, iscoroutinefunction, isasyncgen, isgenerator
22
22
  from itertools import chain
23
23
  from shutil import COPY_BUFSIZE # type: ignore
24
24
  from threading import Lock
25
- from typing import runtime_checkable, Any, ParamSpec, Protocol, TypeVar
25
+ from typing import cast, runtime_checkable, Any, ParamSpec, Protocol, TypeVar
26
26
 
27
27
  try:
28
28
  from collections.abc import Buffer # type: ignore
@@ -658,7 +658,7 @@ async def bytes_ensure_part_async_iter(
658
658
 
659
659
 
660
660
  def progress_bytes_iter(
661
- it: Iterable[Buffer],
661
+ it: Iterable[Buffer] | Callable[[], Buffer],
662
662
  make_progress: None | Callable[Args, Any] = None,
663
663
  /,
664
664
  *args: Args.args,
@@ -666,6 +666,8 @@ def progress_bytes_iter(
666
666
  ) -> Iterator[Buffer]:
667
667
  update_progress: None | Callable = None
668
668
  close_progress: None | Callable = None
669
+ if callable(it):
670
+ it = iter(it, b"")
669
671
  if callable(make_progress):
670
672
  progress = make_progress(*args, **kwds)
671
673
  if isgenerator(progress):
@@ -689,7 +691,7 @@ def progress_bytes_iter(
689
691
 
690
692
 
691
693
  async def progress_bytes_async_iter(
692
- it: Iterable[Buffer] | AsyncIterable[Buffer],
694
+ it: Iterable[Buffer] | AsyncIterable[Buffer] | Callable[[], Buffer] | Callable[[], Awaitable[Buffer]],
693
695
  make_progress: None | Callable[Args, Any] = None,
694
696
  /,
695
697
  *args: Args.args,
@@ -697,6 +699,16 @@ async def progress_bytes_async_iter(
697
699
  ) -> AsyncIterator[Buffer]:
698
700
  update_progress: None | Callable = None
699
701
  close_progress: None | Callable = None
702
+ if callable(it):
703
+ async def wrapiter(it) -> Buffer:
704
+ while True:
705
+ chunk = it()
706
+ if isawaitable(chunk):
707
+ chunk = await chunk
708
+ if not chunk:
709
+ break
710
+ yield chunk
711
+ it = cast(AsyncIterable[Buffer], wrapiter(it))
700
712
  if callable(make_progress):
701
713
  progress = make_progress(*args, **kwds)
702
714
  if isgenerator(progress):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-filewrap"
3
- version = "0.1.1"
3
+ version = "0.1.2"
4
4
  description = "Python file wrappers."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
File without changes