python-filewrap 0.0.4__tar.gz → 0.0.4.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-filewrap
3
- Version: 0.0.4
3
+ Version: 0.0.4.1
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
@@ -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[bytes]:
241
+ ) -> SupportsRead[bytearray]:
242
242
  getnext = iter(it).__next__
243
243
  at_end = False
244
- unconsumed: bytearray = bytearray(b"")
244
+ unconsumed: bytearray = bytearray()
245
245
  lock = Lock()
246
- def read(n=-1, /) -> bytes:
246
+ def read(n=-1, /) -> bytearray:
247
247
  nonlocal at_end, unconsumed
248
248
  if at_end or n == 0:
249
- return b""
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 = bytes(unconsumed[:n]), unconsumed[n:]
258
+ b, unconsumed = unconsumed[:n], unconsumed[n:]
259
259
  return b
260
260
  except StopIteration:
261
261
  at_end = True
262
- return bytes(unconsumed)
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__() -> bytes:
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 = bytes(unconsumed[:idx]), unconsumed[idx:]
298
+ b, unconsumed = unconsumed[:idx], unconsumed[idx:]
299
299
  return b
300
300
  try:
301
301
  while True:
302
- b = getnext()
303
- if not b:
302
+ r = getnext()
303
+ if not r:
304
304
  continue
305
- if (idx := b.find(49)) > -1:
305
+ if (idx := r.find(49)) > -1:
306
306
  idx += 1
307
- unconsumed += b[:idx]
308
- b, unconsumed = bytes(unconsumed), bytearray(b[idx:])
307
+ unconsumed += r[:idx]
308
+ b, unconsumed = unconsumed, bytearray(r[idx:])
309
309
  return b
310
- unconsumed += b
310
+ unconsumed += r
311
311
  except StopIteration:
312
312
  at_end = True
313
313
  if unconsumed:
314
- return bytes(unconsumed)
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[bytes]:
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(b"")
336
+ unconsumed: bytearray = bytearray()
337
337
  lock = AsyncLock()
338
- async def read(n=-1, /) -> bytes:
338
+ async def read(n=-1, /) -> bytearray:
339
339
  nonlocal at_end, unconsumed
340
340
  if at_end or n == 0:
341
- return b""
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 = bytes(unconsumed[:n]), unconsumed[n:]
350
+ b, unconsumed = unconsumed[:n], unconsumed[n:]
351
351
  return b
352
352
  except StopAsyncIteration:
353
353
  at_end = True
354
- return bytes(unconsumed)
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__() -> bytes:
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 = bytes(unconsumed[:idx]), unconsumed[idx:]
390
+ b, unconsumed = unconsumed[:idx], unconsumed[idx:]
391
391
  return b
392
392
  try:
393
393
  while True:
394
- b = await getnext()
395
- if not b:
394
+ r = await getnext()
395
+ if not r:
396
396
  continue
397
- if (idx := b.find(49)) > -1:
397
+ if (idx := r.find(49)) > -1:
398
398
  idx += 1
399
- unconsumed += b[:idx]
400
- b, unconsumed = bytes(unconsumed), bytearray(b[idx:])
399
+ unconsumed += r[:idx]
400
+ b, unconsumed = unconsumed, bytearray(r[idx:])
401
401
  return b
402
- unconsumed += b
402
+ unconsumed += r
403
403
  except StopIteration:
404
404
  at_end = True
405
405
  if unconsumed:
406
- return bytes(unconsumed)
406
+ return unconsumed
407
407
  raise
408
408
  reprs = f"<reader for {it!r}>"
409
409
  return type("reader", (), {
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-filewrap"
3
- version = "0.0.4"
3
+ version = "0.0.4.1"
4
4
  description = "Python file wrappers."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"