python-filewrap 0.2__py3-none-any.whl → 0.2.2__py3-none-any.whl
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.
- filewrap/__init__.py +65 -6
- {python_filewrap-0.2.dist-info → python_filewrap-0.2.2.dist-info}/METADATA +2 -2
- python_filewrap-0.2.2.dist-info/RECORD +7 -0
- python_filewrap-0.2.dist-info/RECORD +0 -7
- {python_filewrap-0.2.dist-info → python_filewrap-0.2.2.dist-info}/LICENSE +0 -0
- {python_filewrap-0.2.dist-info → python_filewrap-0.2.2.dist-info}/WHEEL +0 -0
filewrap/__init__.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 2)
|
|
5
|
+
__version__ = (0, 2, 2)
|
|
6
6
|
__all__ = [
|
|
7
7
|
"Buffer", "SupportsRead", "SupportsReadinto", "SupportsWrite", "SupportsSeek",
|
|
8
8
|
"AsyncBufferedReader", "AsyncTextIOWrapper",
|
|
@@ -14,9 +14,10 @@ __all__ = [
|
|
|
14
14
|
"bytes_to_chunk_iter", "bytes_to_chunk_async_iter",
|
|
15
15
|
"bytes_ensure_part_iter", "bytes_ensure_part_async_iter",
|
|
16
16
|
"progress_bytes_iter", "progress_bytes_async_iter",
|
|
17
|
+
"copyfileobj", "copyfileobj_async",
|
|
17
18
|
]
|
|
18
19
|
|
|
19
|
-
from asyncio import
|
|
20
|
+
from asyncio import to_thread, Lock as AsyncLock
|
|
20
21
|
from collections.abc import Awaitable, AsyncIterable, AsyncIterator, Callable, Iterable, Iterator
|
|
21
22
|
from functools import update_wrapper
|
|
22
23
|
from io import BufferedIOBase, BufferedReader, BytesIO, RawIOBase, TextIOWrapper
|
|
@@ -45,7 +46,7 @@ except ImportError:
|
|
|
45
46
|
Buffer.register(_SimpleCData)
|
|
46
47
|
Buffer.register(array)
|
|
47
48
|
|
|
48
|
-
from asynctools import async_chain, ensure_async, ensure_aiter,
|
|
49
|
+
from asynctools import async_chain, ensure_async, ensure_aiter, run_async
|
|
49
50
|
from property import staticproperty
|
|
50
51
|
|
|
51
52
|
|
|
@@ -164,7 +165,7 @@ class AsyncBufferedReader(BufferedReader):
|
|
|
164
165
|
except (AttributeError, TypeError):
|
|
165
166
|
ret = getattr(raw, "close")()
|
|
166
167
|
if isawaitable(ret):
|
|
167
|
-
run_async(
|
|
168
|
+
run_async(ret)
|
|
168
169
|
|
|
169
170
|
async def flush(self, /):
|
|
170
171
|
return await ensure_async(self.raw.flush, threaded=True)()
|
|
@@ -588,7 +589,7 @@ class AsyncTextIOWrapper(TextIOWrapper):
|
|
|
588
589
|
except (AttributeError, TypeError):
|
|
589
590
|
ret = getattr(buffer, "close")()
|
|
590
591
|
if isawaitable(ret):
|
|
591
|
-
run_async(
|
|
592
|
+
run_async(ret)
|
|
592
593
|
|
|
593
594
|
async def flush(self, /):
|
|
594
595
|
return await ensure_async(self.buffer.flush, threaded=True)()
|
|
@@ -1476,14 +1477,17 @@ def bytes_iter_to_async_reader(
|
|
|
1476
1477
|
except:
|
|
1477
1478
|
pass
|
|
1478
1479
|
def close():
|
|
1480
|
+
nonlocal at_end
|
|
1479
1481
|
try:
|
|
1480
1482
|
method = getattr(it, "aclose")
|
|
1481
1483
|
except AttributeError:
|
|
1482
1484
|
method = getattr(it, "close")
|
|
1483
1485
|
ret = method()
|
|
1484
1486
|
if isawaitable(ret):
|
|
1485
|
-
run_async(
|
|
1487
|
+
run_async(ret)
|
|
1488
|
+
at_end = True
|
|
1486
1489
|
async def aclose():
|
|
1490
|
+
nonlocal at_end
|
|
1487
1491
|
try:
|
|
1488
1492
|
method = getattr(it, "aclose")
|
|
1489
1493
|
except AttributeError:
|
|
@@ -1491,6 +1495,7 @@ def bytes_iter_to_async_reader(
|
|
|
1491
1495
|
ret = method()
|
|
1492
1496
|
if isawaitable(ret):
|
|
1493
1497
|
await ret
|
|
1498
|
+
at_end = True
|
|
1494
1499
|
def peek(n: int = 0, /) -> bytearray:
|
|
1495
1500
|
if n <= 0:
|
|
1496
1501
|
return unconsumed[:]
|
|
@@ -1789,3 +1794,57 @@ async def progress_bytes_async_iter(
|
|
|
1789
1794
|
if callable(close_progress):
|
|
1790
1795
|
await ensure_async(close_progress)()
|
|
1791
1796
|
|
|
1797
|
+
|
|
1798
|
+
def copyfileobj(
|
|
1799
|
+
fsrc,
|
|
1800
|
+
fdst: SupportsWrite[Buffer],
|
|
1801
|
+
/,
|
|
1802
|
+
chunksize: int = COPY_BUFSIZE,
|
|
1803
|
+
):
|
|
1804
|
+
if chunksize <= 0:
|
|
1805
|
+
chunksize = COPY_BUFSIZE
|
|
1806
|
+
fdst_write = fdst.write
|
|
1807
|
+
fsrc_read = getattr(fsrc, "read", None)
|
|
1808
|
+
fsrc_readinto = getattr(fsrc, "readinto", None)
|
|
1809
|
+
if callable(fsrc_readinto):
|
|
1810
|
+
buf = bytearray(chunksize)
|
|
1811
|
+
view = memoryview(buf)
|
|
1812
|
+
while size := fsrc_readinto(buf):
|
|
1813
|
+
fdst_write(view[:size])
|
|
1814
|
+
elif callable(fsrc_read):
|
|
1815
|
+
while chunk := fsrc_read(chunksize):
|
|
1816
|
+
fdst_write(chunk)
|
|
1817
|
+
else:
|
|
1818
|
+
for chunk in fsrc:
|
|
1819
|
+
if chunk:
|
|
1820
|
+
fdst_write(chunk)
|
|
1821
|
+
|
|
1822
|
+
|
|
1823
|
+
async def copyfileobj_async(
|
|
1824
|
+
fsrc,
|
|
1825
|
+
fdst: SupportsWrite[Buffer],
|
|
1826
|
+
/,
|
|
1827
|
+
chunksize: int = COPY_BUFSIZE,
|
|
1828
|
+
threaded: bool = True,
|
|
1829
|
+
):
|
|
1830
|
+
if chunksize <= 0:
|
|
1831
|
+
chunksize = COPY_BUFSIZE
|
|
1832
|
+
fdst_write = ensure_async(fdst.write, threaded=threaded)
|
|
1833
|
+
fsrc_read = getattr(fsrc, "read", None)
|
|
1834
|
+
fsrc_readinto = getattr(fsrc, "readinto", None)
|
|
1835
|
+
if callable(fsrc_readinto):
|
|
1836
|
+
fsrc_readinto = ensure_async(fsrc_readinto, threaded=threaded)
|
|
1837
|
+
buf = bytearray(chunksize)
|
|
1838
|
+
view = memoryview(buf)
|
|
1839
|
+
while size := await fsrc_readinto(buf):
|
|
1840
|
+
await fdst_write(view[:size])
|
|
1841
|
+
elif callable(fsrc_read):
|
|
1842
|
+
fsrc_read = ensure_async(fsrc_read, threaded=threaded)
|
|
1843
|
+
while chunk := await fsrc_read(chunksize):
|
|
1844
|
+
await fdst_write(chunk)
|
|
1845
|
+
else:
|
|
1846
|
+
chunkiter = ensure_aiter(fsrc, threaded=threaded)
|
|
1847
|
+
async for chunk in chunkiter:
|
|
1848
|
+
if chunk:
|
|
1849
|
+
await fdst_write(chunk)
|
|
1850
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-filewrap
|
|
3
|
-
Version: 0.2
|
|
3
|
+
Version: 0.2.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
|
|
@@ -21,7 +21,7 @@ Classifier: Programming Language :: Python :: 3 :: Only
|
|
|
21
21
|
Classifier: Topic :: Software Development
|
|
22
22
|
Classifier: Topic :: Software Development :: Libraries
|
|
23
23
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
-
Requires-Dist: python-asynctools (>=0.0.
|
|
24
|
+
Requires-Dist: python-asynctools (>=0.0.5)
|
|
25
25
|
Requires-Dist: python-property (>=0.0.2)
|
|
26
26
|
Project-URL: Repository, https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-filewrap
|
|
27
27
|
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
filewrap/__init__.py,sha256=kQ3EL_pPx5jkImO5tPuhAx6PiQnocXeHwVmBz3_o60k,62700
|
|
3
|
+
filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_filewrap-0.2.2.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_filewrap-0.2.2.dist-info/METADATA,sha256=hOJOU4Q01T3SkJQ0VQ7qAVOZSUcvwlEe3q2uHeo_xZ4,1413
|
|
6
|
+
python_filewrap-0.2.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
+
python_filewrap-0.2.2.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
filewrap/__init__.py,sha256=WKOOUCXO47ZmDRyROPcLkKIFiwsb5eDBhvbItCJ8zm4,61007
|
|
3
|
-
filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_filewrap-0.2.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_filewrap-0.2.dist-info/METADATA,sha256=mSMywqyvrqatQcKls-K7-2HQP02yE9ux2jMk6Gxuvu4,1411
|
|
6
|
-
python_filewrap-0.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
-
python_filewrap-0.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|