python-filewrap 0.2.7.1__tar.gz → 0.2.8.1__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_filewrap-0.2.7.1 → python_filewrap-0.2.8.1}/PKG-INFO +1 -1
- {python_filewrap-0.2.7.1 → python_filewrap-0.2.8.1}/filewrap/__init__.py +45 -53
- {python_filewrap-0.2.7.1 → python_filewrap-0.2.8.1}/pyproject.toml +1 -1
- {python_filewrap-0.2.7.1 → python_filewrap-0.2.8.1}/LICENSE +0 -0
- {python_filewrap-0.2.7.1 → python_filewrap-0.2.8.1}/filewrap/py.typed +0 -0
- {python_filewrap-0.2.7.1 → python_filewrap-0.2.8.1}/readme.md +0 -0
|
@@ -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, 8)
|
|
6
6
|
__all__ = [
|
|
7
7
|
"SupportsRead", "SupportsReadinto", "SupportsWrite", "SupportsSeek",
|
|
8
8
|
"AsyncBufferedReader", "AsyncTextIOWrapper", "buffer_length",
|
|
@@ -11,7 +11,7 @@ __all__ = [
|
|
|
11
11
|
"bytes_iter_to_reader", "bytes_iter_to_async_reader", "bytes_to_chunk_iter",
|
|
12
12
|
"bytes_to_chunk_async_iter", "bytes_ensure_part_iter", "bytes_ensure_part_async_iter",
|
|
13
13
|
"progress_bytes_iter", "progress_bytes_async_iter", "copyfileobj", "copyfileobj_async",
|
|
14
|
-
"
|
|
14
|
+
"bound_bytes_reader", "bound_async_bytes_reader",
|
|
15
15
|
]
|
|
16
16
|
|
|
17
17
|
from asyncio import Lock as AsyncLock
|
|
@@ -1275,28 +1275,28 @@ def bytes_iter_to_reader(
|
|
|
1275
1275
|
if at_end or not (bufsize := buffer_length(buf)):
|
|
1276
1276
|
return 0
|
|
1277
1277
|
with lock:
|
|
1278
|
-
n
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1278
|
+
if n := buffer_length(unconsumed):
|
|
1279
|
+
if bufsize <= n:
|
|
1280
|
+
buf[:], unconsumed = unconsumed[:bufsize], unconsumed[bufsize:]
|
|
1281
|
+
pos += bufsize
|
|
1282
|
+
return bufsize
|
|
1283
|
+
buf[:n] = unconsumed
|
|
1284
|
+
pos += n
|
|
1285
|
+
del unconsumed[:]
|
|
1285
1286
|
try:
|
|
1286
1287
|
while True:
|
|
1287
|
-
b
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
n = m
|
|
1288
|
+
if b := memoryview(getnext()):
|
|
1289
|
+
m = n + len(b)
|
|
1290
|
+
if m >= bufsize:
|
|
1291
|
+
delta = bufsize - n
|
|
1292
|
+
buf[n:] = b[:delta]
|
|
1293
|
+
unconsumed += b[delta:]
|
|
1294
|
+
pos += delta
|
|
1295
|
+
return bufsize
|
|
1296
|
+
else:
|
|
1297
|
+
buf[n:m] = b
|
|
1298
|
+
pos += len(b)
|
|
1299
|
+
n = m
|
|
1300
1300
|
except StopIteration:
|
|
1301
1301
|
at_end = True
|
|
1302
1302
|
return n
|
|
@@ -1401,15 +1401,7 @@ def bytes_iter_to_async_reader(
|
|
|
1401
1401
|
except:
|
|
1402
1402
|
pass
|
|
1403
1403
|
def close():
|
|
1404
|
-
|
|
1405
|
-
try:
|
|
1406
|
-
method = getattr(it, "aclose")
|
|
1407
|
-
except AttributeError:
|
|
1408
|
-
method = getattr(it, "close")
|
|
1409
|
-
ret = method()
|
|
1410
|
-
if isawaitable(ret):
|
|
1411
|
-
run_async(ret)
|
|
1412
|
-
at_end = True
|
|
1404
|
+
run_async(aclose())
|
|
1413
1405
|
async def aclose():
|
|
1414
1406
|
nonlocal at_end
|
|
1415
1407
|
try:
|
|
@@ -1452,28 +1444,28 @@ def bytes_iter_to_async_reader(
|
|
|
1452
1444
|
if at_end or not (bufsize := buffer_length(buf)):
|
|
1453
1445
|
return 0
|
|
1454
1446
|
async with lock:
|
|
1455
|
-
n
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1447
|
+
if n := buffer_length(unconsumed):
|
|
1448
|
+
if bufsize <= n:
|
|
1449
|
+
buf[:], unconsumed = unconsumed[:bufsize], unconsumed[bufsize:]
|
|
1450
|
+
pos += bufsize
|
|
1451
|
+
return bufsize
|
|
1452
|
+
buf[:n] = unconsumed
|
|
1453
|
+
pos += n
|
|
1454
|
+
del unconsumed[:]
|
|
1462
1455
|
try:
|
|
1463
1456
|
while True:
|
|
1464
|
-
b
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
n = m
|
|
1457
|
+
if b := memoryview(await getnext()):
|
|
1458
|
+
m = n + len(b)
|
|
1459
|
+
if m >= bufsize:
|
|
1460
|
+
delta = bufsize - n
|
|
1461
|
+
buf[n:] = b[:delta]
|
|
1462
|
+
unconsumed += b[delta:]
|
|
1463
|
+
pos += delta
|
|
1464
|
+
return bufsize
|
|
1465
|
+
else:
|
|
1466
|
+
buf[n:m] = b
|
|
1467
|
+
pos += len(b)
|
|
1468
|
+
n = m
|
|
1477
1469
|
except (StopIteration, StopAsyncIteration):
|
|
1478
1470
|
at_end = True
|
|
1479
1471
|
return n
|
|
@@ -1773,7 +1765,7 @@ async def copyfileobj_async(
|
|
|
1773
1765
|
await fdst_write(chunk)
|
|
1774
1766
|
|
|
1775
1767
|
|
|
1776
|
-
def
|
|
1768
|
+
def bound_bytes_reader(
|
|
1777
1769
|
file: SupportsRead[Buffer],
|
|
1778
1770
|
size: int = -1,
|
|
1779
1771
|
) -> SupportsRead[Buffer]:
|
|
@@ -1807,7 +1799,7 @@ def bound_bufferd_reader(
|
|
|
1807
1799
|
return Reader()
|
|
1808
1800
|
|
|
1809
1801
|
|
|
1810
|
-
def
|
|
1802
|
+
def bound_async_bytes_reader(
|
|
1811
1803
|
file: SupportsRead[Buffer] | SupportsRead[Awaitable[Buffer]],
|
|
1812
1804
|
size: int = -1,
|
|
1813
1805
|
) -> SupportsRead[Awaitable[Buffer]]:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|