pybare 1.2.2__tar.gz → 1.2.3__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.2 → pybare-1.2.3}/PKG-INFO +17 -10
- {pybare-1.2.2 → pybare-1.2.3}/README.md +16 -9
- {pybare-1.2.2 → pybare-1.2.3}/bare/__init__.py +2 -1
- {pybare-1.2.2 → pybare-1.2.3}/bare/barestruct.py +25 -2
- {pybare-1.2.2 → pybare-1.2.3}/bare/test_barestruct.py +8 -1
- {pybare-1.2.2 → pybare-1.2.3}/pybare.egg-info/PKG-INFO +17 -10
- {pybare-1.2.2 → pybare-1.2.3}/setup.py +1 -1
- {pybare-1.2.2 → pybare-1.2.3}/LICENSE +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/barearray.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/baretype.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/data.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/map.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/misc.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/number.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/test_barearray.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/test_data.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/test_encoder.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/test_map.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/test_misc.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/test_number.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/test_union.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/union.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/bare/util.py +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/pybare.egg-info/SOURCES.txt +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/pybare.egg-info/dependency_links.txt +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/pybare.egg-info/top_level.txt +0 -0
- {pybare-1.2.2 → pybare-1.2.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pybare
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.3
|
|
4
4
|
Summary: A declarative implementation of BARE for Python
|
|
5
5
|
Home-page: https://sr.ht/~chiefnoah/pybare/
|
|
6
6
|
Author: Noah Pederson
|
|
@@ -18,7 +18,7 @@ License-File: LICENSE
|
|
|
18
18
|
[](https://builds.sr.ht/~chiefnoah/pybare?)
|
|
19
19
|
|
|
20
20
|
A declarative implementation of the [BARE](https://baremessages.org/) message
|
|
21
|
-
format for Python 3.
|
|
21
|
+
format for Python 3.10+
|
|
22
22
|
|
|
23
23
|
---
|
|
24
24
|
|
|
@@ -40,36 +40,43 @@ pip install pybare
|
|
|
40
40
|
pybare fully implements all BARE types for both encoding and decoding. This
|
|
41
41
|
includes reading multiple messages from the same `BinaryIO` stream.
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
## Gotchas
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
- [ ] More tests
|
|
48
|
-
- [ ] Fast C implementation for encoding
|
|
45
|
+
We use "Array" / "array" instead of "List" / "list" to avoid conflicts with Python's
|
|
46
|
+
common builtin type of the same name.
|
|
49
47
|
|
|
50
48
|
## Examples
|
|
51
49
|
|
|
50
|
+
An example that defines the types used as an example in the RFC may be found in
|
|
51
|
+
[`example.py`](./example.py)
|
|
52
|
+
|
|
52
53
|
pybare currently requires you define your structures by hand. Examples can be
|
|
53
54
|
found in the
|
|
54
55
|
[tests](https://git.sr.ht/~chiefnoah/pybare/tree/master/bare/test_encoder.py).
|
|
55
56
|
|
|
56
57
|
### Quickstart
|
|
57
58
|
|
|
59
|
+
The general convention is type identifiers start with a *capital* letter and anonymous
|
|
60
|
+
generating functions begin with a lowercase. This follows general "pythonic" style for
|
|
61
|
+
classes vs functions.
|
|
62
|
+
|
|
58
63
|
```python
|
|
59
|
-
from bare import Struct, map, Str, UInt, optional, data, array, Void
|
|
64
|
+
from bare import Struct, map, Str, UInt, optional, data, array, Void, struct, U8
|
|
60
65
|
|
|
61
66
|
# Alternatively, class Data(size=64): ...
|
|
62
67
|
PubKey = data(64) # 512 bits
|
|
63
68
|
|
|
64
69
|
class User(Struct):
|
|
65
|
-
username =
|
|
70
|
+
username = Field(Str)
|
|
66
71
|
userid = Field(Int)
|
|
67
72
|
email = Field(optional(Str))
|
|
68
73
|
keys = Field(map(Str, PubKey))
|
|
69
74
|
repos = Field(array(Str)) # variable length array
|
|
75
|
+
# anonymous array and struct
|
|
76
|
+
friends = Field(array(struct(name=Str, age=U8)))
|
|
70
77
|
|
|
71
78
|
|
|
72
|
-
noah = User(username="chiefnoah", userid=1, email=Void(), keys={}, repos=[])
|
|
79
|
+
noah = User(username="chiefnoah", userid=1, email=Void(), keys={}, repos=[], friends=[])
|
|
73
80
|
noah.username == 'chiefnoah'
|
|
74
81
|
noah.username = 'someoneelse'
|
|
75
82
|
noah.username == 'someoneelse'
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
[](https://builds.sr.ht/~chiefnoah/pybare?)
|
|
3
3
|
|
|
4
4
|
A declarative implementation of the [BARE](https://baremessages.org/) message
|
|
5
|
-
format for Python 3.
|
|
5
|
+
format for Python 3.10+
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -24,36 +24,43 @@ pip install pybare
|
|
|
24
24
|
pybare fully implements all BARE types for both encoding and decoding. This
|
|
25
25
|
includes reading multiple messages from the same `BinaryIO` stream.
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
## Gotchas
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- [ ] More tests
|
|
32
|
-
- [ ] Fast C implementation for encoding
|
|
29
|
+
We use "Array" / "array" instead of "List" / "list" to avoid conflicts with Python's
|
|
30
|
+
common builtin type of the same name.
|
|
33
31
|
|
|
34
32
|
## Examples
|
|
35
33
|
|
|
34
|
+
An example that defines the types used as an example in the RFC may be found in
|
|
35
|
+
[`example.py`](./example.py)
|
|
36
|
+
|
|
36
37
|
pybare currently requires you define your structures by hand. Examples can be
|
|
37
38
|
found in the
|
|
38
39
|
[tests](https://git.sr.ht/~chiefnoah/pybare/tree/master/bare/test_encoder.py).
|
|
39
40
|
|
|
40
41
|
### Quickstart
|
|
41
42
|
|
|
43
|
+
The general convention is type identifiers start with a *capital* letter and anonymous
|
|
44
|
+
generating functions begin with a lowercase. This follows general "pythonic" style for
|
|
45
|
+
classes vs functions.
|
|
46
|
+
|
|
42
47
|
```python
|
|
43
|
-
from bare import Struct, map, Str, UInt, optional, data, array, Void
|
|
48
|
+
from bare import Struct, map, Str, UInt, optional, data, array, Void, struct, U8
|
|
44
49
|
|
|
45
50
|
# Alternatively, class Data(size=64): ...
|
|
46
51
|
PubKey = data(64) # 512 bits
|
|
47
52
|
|
|
48
53
|
class User(Struct):
|
|
49
|
-
username =
|
|
54
|
+
username = Field(Str)
|
|
50
55
|
userid = Field(Int)
|
|
51
56
|
email = Field(optional(Str))
|
|
52
57
|
keys = Field(map(Str, PubKey))
|
|
53
58
|
repos = Field(array(Str)) # variable length array
|
|
59
|
+
# anonymous array and struct
|
|
60
|
+
friends = Field(array(struct(name=Str, age=U8)))
|
|
54
61
|
|
|
55
62
|
|
|
56
|
-
noah = User(username="chiefnoah", userid=1, email=Void(), keys={}, repos=[])
|
|
63
|
+
noah = User(username="chiefnoah", userid=1, email=Void(), keys={}, repos=[], friends=[])
|
|
57
64
|
noah.username == 'chiefnoah'
|
|
58
65
|
noah.username = 'someoneelse'
|
|
59
66
|
noah.username == 'someoneelse'
|
|
@@ -7,7 +7,7 @@ BARE RFC.
|
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
from .barearray import Array, array
|
|
10
|
-
from .barestruct import Field, Struct
|
|
10
|
+
from .barestruct import Field, Struct, struct
|
|
11
11
|
from .baretype import BAREType
|
|
12
12
|
from .data import Data, data
|
|
13
13
|
from .map import Map, map
|
|
@@ -43,6 +43,7 @@ __all__ = [
|
|
|
43
43
|
"array",
|
|
44
44
|
"Field",
|
|
45
45
|
"Struct",
|
|
46
|
+
"struct",
|
|
46
47
|
"Map",
|
|
47
48
|
"map",
|
|
48
49
|
]
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Any, BinaryIO, _ProtocolMeta
|
|
3
|
+
from typing import Any, BinaryIO, _ProtocolMeta, Type, Dict, TypeVar
|
|
4
4
|
|
|
5
5
|
from .util import Field
|
|
6
6
|
from .baretype import BAREType
|
|
7
7
|
|
|
8
|
-
__all__ = ["Struct"]
|
|
8
|
+
__all__ = ["Struct", "struct"]
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
T = TypeVar("T")
|
|
12
|
+
|
|
11
13
|
class StructMeta(_ProtocolMeta, type):
|
|
12
14
|
def __new__(cls, clsname, bases, clsdict):
|
|
13
15
|
fields = {}
|
|
@@ -118,3 +120,24 @@ class Struct(BAREType, metaclass=StructMeta):
|
|
|
118
120
|
return False
|
|
119
121
|
return True
|
|
120
122
|
return NotImplemented
|
|
123
|
+
|
|
124
|
+
def struct(**kwargs: Dict[str, BAREType[T]]) -> Type[Struct]:
|
|
125
|
+
"""
|
|
126
|
+
A function that defines and returnes an anonymous BARE `Struct` subclass with the
|
|
127
|
+
provided `kwargs` as fields. The name of each kwarg becomes the field name, with the
|
|
128
|
+
value being the field type. The field type is implicitly wrapped in a `Field`.Field
|
|
129
|
+
|
|
130
|
+
Proper usage of this function is as follows:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
MyStruct = struct(a=UInt, b=Str)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Note that the name of the class is unspecified, use at your own risk.
|
|
137
|
+
"""
|
|
138
|
+
name = "Struct_{}_anonymous".format("_".join(kwargs.keys()))
|
|
139
|
+
namespace = StructMeta.__prepare__(name, (Struct,))
|
|
140
|
+
namespace.update({field: Field(ty) for field, ty in kwargs.items()}) # type: ignore
|
|
141
|
+
AnonymousStruct = StructMeta.__new__(StructMeta, name, (Struct,), namespace)
|
|
142
|
+
StructMeta.__init__(AnonymousStruct, name, (Struct,), namespace)
|
|
143
|
+
return AnonymousStruct
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import io
|
|
2
|
-
from bare import Struct, UInt, Str, Field
|
|
2
|
+
from bare import Struct, UInt, Str, Field, struct
|
|
3
3
|
|
|
4
4
|
def test_struct_basic():
|
|
5
5
|
class MyStruct(Struct):
|
|
@@ -22,3 +22,10 @@ def test_nested_struct():
|
|
|
22
22
|
b = x.pack()
|
|
23
23
|
x2 = MyStruct.unpack(io.BytesIO(b))
|
|
24
24
|
assert x == x2
|
|
25
|
+
|
|
26
|
+
def test_anonymous_struct():
|
|
27
|
+
MyStruct = struct(name=Str, age=UInt)
|
|
28
|
+
x = MyStruct(name="Noah", age=27)
|
|
29
|
+
b = x.pack()
|
|
30
|
+
x2 = MyStruct.unpack(io.BytesIO(b))
|
|
31
|
+
assert x == x2
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pybare
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.3
|
|
4
4
|
Summary: A declarative implementation of BARE for Python
|
|
5
5
|
Home-page: https://sr.ht/~chiefnoah/pybare/
|
|
6
6
|
Author: Noah Pederson
|
|
@@ -18,7 +18,7 @@ License-File: LICENSE
|
|
|
18
18
|
[](https://builds.sr.ht/~chiefnoah/pybare?)
|
|
19
19
|
|
|
20
20
|
A declarative implementation of the [BARE](https://baremessages.org/) message
|
|
21
|
-
format for Python 3.
|
|
21
|
+
format for Python 3.10+
|
|
22
22
|
|
|
23
23
|
---
|
|
24
24
|
|
|
@@ -40,36 +40,43 @@ pip install pybare
|
|
|
40
40
|
pybare fully implements all BARE types for both encoding and decoding. This
|
|
41
41
|
includes reading multiple messages from the same `BinaryIO` stream.
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
## Gotchas
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
- [ ] More tests
|
|
48
|
-
- [ ] Fast C implementation for encoding
|
|
45
|
+
We use "Array" / "array" instead of "List" / "list" to avoid conflicts with Python's
|
|
46
|
+
common builtin type of the same name.
|
|
49
47
|
|
|
50
48
|
## Examples
|
|
51
49
|
|
|
50
|
+
An example that defines the types used as an example in the RFC may be found in
|
|
51
|
+
[`example.py`](./example.py)
|
|
52
|
+
|
|
52
53
|
pybare currently requires you define your structures by hand. Examples can be
|
|
53
54
|
found in the
|
|
54
55
|
[tests](https://git.sr.ht/~chiefnoah/pybare/tree/master/bare/test_encoder.py).
|
|
55
56
|
|
|
56
57
|
### Quickstart
|
|
57
58
|
|
|
59
|
+
The general convention is type identifiers start with a *capital* letter and anonymous
|
|
60
|
+
generating functions begin with a lowercase. This follows general "pythonic" style for
|
|
61
|
+
classes vs functions.
|
|
62
|
+
|
|
58
63
|
```python
|
|
59
|
-
from bare import Struct, map, Str, UInt, optional, data, array, Void
|
|
64
|
+
from bare import Struct, map, Str, UInt, optional, data, array, Void, struct, U8
|
|
60
65
|
|
|
61
66
|
# Alternatively, class Data(size=64): ...
|
|
62
67
|
PubKey = data(64) # 512 bits
|
|
63
68
|
|
|
64
69
|
class User(Struct):
|
|
65
|
-
username =
|
|
70
|
+
username = Field(Str)
|
|
66
71
|
userid = Field(Int)
|
|
67
72
|
email = Field(optional(Str))
|
|
68
73
|
keys = Field(map(Str, PubKey))
|
|
69
74
|
repos = Field(array(Str)) # variable length array
|
|
75
|
+
# anonymous array and struct
|
|
76
|
+
friends = Field(array(struct(name=Str, age=U8)))
|
|
70
77
|
|
|
71
78
|
|
|
72
|
-
noah = User(username="chiefnoah", userid=1, email=Void(), keys={}, repos=[])
|
|
79
|
+
noah = User(username="chiefnoah", userid=1, email=Void(), keys={}, repos=[], friends=[])
|
|
73
80
|
noah.username == 'chiefnoah'
|
|
74
81
|
noah.username = 'someoneelse'
|
|
75
82
|
noah.username == 'someoneelse'
|
|
@@ -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.3",
|
|
9
9
|
author="Noah Pederson",
|
|
10
10
|
author_email="noah@packetlost.dev",
|
|
11
11
|
description="A declarative implementation of BARE for Python",
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|