pybare 1.2.0__tar.gz → 1.2.2__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.
- {pybare-1.2.0/pybare.egg-info → pybare-1.2.2}/PKG-INFO +3 -2
- {pybare-1.2.0 → pybare-1.2.2}/bare/barearray.py +10 -5
- {pybare-1.2.0 → pybare-1.2.2}/bare/baretype.py +3 -2
- {pybare-1.2.0 → pybare-1.2.2}/bare/data.py +3 -2
- {pybare-1.2.0 → pybare-1.2.2}/bare/map.py +4 -2
- {pybare-1.2.0 → pybare-1.2.2}/bare/misc.py +8 -10
- {pybare-1.2.0 → pybare-1.2.2}/bare/number.py +16 -14
- {pybare-1.2.0 → pybare-1.2.2}/bare/union.py +2 -2
- {pybare-1.2.0 → pybare-1.2.2/pybare.egg-info}/PKG-INFO +3 -2
- {pybare-1.2.0 → pybare-1.2.2}/setup.py +3 -2
- {pybare-1.2.0 → pybare-1.2.2}/LICENSE +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/README.md +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/__init__.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/barestruct.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/test_barearray.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/test_barestruct.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/test_data.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/test_encoder.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/test_map.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/test_misc.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/test_number.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/test_union.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/bare/util.py +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/pybare.egg-info/SOURCES.txt +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/pybare.egg-info/dependency_links.txt +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/pybare.egg-info/top_level.txt +0 -0
- {pybare-1.2.0 → pybare-1.2.2}/setup.cfg +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pybare
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Summary: A declarative implementation of BARE for Python
|
|
5
5
|
Home-page: https://sr.ht/~chiefnoah/pybare/
|
|
6
6
|
Author: Noah Pederson
|
|
7
7
|
Author-email: noah@packetlost.dev
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
8
9
|
Classifier: Programming Language :: Python :: 3.11
|
|
9
10
|
Classifier: Programming Language :: Python :: 3.12
|
|
10
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
12
|
Classifier: Operating System :: OS Independent
|
|
12
|
-
Requires-Python: >=3.
|
|
13
|
+
Requires-Python: >=3.10
|
|
13
14
|
Description-Content-Type: text/markdown
|
|
14
15
|
License-File: LICENSE
|
|
15
16
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
import io
|
|
2
|
-
from typing import (Any, BinaryIO, ClassVar, Generic, Iterable, Optional,
|
|
3
|
-
Self, Type, TypeVar, _ProtocolMeta)
|
|
4
3
|
from collections import UserList
|
|
4
|
+
from typing import (Any, BinaryIO, ClassVar, Generic, Iterable, Optional, Type,
|
|
5
|
+
TypeVar, _ProtocolMeta)
|
|
5
6
|
|
|
6
7
|
from .baretype import BAREType
|
|
7
8
|
from .number import UInt
|
|
@@ -60,7 +61,9 @@ class ArrayValidator(Generic[T, A]):
|
|
|
60
61
|
else:
|
|
61
62
|
_value.append(v) # type: ignore
|
|
62
63
|
if self.size and len(_value) != self.size:
|
|
63
|
-
raise ValueError(
|
|
64
|
+
raise ValueError(
|
|
65
|
+
f"Array size mismatch. Expected {self.size}, got {len(_value)}"
|
|
66
|
+
)
|
|
64
67
|
inst.__dict__["_inner"] = _value
|
|
65
68
|
|
|
66
69
|
|
|
@@ -144,7 +147,7 @@ class Array(Generic[T, A], BAREType[T], metaclass=ArrayMeta):
|
|
|
144
147
|
return fp.getbuffer()
|
|
145
148
|
|
|
146
149
|
@classmethod
|
|
147
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
150
|
+
def unpack(cls, fp: BinaryIO) -> Array:
|
|
148
151
|
size = cls._size or UInt.unpack(fp).value
|
|
149
152
|
out = []
|
|
150
153
|
for _ in range(size):
|
|
@@ -166,7 +169,9 @@ class Array(Generic[T, A], BAREType[T], metaclass=ArrayMeta):
|
|
|
166
169
|
return f"{self.__class__.__name__}({repr(self.value)})"
|
|
167
170
|
|
|
168
171
|
|
|
169
|
-
def array(
|
|
172
|
+
def array(
|
|
173
|
+
inner: Type[BAREType[Any]], size: Optional[int] = None
|
|
174
|
+
) -> Type[Array[Any, A]]:
|
|
170
175
|
"""
|
|
171
176
|
A function that defines and returns anonymous BARE `Array` subclass with
|
|
172
177
|
the provided `inner` type and (optional) `size` arguments.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
from abc import abstractmethod
|
|
2
|
-
from typing import Any, BinaryIO, Generic, Protocol, TypeVar
|
|
3
|
+
from typing import Any, BinaryIO, Generic, Protocol, TypeVar
|
|
3
4
|
|
|
4
5
|
T = TypeVar("T", covariant=True)
|
|
5
6
|
|
|
@@ -15,7 +16,7 @@ class BAREType(Protocol, Generic[T]):
|
|
|
15
16
|
|
|
16
17
|
@classmethod
|
|
17
18
|
@abstractmethod
|
|
18
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
19
|
+
def unpack(cls, fp: BinaryIO) -> BAREType:
|
|
19
20
|
...
|
|
20
21
|
|
|
21
22
|
@classmethod
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
import io
|
|
2
|
-
from typing import Any, BinaryIO, Optional,
|
|
3
|
+
from typing import Any, BinaryIO, Optional, Type, TypeVar, _ProtocolMeta
|
|
3
4
|
|
|
4
5
|
from .baretype import BAREType
|
|
5
6
|
from .number import UInt
|
|
@@ -64,7 +65,7 @@ class Data(BAREType[bytes], metaclass=DataMeta):
|
|
|
64
65
|
return self.value == other.value
|
|
65
66
|
|
|
66
67
|
@classmethod
|
|
67
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
68
|
+
def unpack(cls, fp: BinaryIO) -> Data:
|
|
68
69
|
size = cls._size or UInt.unpack(fp).value
|
|
69
70
|
buf = fp.read(size)
|
|
70
71
|
return cls(buf)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import io
|
|
2
|
-
from typing import Any, BinaryIO, Mapping,
|
|
4
|
+
from typing import Any, BinaryIO, Mapping, Type, TypeVar, _ProtocolMeta
|
|
3
5
|
|
|
4
6
|
from .baretype import BAREType
|
|
5
7
|
from .number import UInt
|
|
@@ -99,7 +101,7 @@ class Map(BAREType[dict[K, V]], metaclass=MapMeta):
|
|
|
99
101
|
return fp.getbuffer()
|
|
100
102
|
|
|
101
103
|
@classmethod
|
|
102
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
104
|
+
def unpack(cls, fp: BinaryIO) -> Map:
|
|
103
105
|
size = UInt.unpack(fp).value
|
|
104
106
|
out = {}
|
|
105
107
|
for _ in range(size):
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import io
|
|
2
|
-
from enum import
|
|
3
|
-
from typing import Any, BinaryIO
|
|
4
|
+
from enum import EnumMeta, IntEnum
|
|
5
|
+
from typing import Any, BinaryIO
|
|
4
6
|
|
|
5
7
|
from .baretype import BAREType
|
|
6
8
|
from .number import UInt
|
|
@@ -8,11 +10,7 @@ from .number import UInt
|
|
|
8
10
|
__all__ = ["Enum", "Void", "Str"]
|
|
9
11
|
|
|
10
12
|
|
|
11
|
-
class
|
|
12
|
-
...
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class Enum(BAREType[int], IntEnum, metaclass=BAREEnumMeta):
|
|
13
|
+
class Enum(IntEnum, metaclass=EnumMeta):
|
|
16
14
|
"""
|
|
17
15
|
A BARE enum type. It is a subclass of `IntEnum` and is used to represent
|
|
18
16
|
a BARE enum type.
|
|
@@ -38,7 +36,7 @@ class Enum(BAREType[int], IntEnum, metaclass=BAREEnumMeta):
|
|
|
38
36
|
return UInt(self.value).pack()
|
|
39
37
|
|
|
40
38
|
@classmethod
|
|
41
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
39
|
+
def unpack(cls, fp: BinaryIO) -> Enum:
|
|
42
40
|
x = UInt.unpack(fp).value
|
|
43
41
|
return cls(x)
|
|
44
42
|
|
|
@@ -74,7 +72,7 @@ class Void:
|
|
|
74
72
|
return bytes()
|
|
75
73
|
|
|
76
74
|
@classmethod
|
|
77
|
-
def unpack(cls, _: BinaryIO) ->
|
|
75
|
+
def unpack(cls, _: BinaryIO) -> Void:
|
|
78
76
|
return cls()
|
|
79
77
|
|
|
80
78
|
def __eq__(self, other: Any) -> bool:
|
|
@@ -126,7 +124,7 @@ class Str(BAREType[str]):
|
|
|
126
124
|
return isinstance(value, (str, cls))
|
|
127
125
|
|
|
128
126
|
@classmethod
|
|
129
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
127
|
+
def unpack(cls, fp: BinaryIO) -> Str:
|
|
130
128
|
size = UInt.unpack(fp).value
|
|
131
129
|
buf = fp.read(size)
|
|
132
130
|
if len(buf) != size:
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import io
|
|
2
4
|
import struct
|
|
3
|
-
from typing import Any, BinaryIO, Generic,
|
|
5
|
+
from typing import Any, BinaryIO, Generic, TypeVar
|
|
4
6
|
|
|
5
7
|
from .baretype import BAREType
|
|
6
8
|
|
|
@@ -64,7 +66,7 @@ class UInt(NumberMixin[int], BAREType[int]):
|
|
|
64
66
|
return buf.getvalue()
|
|
65
67
|
|
|
66
68
|
@classmethod
|
|
67
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
69
|
+
def unpack(cls, fp: BinaryIO) -> UInt:
|
|
68
70
|
return cls(_read_varint(fp, False))
|
|
69
71
|
|
|
70
72
|
@classmethod
|
|
@@ -102,7 +104,7 @@ class Int(NumberMixin[int]):
|
|
|
102
104
|
return buf.getvalue()
|
|
103
105
|
|
|
104
106
|
@classmethod
|
|
105
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
107
|
+
def unpack(cls, fp: BinaryIO) -> Int:
|
|
106
108
|
return cls(_read_varint(fp, True))
|
|
107
109
|
|
|
108
110
|
@classmethod
|
|
@@ -136,7 +138,7 @@ class F64(NumberMixin[float]):
|
|
|
136
138
|
return struct.pack("<d", self.value)
|
|
137
139
|
|
|
138
140
|
@classmethod
|
|
139
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
141
|
+
def unpack(cls, fp: BinaryIO) -> F64:
|
|
140
142
|
buf = fp.read(struct.calcsize("<d"))
|
|
141
143
|
return cls(struct.unpack("<d", buf)[0])
|
|
142
144
|
|
|
@@ -169,7 +171,7 @@ class F32(NumberMixin[float]):
|
|
|
169
171
|
return struct.pack("<f", self.value)
|
|
170
172
|
|
|
171
173
|
@classmethod
|
|
172
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
174
|
+
def unpack(cls, fp: BinaryIO) -> F32:
|
|
173
175
|
buf = fp.read(struct.calcsize("<f"))
|
|
174
176
|
return cls(struct.unpack("<f", buf)[0]) # type: ignore
|
|
175
177
|
|
|
@@ -193,7 +195,7 @@ class U8(NumberMixin[int]):
|
|
|
193
195
|
return struct.pack("<B", self.value)
|
|
194
196
|
|
|
195
197
|
@classmethod
|
|
196
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
198
|
+
def unpack(cls, fp: BinaryIO) -> U8:
|
|
197
199
|
buf = fp.read(struct.calcsize("<B"))
|
|
198
200
|
return cls(struct.unpack("<B", buf)[0]) # type: ignore
|
|
199
201
|
|
|
@@ -217,7 +219,7 @@ class Bool(NumberMixin[bool]):
|
|
|
217
219
|
return struct.pack("<?", self.value)
|
|
218
220
|
|
|
219
221
|
@classmethod
|
|
220
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
222
|
+
def unpack(cls, fp: BinaryIO) -> Bool:
|
|
221
223
|
buf = fp.read(struct.calcsize("<?"))
|
|
222
224
|
return cls(struct.unpack("<?", buf)[0]) # type: ignore
|
|
223
225
|
|
|
@@ -235,7 +237,7 @@ class I8(NumberMixin[int]):
|
|
|
235
237
|
return struct.pack("<b", self.value)
|
|
236
238
|
|
|
237
239
|
@classmethod
|
|
238
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
240
|
+
def unpack(cls, fp: BinaryIO) -> I8:
|
|
239
241
|
buf = fp.read(struct.calcsize("<b"))
|
|
240
242
|
return cls(struct.unpack("<b", buf)[0]) # type: ignore
|
|
241
243
|
|
|
@@ -259,7 +261,7 @@ class U16(NumberMixin[int]):
|
|
|
259
261
|
return struct.pack("<H", self.value)
|
|
260
262
|
|
|
261
263
|
@classmethod
|
|
262
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
264
|
+
def unpack(cls, fp: BinaryIO) -> U16:
|
|
263
265
|
buf = fp.read(struct.calcsize("<H"))
|
|
264
266
|
return cls(struct.unpack("<H", buf)[0]) # type: ignore
|
|
265
267
|
|
|
@@ -283,7 +285,7 @@ class I16(NumberMixin[int]):
|
|
|
283
285
|
return struct.pack("<h", self.value)
|
|
284
286
|
|
|
285
287
|
@classmethod
|
|
286
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
288
|
+
def unpack(cls, fp: BinaryIO) -> I16:
|
|
287
289
|
buf = fp.read(struct.calcsize("<h"))
|
|
288
290
|
return cls(struct.unpack("<h", buf)[0]) # type: ignore
|
|
289
291
|
|
|
@@ -307,7 +309,7 @@ class U32(NumberMixin[int]):
|
|
|
307
309
|
return struct.pack("<L", self.value)
|
|
308
310
|
|
|
309
311
|
@classmethod
|
|
310
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
312
|
+
def unpack(cls, fp: BinaryIO) -> U32:
|
|
311
313
|
buf = fp.read(struct.calcsize("<L"))
|
|
312
314
|
return cls(struct.unpack("<L", buf)[0]) # type: ignore
|
|
313
315
|
|
|
@@ -331,7 +333,7 @@ class I32(NumberMixin[int]):
|
|
|
331
333
|
return struct.pack("<l", self.value)
|
|
332
334
|
|
|
333
335
|
@classmethod
|
|
334
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
336
|
+
def unpack(cls, fp: BinaryIO) -> I32:
|
|
335
337
|
buf = fp.read(struct.calcsize("<l"))
|
|
336
338
|
return cls(struct.unpack("<l", buf)[0]) # type: ignore
|
|
337
339
|
|
|
@@ -355,7 +357,7 @@ class U64(NumberMixin[int]):
|
|
|
355
357
|
return struct.pack("<Q", self.value)
|
|
356
358
|
|
|
357
359
|
@classmethod
|
|
358
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
360
|
+
def unpack(cls, fp: BinaryIO) -> U64:
|
|
359
361
|
buf = fp.read(struct.calcsize("<Q"))
|
|
360
362
|
return cls(struct.unpack("<Q", buf)[0]) # type: ignore
|
|
361
363
|
|
|
@@ -382,7 +384,7 @@ class I64(NumberMixin[int]):
|
|
|
382
384
|
return struct.pack("<q", self.value)
|
|
383
385
|
|
|
384
386
|
@classmethod
|
|
385
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
387
|
+
def unpack(cls, fp: BinaryIO) -> I64:
|
|
386
388
|
buf = fp.read(struct.calcsize("<q"))
|
|
387
389
|
return cls(struct.unpack("<q", buf)[0]) # type: ignore
|
|
388
390
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import io
|
|
4
|
-
from typing import Any, BinaryIO, Generic, Iterable,
|
|
4
|
+
from typing import Any, BinaryIO, Generic, Iterable, Type, TypeVar
|
|
5
5
|
|
|
6
6
|
from .misc import Void
|
|
7
7
|
from .number import UInt
|
|
@@ -104,7 +104,7 @@ class Union(metaclass=UnionMeta, variants=()):
|
|
|
104
104
|
return buf.getbuffer()
|
|
105
105
|
|
|
106
106
|
@classmethod
|
|
107
|
-
def unpack(cls, fp: BinaryIO) ->
|
|
107
|
+
def unpack(cls, fp: BinaryIO) -> Union:
|
|
108
108
|
discriminant = UInt.unpack(fp).value
|
|
109
109
|
if discriminant not in cls._variants:
|
|
110
110
|
raise TypeError(
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pybare
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Summary: A declarative implementation of BARE for Python
|
|
5
5
|
Home-page: https://sr.ht/~chiefnoah/pybare/
|
|
6
6
|
Author: Noah Pederson
|
|
7
7
|
Author-email: noah@packetlost.dev
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
8
9
|
Classifier: Programming Language :: Python :: 3.11
|
|
9
10
|
Classifier: Programming Language :: Python :: 3.12
|
|
10
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
12
|
Classifier: Operating System :: OS Independent
|
|
12
|
-
Requires-Python: >=3.
|
|
13
|
+
Requires-Python: >=3.10
|
|
13
14
|
Description-Content-Type: text/markdown
|
|
14
15
|
License-File: LICENSE
|
|
15
16
|
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|
|
5
5
|
|
|
6
6
|
setuptools.setup(
|
|
7
7
|
name="pybare", # Replace with your own username
|
|
8
|
-
version="1.2.
|
|
8
|
+
version="1.2.2",
|
|
9
9
|
author="Noah Pederson",
|
|
10
10
|
author_email="noah@packetlost.dev",
|
|
11
11
|
description="A declarative implementation of BARE for Python",
|
|
@@ -14,10 +14,11 @@ setuptools.setup(
|
|
|
14
14
|
url="https://sr.ht/~chiefnoah/pybare/",
|
|
15
15
|
packages=setuptools.find_packages(),
|
|
16
16
|
classifiers=[
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
17
18
|
"Programming Language :: Python :: 3.11",
|
|
18
19
|
"Programming Language :: Python :: 3.12",
|
|
19
20
|
"License :: OSI Approved :: MIT License",
|
|
20
21
|
"Operating System :: OS Independent",
|
|
21
22
|
],
|
|
22
|
-
python_requires=">=3.
|
|
23
|
+
python_requires=">=3.10",
|
|
23
24
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|