python-filewrap 0.2.8.1__tar.gz → 0.2.9__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,8 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-filewrap
3
- Version: 0.2.8.1
3
+ Version: 0.2.9
4
4
  Summary: Python file wrappers.
5
- Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-filewrap
5
+ Home-page: https://github.com/ChenyangGao/python-modules/tree/main/python-filewrap
6
6
  License: MIT
7
7
  Keywords: file,wrapper
8
8
  Author: ChenyangGao
@@ -20,9 +20,9 @@ Classifier: Programming Language :: Python :: 3 :: Only
20
20
  Classifier: Topic :: Software Development
21
21
  Classifier: Topic :: Software Development :: Libraries
22
22
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
- Requires-Dist: python-asynctools (>=0.1)
23
+ Requires-Dist: python-asynctools (>=0.1.3)
24
24
  Requires-Dist: python-property (>=0.0.3)
25
- Project-URL: Repository, https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-filewrap
25
+ Project-URL: Repository, https://github.com/ChenyangGao/python-modules/tree/main/python-filewrap
26
26
  Description-Content-Type: text/markdown
27
27
 
28
28
  # Python file wrappers.
@@ -2,7 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  __author__ = "ChenyangGao <https://chenyanggao.github.io>"
5
- __version__ = (0, 2, 8)
5
+ __version__ = (0, 2, 9)
6
6
  __all__ = [
7
7
  "SupportsRead", "SupportsReadinto", "SupportsWrite", "SupportsSeek",
8
8
  "AsyncBufferedReader", "AsyncTextIOWrapper", "buffer_length",
@@ -31,8 +31,7 @@ from asynctools import async_chain, ensure_async, ensure_aiter, run_async
31
31
  from property import funcproperty
32
32
 
33
33
 
34
- READ_BUFSIZE = 1 << 13
35
- WRITE_BUFSIZE = 1 << 16
34
+ READ_BUFSIZE = 1 << 16
36
35
  CRE_NOT_UNIX_NEWLINES: Final = re_compile("\r\n|\r")
37
36
 
38
37
 
@@ -46,7 +45,7 @@ class VirtualBufferedReader:
46
45
 
47
46
  @runtime_checkable
48
47
  class SupportsRead[T](Protocol):
49
- def read(self, /, size: int) -> T: ...
48
+ def read(self, /, size: int = -1) -> T: ...
50
49
 
51
50
 
52
51
  @runtime_checkable
@@ -827,17 +826,16 @@ def get_bom(encoding: str, /) -> bytes:
827
826
 
828
827
 
829
828
  def buffer_length(b: Buffer, /) -> int:
830
- try:
831
- return len(b) # type: ignore
832
- except:
833
- return len(memoryview(b))
829
+ if isinstance(b, (bytes, bytearray, memoryview)):
830
+ return len(b)
831
+ return len(memoryview(b))
834
832
 
835
833
 
836
834
  def bio_chunk_iter(
837
835
  bio: SupportsRead[Buffer] | SupportsReadinto | Callable[[int], Buffer],
838
836
  /,
839
837
  size: int = -1,
840
- chunksize: int = WRITE_BUFSIZE,
838
+ chunksize: int = READ_BUFSIZE,
841
839
  can_buffer: bool = False,
842
840
  callback: None | Callable[[int], Any] = None,
843
841
  ) -> Iterator[Buffer]:
@@ -866,6 +864,8 @@ def bio_chunk_iter(
866
864
  if size < chunksize:
867
865
  del buf[size:]
868
866
  length = readinto(buf)
867
+ if not length:
868
+ return
869
869
  if callback:
870
870
  callback(length)
871
871
  if length < buffer_length(buf):
@@ -889,6 +889,8 @@ def bio_chunk_iter(
889
889
  readsize = min(chunksize, size)
890
890
  chunk = read(readsize)
891
891
  length = buffer_length(chunk)
892
+ if not length:
893
+ return
892
894
  if callback:
893
895
  callback(length)
894
896
  yield chunk
@@ -906,7 +908,7 @@ async def bio_chunk_async_iter(
906
908
  bio: SupportsRead[Buffer] | SupportsRead[Awaitable[Buffer]] | SupportsReadinto | Callable[[int], Buffer] | Callable[[int], Awaitable[Buffer]],
907
909
  /,
908
910
  size: int = -1,
909
- chunksize: int = WRITE_BUFSIZE,
911
+ chunksize: int = READ_BUFSIZE,
910
912
  can_buffer: bool = False,
911
913
  callback: None | Callable[[int], Any] = None,
912
914
  ) -> AsyncIterator[Buffer]:
@@ -934,6 +936,8 @@ async def bio_chunk_async_iter(
934
936
  if size < chunksize:
935
937
  del buf[size:]
936
938
  length = await readinto(buf)
939
+ if not length:
940
+ return
937
941
  if callback:
938
942
  await callback(length)
939
943
  if length < buffer_length(buf):
@@ -957,6 +961,8 @@ async def bio_chunk_async_iter(
957
961
  readsize = min(chunksize, size)
958
962
  chunk = await read(readsize)
959
963
  length = buffer_length(chunk)
964
+ if not length:
965
+ return
960
966
  if callback:
961
967
  await callback(length)
962
968
  yield chunk
@@ -974,7 +980,7 @@ def bio_skip_iter(
974
980
  bio: SupportsRead[Buffer] | SupportsReadinto | Callable[[int], Buffer],
975
981
  /,
976
982
  size: int = -1,
977
- chunksize: int = WRITE_BUFSIZE,
983
+ chunksize: int = READ_BUFSIZE,
978
984
  callback: None | Callable[[int], Any] = None,
979
985
  ) -> Iterator[int]:
980
986
  if size == 0:
@@ -990,7 +996,7 @@ def bio_skip_iter(
990
996
  length = seek(0, 2) - curpos
991
997
  except Exception:
992
998
  if chunksize <= 0:
993
- chunksize = WRITE_BUFSIZE
999
+ chunksize = READ_BUFSIZE
994
1000
  if callable(bio):
995
1001
  read = bio
996
1002
  elif hasattr(bio, "readinto"):
@@ -1045,7 +1051,7 @@ async def bio_skip_async_iter(
1045
1051
  bio: SupportsRead[Buffer] | SupportsRead[Awaitable[Buffer]] | SupportsReadinto | Callable[[int], Buffer] | Callable[[int], Awaitable[Buffer]],
1046
1052
  /,
1047
1053
  size: int = -1,
1048
- chunksize: int = WRITE_BUFSIZE,
1054
+ chunksize: int = READ_BUFSIZE,
1049
1055
  callback: None | Callable[[int], Any] = None,
1050
1056
  ) -> AsyncIterator[int]:
1051
1057
  if size == 0:
@@ -1061,7 +1067,7 @@ async def bio_skip_async_iter(
1061
1067
  length = (await seek(0, 2)) - curpos
1062
1068
  except Exception:
1063
1069
  if chunksize <= 0:
1064
- chunksize = WRITE_BUFSIZE
1070
+ chunksize = READ_BUFSIZE
1065
1071
  if callable(bio):
1066
1072
  read: Callable[[int], Awaitable[Buffer]] = ensure_async(bio, threaded=True)
1067
1073
  elif hasattr(bio, "readinto"):
@@ -1558,7 +1564,7 @@ def bytes_iter_to_async_reader(
1558
1564
  def bytes_to_chunk_iter(
1559
1565
  b: Buffer,
1560
1566
  /,
1561
- chunksize: int = WRITE_BUFSIZE,
1567
+ chunksize: int = READ_BUFSIZE,
1562
1568
  ) -> Iterator[memoryview]:
1563
1569
  m = memoryview(b)
1564
1570
  for i in range(0, buffer_length(m), chunksize):
@@ -1568,7 +1574,7 @@ def bytes_to_chunk_iter(
1568
1574
  async def bytes_to_chunk_async_iter(
1569
1575
  b: Buffer,
1570
1576
  /,
1571
- chunksize: int = WRITE_BUFSIZE,
1577
+ chunksize: int = READ_BUFSIZE,
1572
1578
  ) -> AsyncIterator[memoryview]:
1573
1579
  m = memoryview(b)
1574
1580
  for i in range(0, buffer_length(m), chunksize):
@@ -1578,7 +1584,7 @@ async def bytes_to_chunk_async_iter(
1578
1584
  def bytes_ensure_part_iter(
1579
1585
  it: Iterable[Buffer],
1580
1586
  /,
1581
- partsize: int = WRITE_BUFSIZE,
1587
+ partsize: int = READ_BUFSIZE,
1582
1588
  ) -> Iterator[Buffer]:
1583
1589
  n = partsize
1584
1590
  for b in it:
@@ -1606,7 +1612,7 @@ def bytes_ensure_part_iter(
1606
1612
  async def bytes_ensure_part_async_iter(
1607
1613
  it: Iterable[Buffer] | AsyncIterable[Buffer],
1608
1614
  /,
1609
- partsize: int = WRITE_BUFSIZE,
1615
+ partsize: int = READ_BUFSIZE,
1610
1616
  ) -> AsyncIterator[Buffer]:
1611
1617
  n = partsize
1612
1618
  async for b in ensure_aiter(it):
@@ -1715,10 +1721,10 @@ def copyfileobj(
1715
1721
  fsrc,
1716
1722
  fdst: SupportsWrite[Buffer],
1717
1723
  /,
1718
- chunksize: int = WRITE_BUFSIZE,
1724
+ chunksize: int = READ_BUFSIZE,
1719
1725
  ):
1720
1726
  if chunksize <= 0:
1721
- chunksize = WRITE_BUFSIZE
1727
+ chunksize = READ_BUFSIZE
1722
1728
  fdst_write = fdst.write
1723
1729
  fsrc_read = getattr(fsrc, "read", None)
1724
1730
  fsrc_readinto = getattr(fsrc, "readinto", None)
@@ -1740,11 +1746,11 @@ async def copyfileobj_async(
1740
1746
  fsrc,
1741
1747
  fdst: SupportsWrite[Buffer],
1742
1748
  /,
1743
- chunksize: int = WRITE_BUFSIZE,
1749
+ chunksize: int = READ_BUFSIZE,
1744
1750
  threaded: bool = True,
1745
1751
  ):
1746
1752
  if chunksize <= 0:
1747
- chunksize = WRITE_BUFSIZE
1753
+ chunksize = READ_BUFSIZE
1748
1754
  fdst_write = ensure_async(fdst.write, threaded=threaded)
1749
1755
  fsrc_read = getattr(fsrc, "read", None)
1750
1756
  fsrc_readinto = getattr(fsrc, "readinto", None)
@@ -1,12 +1,12 @@
1
1
  [tool.poetry]
2
2
  name = "python-filewrap"
3
- version = "0.2.8.1"
3
+ version = "0.2.9"
4
4
  description = "Python file wrappers."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
7
7
  readme = "readme.md"
8
- homepage = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-filewrap"
9
- repository = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-filewrap"
8
+ homepage = "https://github.com/ChenyangGao/python-modules/tree/main/python-filewrap"
9
+ repository = "https://github.com/ChenyangGao/python-modules/tree/main/python-filewrap"
10
10
  keywords = ["file", "wrapper"]
11
11
  classifiers = [
12
12
  "License :: OSI Approved :: MIT License",
@@ -27,7 +27,7 @@ include = [
27
27
 
28
28
  [tool.poetry.dependencies]
29
29
  python = "^3.12"
30
- python-asynctools = ">=0.1"
30
+ python-asynctools = ">=0.1.3"
31
31
  python-property = ">=0.0.3"
32
32
 
33
33
  [build-system]