python-filewrap 0.0.8__py3-none-any.whl → 0.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 CHANGED
@@ -2,9 +2,10 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  __author__ = "ChenyangGao <https://chenyanggao.github.io>"
5
- __version__ = (0, 0, 8)
5
+ __version__ = (0, 1)
6
6
  __all__ = [
7
- "SupportsRead", "SupportsWrite", "SupportsSeek",
7
+ "Buffer", "SupportsRead", "SupportsReadinto",
8
+ "SupportsWrite", "SupportsSeek",
8
9
  "bio_chunk_iter", "bio_chunk_async_iter",
9
10
  "bio_skip_iter", "bio_skip_async_iter",
10
11
  "bytes_iter_skip", "bytes_async_iter_skip",
@@ -25,7 +26,39 @@ from typing import runtime_checkable, Any, Protocol, TypeVar
25
26
  try:
26
27
  from collections.abc import Buffer # type: ignore
27
28
  except ImportError:
28
- Buffer = Any
29
+ from abc import ABC, abstractmethod
30
+ from array import array
31
+
32
+ def _check_methods(C, *methods):
33
+ mro = C.__mro__
34
+ for method in methods:
35
+ for B in mro:
36
+ if method in B.__dict__:
37
+ if B.__dict__[method] is None:
38
+ return NotImplemented
39
+ break
40
+ else:
41
+ return NotImplemented
42
+ return True
43
+
44
+ class Buffer(ABC): # type: ignore
45
+ __slots__ = ()
46
+
47
+ @abstractmethod
48
+ def __buffer__(self, flags: int, /) -> memoryview:
49
+ raise NotImplementedError
50
+
51
+ @classmethod
52
+ def __subclasshook__(cls, C):
53
+ if cls is Buffer:
54
+ return _check_methods(C, "__buffer__")
55
+ return NotImplemented
56
+
57
+ Buffer.register(bytes)
58
+ Buffer.register(bytearray)
59
+ Buffer.register(memoryview)
60
+ Buffer.register(array)
61
+
29
62
 
30
63
  from asynctools import async_chain, ensure_async, ensure_aiter
31
64
 
@@ -39,6 +72,11 @@ class SupportsRead(Protocol[_T_co]):
39
72
  def read(self, /, __length: int = ...) -> _T_co: ...
40
73
 
41
74
 
75
+ @runtime_checkable
76
+ class SupportsReadinto(Protocol):
77
+ def readinto(self, /, buf: Buffer = ...) -> int: ...
78
+
79
+
42
80
  @runtime_checkable
43
81
  class SupportsWrite(Protocol[_T_contra]):
44
82
  def write(self, /, __s: _T_contra) -> object: ...
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-filewrap
3
- Version: 0.0.8
3
+ Version: 0.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
@@ -0,0 +1,7 @@
1
+ LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
+ filewrap/__init__.py,sha256=LpqytTgLuqhqPmQpt6yD3LYJLmVow1_QKBx8z8hDRqk,19814
3
+ filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ python_filewrap-0.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
5
+ python_filewrap-0.1.dist-info/METADATA,sha256=dnQEqPHE9x7i5QSZ-SRlr5OWFwYC1qXe8hU8hOoGcWo,1360
6
+ python_filewrap-0.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
7
+ python_filewrap-0.1.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
- filewrap/__init__.py,sha256=kgvpxjHpP0ZfyZsxofnSEjYXClNVhbsQARewbytl01Q,18778
3
- filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- python_filewrap-0.0.8.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
5
- python_filewrap-0.0.8.dist-info/METADATA,sha256=Eb2gtpXftkLvFpwHFIlq8QOw1qHwbWBu0mWxhdEPfP4,1362
6
- python_filewrap-0.0.8.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
7
- python_filewrap-0.0.8.dist-info/RECORD,,