pybare 1.2.4__tar.gz → 1.2.5__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.4 → pybare-1.2.5}/PKG-INFO +22 -19
- {pybare-1.2.4 → pybare-1.2.5}/README.md +2 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/barestruct.py +1 -1
- {pybare-1.2.4 → pybare-1.2.5}/bare/baretype.py +6 -3
- {pybare-1.2.4 → pybare-1.2.5}/bare/test_barearray.py +8 -3
- {pybare-1.2.4 → pybare-1.2.5}/bare/test_barestruct.py +2 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/test_data.py +6 -2
- {pybare-1.2.4 → pybare-1.2.5}/bare/test_encoder.py +8 -3
- {pybare-1.2.4 → pybare-1.2.5}/bare/test_map.py +6 -2
- {pybare-1.2.4 → pybare-1.2.5}/bare/test_misc.py +4 -1
- {pybare-1.2.4 → pybare-1.2.5}/bare/test_number.py +2 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/test_union.py +10 -4
- {pybare-1.2.4 → pybare-1.2.5}/bare/util.py +5 -4
- {pybare-1.2.4 → pybare-1.2.5}/pyproject.toml +1 -1
- {pybare-1.2.4 → pybare-1.2.5}/LICENSE +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/__init__.py +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/_examples/customer.bin +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/_examples/employee.bin +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/_examples/people.bin +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/_examples/terminated.bin +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/barearray.py +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/data.py +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/map.py +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/misc.py +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/number.py +0 -0
- {pybare-1.2.4 → pybare-1.2.5}/bare/union.py +0 -0
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pybare
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.5
|
|
4
4
|
Summary: A BARE Encoding Library and Data Validation Library for Python.
|
|
5
5
|
Author-Email: Noah Pederson <noah@packetlost.dev>
|
|
6
6
|
License: Copyright 2020 Noah Pederson
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
9
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
10
|
+
the Software without restriction, including without limitation the rights to
|
|
11
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
12
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
13
|
+
so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
|
25
|
+
|
|
25
26
|
Classifier: Development Status :: 4 - Beta
|
|
26
27
|
Classifier: Intended Audience :: Developers
|
|
27
28
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -38,6 +39,8 @@ Description-Content-Type: text/markdown
|
|
|
38
39
|
|
|
39
40
|
# PyBARE
|
|
40
41
|
[](https://builds.sr.ht/~chiefnoah/pybare?)
|
|
42
|
+
[](https://pybare.ngp.computer)
|
|
41
44
|
|
|
42
45
|
A declarative implementation of the [BARE](https://baremessages.org/) message
|
|
43
46
|
format for Python 3.10+
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# PyBARE
|
|
2
2
|
[](https://builds.sr.ht/~chiefnoah/pybare?)
|
|
3
|
+
[](https://pybare.ngp.computer)
|
|
3
5
|
|
|
4
6
|
A declarative implementation of the [BARE](https://baremessages.org/) message
|
|
5
7
|
format for Python 3.10+
|
|
@@ -122,7 +122,7 @@ class Struct(BAREType, metaclass=StructMeta):
|
|
|
122
122
|
return NotImplemented
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
def struct(**kwargs:
|
|
125
|
+
def struct(**kwargs: Type[BAREType]) -> Type[Struct]:
|
|
126
126
|
"""
|
|
127
127
|
A function that defines and returnes an anonymous BARE `Struct` subclass with the
|
|
128
128
|
provided `kwargs` as fields. The name of each kwarg becomes the field name, with the
|
|
@@ -7,14 +7,17 @@ T = TypeVar("T", covariant=True)
|
|
|
7
7
|
|
|
8
8
|
class BAREType(Protocol, Generic[T]):
|
|
9
9
|
@abstractmethod
|
|
10
|
-
def __init__(self, *arg, **kwargs):
|
|
10
|
+
def __init__(self, *arg, **kwargs):
|
|
11
|
+
...
|
|
11
12
|
|
|
12
13
|
@abstractmethod
|
|
13
|
-
def pack(self) -> bytes:
|
|
14
|
+
def pack(self) -> bytes:
|
|
15
|
+
...
|
|
14
16
|
|
|
15
17
|
@classmethod
|
|
16
18
|
@abstractmethod
|
|
17
|
-
def unpack(cls, fp: BinaryIO) -> BAREType:
|
|
19
|
+
def unpack(cls, fp: BinaryIO) -> BAREType:
|
|
20
|
+
...
|
|
18
21
|
|
|
19
22
|
@classmethod
|
|
20
23
|
@abstractmethod
|
|
@@ -5,11 +5,15 @@ import bare
|
|
|
5
5
|
import pytest
|
|
6
6
|
import io
|
|
7
7
|
|
|
8
|
+
__all__ = []
|
|
9
|
+
|
|
8
10
|
|
|
9
11
|
def test_2d_array_unsized():
|
|
10
|
-
class InnerArray(Array, inner=UInt):
|
|
12
|
+
class InnerArray(Array, inner=UInt):
|
|
13
|
+
...
|
|
11
14
|
|
|
12
|
-
class My2DArray(Array, inner=InnerArray):
|
|
15
|
+
class My2DArray(Array, inner=InnerArray):
|
|
16
|
+
...
|
|
13
17
|
|
|
14
18
|
input = [[1, 2], [3, 4]]
|
|
15
19
|
x = My2DArray(input)
|
|
@@ -45,7 +49,8 @@ def test_anonymous_array_sized():
|
|
|
45
49
|
|
|
46
50
|
|
|
47
51
|
def test_array_sized():
|
|
48
|
-
class MyArry(Array, inner=UInt, size=3):
|
|
52
|
+
class MyArry(Array, inner=UInt, size=3):
|
|
53
|
+
...
|
|
49
54
|
|
|
50
55
|
input = [1, 2, 3]
|
|
51
56
|
x = MyArry(input)
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
from bare import Data, data
|
|
2
2
|
import io
|
|
3
3
|
|
|
4
|
+
__all__ = []
|
|
5
|
+
|
|
4
6
|
|
|
5
7
|
def test_data_sized():
|
|
6
|
-
class SizedData(Data, size=5):
|
|
8
|
+
class SizedData(Data, size=5):
|
|
9
|
+
...
|
|
7
10
|
|
|
8
11
|
x = SizedData(b"12345")
|
|
9
12
|
b = x.pack()
|
|
@@ -13,7 +16,8 @@ def test_data_sized():
|
|
|
13
16
|
|
|
14
17
|
|
|
15
18
|
def test_data_unsized():
|
|
16
|
-
class SizedData(Data):
|
|
19
|
+
class SizedData(Data):
|
|
20
|
+
...
|
|
17
21
|
|
|
18
22
|
x = SizedData(b"12345")
|
|
19
23
|
b = x.pack()
|
|
@@ -27,6 +27,8 @@ from bare import (
|
|
|
27
27
|
UnionVariant,
|
|
28
28
|
)
|
|
29
29
|
|
|
30
|
+
__all__ = []
|
|
31
|
+
|
|
30
32
|
|
|
31
33
|
class Nested(Struct):
|
|
32
34
|
s = Field(Str)
|
|
@@ -100,7 +102,8 @@ def test_map():
|
|
|
100
102
|
assert map2.value["another"] == "test"
|
|
101
103
|
|
|
102
104
|
|
|
103
|
-
class MyArray(Array, inner=Int):
|
|
105
|
+
class MyArray(Array, inner=Int):
|
|
106
|
+
...
|
|
104
107
|
|
|
105
108
|
|
|
106
109
|
class ArrayTest(Struct):
|
|
@@ -141,7 +144,8 @@ def test_optional():
|
|
|
141
144
|
ex.nested = "test"
|
|
142
145
|
|
|
143
146
|
|
|
144
|
-
class ExampleUnion(Union, variants=(Str, Int)):
|
|
147
|
+
class ExampleUnion(Union, variants=(Str, Int)):
|
|
148
|
+
...
|
|
145
149
|
|
|
146
150
|
|
|
147
151
|
class UnionTest(Struct):
|
|
@@ -234,7 +238,8 @@ class TerminatedEmployee(Void):
|
|
|
234
238
|
pass
|
|
235
239
|
|
|
236
240
|
|
|
237
|
-
class Person(Union, variants=(Customer, Employee, TerminatedEmployee)):
|
|
241
|
+
class Person(Union, variants=(Customer, Employee, TerminatedEmployee)):
|
|
242
|
+
...
|
|
238
243
|
|
|
239
244
|
|
|
240
245
|
@pytest.mark.parametrize(
|
|
@@ -4,8 +4,11 @@ import io
|
|
|
4
4
|
|
|
5
5
|
import pytest
|
|
6
6
|
|
|
7
|
+
__all__ = []
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
class MyMap(Map, key_type=Str, value_type=Int):
|
|
11
|
+
...
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
def test_basic_map():
|
|
@@ -30,7 +33,8 @@ def test_anonymous_map():
|
|
|
30
33
|
def test_nested_map():
|
|
31
34
|
InnerMap = map(Str, Str)
|
|
32
35
|
|
|
33
|
-
class NestedMap(Map, key_type=Str, value_type=InnerMap):
|
|
36
|
+
class NestedMap(Map, key_type=Str, value_type=InnerMap):
|
|
37
|
+
...
|
|
34
38
|
|
|
35
39
|
x = NestedMap({"outer": {"hello": "world"}})
|
|
36
40
|
b = x.pack()
|
|
@@ -3,6 +3,8 @@ from bare import Enum, UInt, Void, Str
|
|
|
3
3
|
import io
|
|
4
4
|
import pytest
|
|
5
5
|
|
|
6
|
+
__all__ = []
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
class MyEnum(Enum):
|
|
8
10
|
A = 1
|
|
@@ -19,7 +21,8 @@ def test_enum_basic():
|
|
|
19
21
|
MyEnum.unpack(io.BytesIO(b))
|
|
20
22
|
|
|
21
23
|
|
|
22
|
-
class MyVoid(Void):
|
|
24
|
+
class MyVoid(Void):
|
|
25
|
+
...
|
|
23
26
|
|
|
24
27
|
|
|
25
28
|
def test_custom_void():
|
|
@@ -3,8 +3,11 @@ import bare
|
|
|
3
3
|
import io
|
|
4
4
|
import pytest
|
|
5
5
|
|
|
6
|
+
__all__ = []
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
class MyUnion(Union, variants=(Str, Int)):
|
|
10
|
+
...
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
def test_union_basic():
|
|
@@ -37,7 +40,8 @@ def test_anonymous_union():
|
|
|
37
40
|
|
|
38
41
|
|
|
39
42
|
def test_explicit_discriminant_implicit_following():
|
|
40
|
-
class MyUnion(Union, variants=(UnionVariant(Str, 4), Int)):
|
|
43
|
+
class MyUnion(Union, variants=(UnionVariant(Str, 4), Int)):
|
|
44
|
+
...
|
|
41
45
|
|
|
42
46
|
x = MyUnion(Str("Hello"))
|
|
43
47
|
b = x.pack()
|
|
@@ -57,7 +61,8 @@ def test_explicit_discriminant_implicit_following():
|
|
|
57
61
|
|
|
58
62
|
|
|
59
63
|
def test_explicit_discriminant_all_cases():
|
|
60
|
-
class MyUnion(Union, variants=(UnionVariant(Str, 4), UnionVariant(Int, 10))):
|
|
64
|
+
class MyUnion(Union, variants=(UnionVariant(Str, 4), UnionVariant(Int, 10))):
|
|
65
|
+
...
|
|
61
66
|
|
|
62
67
|
x = MyUnion(Str("Hello"))
|
|
63
68
|
b = x.pack()
|
|
@@ -96,7 +101,8 @@ class AllPrimativeTypes(
|
|
|
96
101
|
bare.Data,
|
|
97
102
|
bare.Void,
|
|
98
103
|
),
|
|
99
|
-
):
|
|
104
|
+
):
|
|
105
|
+
...
|
|
100
106
|
|
|
101
107
|
|
|
102
108
|
@pytest.mark.parametrize(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Type, TypeVar
|
|
2
|
+
from .misc import Enum
|
|
2
3
|
|
|
3
4
|
from .baretype import BAREType
|
|
4
5
|
|
|
@@ -21,15 +22,15 @@ class Field:
|
|
|
21
22
|
|
|
22
23
|
attr: str
|
|
23
24
|
name: str
|
|
24
|
-
ty: Type[BAREType]
|
|
25
|
+
ty: Type[BAREType | Enum]
|
|
25
26
|
|
|
26
|
-
def __init__(self, ty: Type[BAREType], attr: str | None = None):
|
|
27
|
+
def __init__(self, ty: Type[BAREType | Enum], attr: str | None = None):
|
|
27
28
|
# ignore the typing here because these will always be set when assigned to an
|
|
28
29
|
# object
|
|
29
30
|
self.attr = attr # type: ignore
|
|
30
31
|
self.ty = ty
|
|
31
32
|
|
|
32
|
-
def __get__(self, inst, _) -> T | Type[BAREType[T]]:
|
|
33
|
+
def __get__(self, inst, _) -> T | Type[BAREType[T] | Enum]:
|
|
33
34
|
if inst is None:
|
|
34
35
|
return self.ty
|
|
35
36
|
return inst.__dict__[self.attr]
|
|
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
|