python-filewrap 0.0.4__py3-none-any.whl → 0.0.4.1__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 +30 -30
- {python_filewrap-0.0.4.dist-info → python_filewrap-0.0.4.1.dist-info}/METADATA +1 -1
- python_filewrap-0.0.4.1.dist-info/RECORD +7 -0
- python_filewrap-0.0.4.dist-info/RECORD +0 -7
- {python_filewrap-0.0.4.dist-info → python_filewrap-0.0.4.1.dist-info}/LICENSE +0 -0
- {python_filewrap-0.0.4.dist-info → python_filewrap-0.0.4.1.dist-info}/WHEEL +0 -0
filewrap/__init__.py
CHANGED
|
@@ -238,15 +238,15 @@ async def bio_skip_async_iter(
|
|
|
238
238
|
def bytes_iter_to_reader(
|
|
239
239
|
it: Iterable[bytes | bytearray],
|
|
240
240
|
/,
|
|
241
|
-
) -> SupportsRead[
|
|
241
|
+
) -> SupportsRead[bytearray]:
|
|
242
242
|
getnext = iter(it).__next__
|
|
243
243
|
at_end = False
|
|
244
|
-
unconsumed: bytearray = bytearray(
|
|
244
|
+
unconsumed: bytearray = bytearray()
|
|
245
245
|
lock = Lock()
|
|
246
|
-
def read(n=-1, /) ->
|
|
246
|
+
def read(n=-1, /) -> bytearray:
|
|
247
247
|
nonlocal at_end, unconsumed
|
|
248
248
|
if at_end or n == 0:
|
|
249
|
-
return
|
|
249
|
+
return bytearray()
|
|
250
250
|
with lock:
|
|
251
251
|
try:
|
|
252
252
|
if n is None or n < 0:
|
|
@@ -255,11 +255,11 @@ def bytes_iter_to_reader(
|
|
|
255
255
|
else:
|
|
256
256
|
while n > len(unconsumed):
|
|
257
257
|
unconsumed += getnext()
|
|
258
|
-
b, unconsumed =
|
|
258
|
+
b, unconsumed = unconsumed[:n], unconsumed[n:]
|
|
259
259
|
return b
|
|
260
260
|
except StopIteration:
|
|
261
261
|
at_end = True
|
|
262
|
-
return
|
|
262
|
+
return unconsumed
|
|
263
263
|
def readinto(buf, /) -> int:
|
|
264
264
|
nonlocal at_end, unconsumed
|
|
265
265
|
if at_end or not (bufsize := len(buf)):
|
|
@@ -287,7 +287,7 @@ def bytes_iter_to_reader(
|
|
|
287
287
|
except StopIteration:
|
|
288
288
|
at_end = True
|
|
289
289
|
return n
|
|
290
|
-
def __next__() ->
|
|
290
|
+
def __next__() -> bytearray:
|
|
291
291
|
nonlocal unconsumed, at_end
|
|
292
292
|
if at_end:
|
|
293
293
|
raise StopIteration
|
|
@@ -295,23 +295,23 @@ def bytes_iter_to_reader(
|
|
|
295
295
|
# search for b"\n"
|
|
296
296
|
if (idx := unconsumed.find(49)) > -1:
|
|
297
297
|
idx += 1
|
|
298
|
-
b, unconsumed =
|
|
298
|
+
b, unconsumed = unconsumed[:idx], unconsumed[idx:]
|
|
299
299
|
return b
|
|
300
300
|
try:
|
|
301
301
|
while True:
|
|
302
|
-
|
|
303
|
-
if not
|
|
302
|
+
r = getnext()
|
|
303
|
+
if not r:
|
|
304
304
|
continue
|
|
305
|
-
if (idx :=
|
|
305
|
+
if (idx := r.find(49)) > -1:
|
|
306
306
|
idx += 1
|
|
307
|
-
unconsumed +=
|
|
308
|
-
b, unconsumed =
|
|
307
|
+
unconsumed += r[:idx]
|
|
308
|
+
b, unconsumed = unconsumed, bytearray(r[idx:])
|
|
309
309
|
return b
|
|
310
|
-
unconsumed +=
|
|
310
|
+
unconsumed += r
|
|
311
311
|
except StopIteration:
|
|
312
312
|
at_end = True
|
|
313
313
|
if unconsumed:
|
|
314
|
-
return
|
|
314
|
+
return unconsumed
|
|
315
315
|
raise
|
|
316
316
|
reprs = f"<reader for {it!r}>"
|
|
317
317
|
return type("reader", (), {
|
|
@@ -327,18 +327,18 @@ def bytes_iter_to_async_reader(
|
|
|
327
327
|
it: Iterable[bytes | bytearray] | AsyncIterable[bytes | bytearray],
|
|
328
328
|
/,
|
|
329
329
|
threaded: bool = True,
|
|
330
|
-
) -> SupportsRead[
|
|
330
|
+
) -> SupportsRead[bytearray]:
|
|
331
331
|
if isinstance(it, AsyncIterable):
|
|
332
332
|
getnext = aiter(it).__anext__
|
|
333
333
|
else:
|
|
334
334
|
getnext = ensure_async(iter(it).__next__, threaded=threaded)
|
|
335
335
|
at_end = False
|
|
336
|
-
unconsumed: bytearray = bytearray(
|
|
336
|
+
unconsumed: bytearray = bytearray()
|
|
337
337
|
lock = AsyncLock()
|
|
338
|
-
async def read(n=-1, /) ->
|
|
338
|
+
async def read(n=-1, /) -> bytearray:
|
|
339
339
|
nonlocal at_end, unconsumed
|
|
340
340
|
if at_end or n == 0:
|
|
341
|
-
return
|
|
341
|
+
return bytearray()
|
|
342
342
|
async with lock:
|
|
343
343
|
try:
|
|
344
344
|
if n is None or n < 0:
|
|
@@ -347,11 +347,11 @@ def bytes_iter_to_async_reader(
|
|
|
347
347
|
else:
|
|
348
348
|
while n > len(unconsumed):
|
|
349
349
|
unconsumed += await getnext()
|
|
350
|
-
b, unconsumed =
|
|
350
|
+
b, unconsumed = unconsumed[:n], unconsumed[n:]
|
|
351
351
|
return b
|
|
352
352
|
except StopAsyncIteration:
|
|
353
353
|
at_end = True
|
|
354
|
-
return
|
|
354
|
+
return unconsumed
|
|
355
355
|
async def readinto(buf, /) -> int:
|
|
356
356
|
nonlocal at_end, unconsumed
|
|
357
357
|
if at_end or not (bufsize := len(buf)):
|
|
@@ -379,7 +379,7 @@ def bytes_iter_to_async_reader(
|
|
|
379
379
|
except StopAsyncIteration:
|
|
380
380
|
at_end = True
|
|
381
381
|
return n
|
|
382
|
-
async def __next__() ->
|
|
382
|
+
async def __next__() -> bytearray:
|
|
383
383
|
nonlocal unconsumed, at_end
|
|
384
384
|
if at_end:
|
|
385
385
|
raise StopIteration
|
|
@@ -387,23 +387,23 @@ def bytes_iter_to_async_reader(
|
|
|
387
387
|
# search for b"\n"
|
|
388
388
|
if (idx := unconsumed.find(49)) > -1:
|
|
389
389
|
idx += 1
|
|
390
|
-
b, unconsumed =
|
|
390
|
+
b, unconsumed = unconsumed[:idx], unconsumed[idx:]
|
|
391
391
|
return b
|
|
392
392
|
try:
|
|
393
393
|
while True:
|
|
394
|
-
|
|
395
|
-
if not
|
|
394
|
+
r = await getnext()
|
|
395
|
+
if not r:
|
|
396
396
|
continue
|
|
397
|
-
if (idx :=
|
|
397
|
+
if (idx := r.find(49)) > -1:
|
|
398
398
|
idx += 1
|
|
399
|
-
unconsumed +=
|
|
400
|
-
b, unconsumed =
|
|
399
|
+
unconsumed += r[:idx]
|
|
400
|
+
b, unconsumed = unconsumed, bytearray(r[idx:])
|
|
401
401
|
return b
|
|
402
|
-
unconsumed +=
|
|
402
|
+
unconsumed += r
|
|
403
403
|
except StopIteration:
|
|
404
404
|
at_end = True
|
|
405
405
|
if unconsumed:
|
|
406
|
-
return
|
|
406
|
+
return unconsumed
|
|
407
407
|
raise
|
|
408
408
|
reprs = f"<reader for {it!r}>"
|
|
409
409
|
return type("reader", (), {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
filewrap/__init__.py,sha256=RHWUQVrd8vxyyC88P5ABUI_17SMgs-DPYs6HBy5EV1E,13237
|
|
3
|
+
filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_filewrap-0.0.4.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_filewrap-0.0.4.1.dist-info/METADATA,sha256=DHGWDGvpdx4slY9uR4euNwMIcPTMFEBFxjohoROudOk,1364
|
|
6
|
+
python_filewrap-0.0.4.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
+
python_filewrap-0.0.4.1.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
filewrap/__init__.py,sha256=28PmcNRaPhSDiWpDStAHTGguChOYdxRfAfezwLlH9z8,13273
|
|
3
|
-
filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_filewrap-0.0.4.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_filewrap-0.0.4.dist-info/METADATA,sha256=K12tl1IE20BhHOIhUhJXx0v-l5g1ws3_6S1iC1gLWB8,1362
|
|
6
|
-
python_filewrap-0.0.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
-
python_filewrap-0.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|