python-filewrap 0.0.8__tar.gz → 0.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.0.8 → python_filewrap-0.1}/PKG-INFO +1 -1
- {python_filewrap-0.0.8 → python_filewrap-0.1}/filewrap/__init__.py +41 -3
- {python_filewrap-0.0.8 → python_filewrap-0.1}/pyproject.toml +1 -1
- {python_filewrap-0.0.8 → python_filewrap-0.1}/LICENSE +0 -0
- {python_filewrap-0.0.8 → python_filewrap-0.1}/filewrap/py.typed +0 -0
- {python_filewrap-0.0.8 → python_filewrap-0.1}/readme.md +0 -0
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0,
|
|
5
|
+
__version__ = (0, 1)
|
|
6
6
|
__all__ = [
|
|
7
|
-
"
|
|
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
|
-
|
|
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: ...
|
|
File without changes
|
|
File without changes
|
|
File without changes
|