soia-client 1.0.14__py3-none-any.whl → 1.0.16__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.
Potentially problematic release.
This version of soia-client might be problematic. Click here for more details.
- soia/__init__.py +30 -0
- {soialib/impl → soia/_impl}/arrays.py +10 -10
- {soialib/impl → soia/_impl}/enums.py +10 -10
- {soialib → soia/_impl}/keyed_items.py +0 -1
- {soialib → soia/_impl}/method.py +1 -1
- {soialib → soia/_impl}/never.py +0 -1
- {soialib/impl → soia/_impl}/optionals.py +8 -8
- {soialib/impl → soia/_impl}/primitives.py +25 -25
- {soialib → soia/_impl}/serializer.py +8 -7
- {soialib → soia/_impl}/serializers.py +5 -5
- {soialib → soia/_impl}/service.py +29 -5
- {soialib → soia/_impl}/service_client.py +1 -2
- {soialib/impl → soia/_impl}/structs.py +10 -10
- {soialib/impl → soia/_impl}/type_adapter.py +6 -6
- soialib/module_initializer.py → soia/_module_initializer.py +23 -22
- {soia_client-1.0.14.dist-info → soia_client-1.0.16.dist-info}/METADATA +1 -1
- soia_client-1.0.16.dist-info/RECORD +26 -0
- soia_client-1.0.16.dist-info/top_level.txt +1 -0
- soia_client-1.0.14.dist-info/RECORD +0 -27
- soia_client-1.0.14.dist-info/top_level.txt +0 -1
- soialib/_.py +0 -3
- soialib/__init__.py +0 -25
- {soialib/impl → soia/_impl}/__init__.py +0 -0
- {soialib/impl → soia/_impl}/function_maker.py +0 -0
- {soialib/impl → soia/_impl}/repr.py +0 -0
- {soialib → soia/_impl}/timestamp.py +0 -0
- /soialib/spec.py → /soia/_spec.py +0 -0
- {soialib → soia}/reflection.py +0 -0
- {soia_client-1.0.14.dist-info → soia_client-1.0.16.dist-info}/WHEEL +0 -0
- {soia_client-1.0.14.dist-info → soia_client-1.0.16.dist-info}/licenses/LICENSE +0 -0
soia/__init__.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import typing as _typing
|
|
2
|
+
|
|
3
|
+
from soia._impl.keyed_items import KeyedItems
|
|
4
|
+
from soia._impl.method import Method
|
|
5
|
+
from soia._impl.serializer import Serializer
|
|
6
|
+
from soia._impl.serializers import (
|
|
7
|
+
array_serializer,
|
|
8
|
+
optional_serializer,
|
|
9
|
+
primitive_serializer,
|
|
10
|
+
)
|
|
11
|
+
from soia._impl.service import RequestHeaders, ResponseHeaders, Service
|
|
12
|
+
from soia._impl.service_client import ServiceClient
|
|
13
|
+
from soia._impl.timestamp import Timestamp
|
|
14
|
+
|
|
15
|
+
_: _typing.Final[_typing.Any] = None
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"_",
|
|
19
|
+
"KeyedItems",
|
|
20
|
+
"Method",
|
|
21
|
+
"RequestHeaders",
|
|
22
|
+
"ResponseHeaders",
|
|
23
|
+
"Serializer",
|
|
24
|
+
"Service",
|
|
25
|
+
"ServiceClient",
|
|
26
|
+
"Timestamp",
|
|
27
|
+
"array_serializer",
|
|
28
|
+
"optional_serializer",
|
|
29
|
+
"primitive_serializer",
|
|
30
|
+
]
|
|
@@ -3,11 +3,11 @@ from dataclasses import FrozenInstanceError
|
|
|
3
3
|
from typing import Generic, Optional
|
|
4
4
|
from weakref import WeakValueDictionary
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
from
|
|
8
|
-
from
|
|
9
|
-
|
|
10
|
-
from
|
|
6
|
+
from soia._impl.function_maker import Any, Expr, ExprLike, Line, make_function
|
|
7
|
+
from soia._impl.keyed_items import Item, Key, KeyedItems
|
|
8
|
+
from soia._impl.type_adapter import TypeAdapter
|
|
9
|
+
|
|
10
|
+
from soia import _spec, reflection
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def get_array_adapter(
|
|
@@ -104,14 +104,14 @@ class _ArrayAdapter(TypeAdapter):
|
|
|
104
104
|
|
|
105
105
|
def finalize(
|
|
106
106
|
self,
|
|
107
|
-
resolve_type_fn: Callable[[
|
|
107
|
+
resolve_type_fn: Callable[[_spec.Type], "TypeAdapter"],
|
|
108
108
|
) -> None:
|
|
109
109
|
self.item_adapter.finalize(resolve_type_fn)
|
|
110
110
|
|
|
111
|
-
def get_type(self) ->
|
|
112
|
-
return
|
|
111
|
+
def get_type(self) -> reflection.Type:
|
|
112
|
+
return reflection.ArrayType(
|
|
113
113
|
kind="array",
|
|
114
|
-
value=
|
|
114
|
+
value=reflection.ArrayType.Array(
|
|
115
115
|
item=self.item_adapter.get_type(),
|
|
116
116
|
key_chain=self.key_attributes,
|
|
117
117
|
),
|
|
@@ -119,7 +119,7 @@ class _ArrayAdapter(TypeAdapter):
|
|
|
119
119
|
|
|
120
120
|
def register_records(
|
|
121
121
|
self,
|
|
122
|
-
registry: dict[str,
|
|
122
|
+
registry: dict[str, reflection.Record],
|
|
123
123
|
) -> None:
|
|
124
124
|
self.item_adapter.register_records(registry)
|
|
125
125
|
|
|
@@ -3,11 +3,11 @@ from collections.abc import Callable, Sequence
|
|
|
3
3
|
from dataclasses import FrozenInstanceError, dataclass
|
|
4
4
|
from typing import Any, Final, Union
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
from
|
|
8
|
-
from
|
|
9
|
-
|
|
10
|
-
from
|
|
6
|
+
from soia._impl.function_maker import BodyBuilder, Expr, ExprLike, Line, make_function
|
|
7
|
+
from soia._impl.repr import repr_impl
|
|
8
|
+
from soia._impl.type_adapter import TypeAdapter
|
|
9
|
+
|
|
10
|
+
from soia import _spec, reflection
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class EnumAdapter(TypeAdapter):
|
|
@@ -119,24 +119,24 @@ class EnumAdapter(TypeAdapter):
|
|
|
119
119
|
Expr.local("_cls?", self.gen_class), f".{fn_name}(", json_expr, ")"
|
|
120
120
|
)
|
|
121
121
|
|
|
122
|
-
def get_type(self) ->
|
|
123
|
-
return
|
|
122
|
+
def get_type(self) -> reflection.Type:
|
|
123
|
+
return reflection.RecordType(
|
|
124
124
|
kind="record",
|
|
125
125
|
value=self.spec.id,
|
|
126
126
|
)
|
|
127
127
|
|
|
128
128
|
def register_records(
|
|
129
129
|
self,
|
|
130
|
-
registry: dict[str,
|
|
130
|
+
registry: dict[str, reflection.Record],
|
|
131
131
|
) -> None:
|
|
132
132
|
record_id = self.spec.id
|
|
133
133
|
if record_id in registry:
|
|
134
134
|
return
|
|
135
|
-
registry[record_id] =
|
|
135
|
+
registry[record_id] = reflection.Record(
|
|
136
136
|
kind="enum",
|
|
137
137
|
id=record_id,
|
|
138
138
|
fields=tuple(
|
|
139
|
-
|
|
139
|
+
reflection.Field(
|
|
140
140
|
name=field.spec.name,
|
|
141
141
|
number=field.spec.number,
|
|
142
142
|
type=field.field_type.get_type(),
|
{soialib → soia/_impl}/method.py
RENAMED
{soialib → soia/_impl}/never.py
RENAMED
|
@@ -3,10 +3,10 @@ from dataclasses import dataclass
|
|
|
3
3
|
from typing import TypeVar
|
|
4
4
|
from weakref import WeakValueDictionary
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
from
|
|
8
|
-
|
|
9
|
-
from
|
|
6
|
+
from soia._impl.function_maker import Expr, ExprLike
|
|
7
|
+
from soia._impl.type_adapter import TypeAdapter
|
|
8
|
+
|
|
9
|
+
from soia import _spec, reflection
|
|
10
10
|
|
|
11
11
|
Other = TypeVar("Other")
|
|
12
12
|
|
|
@@ -64,19 +64,19 @@ class _OptionalAdapter(TypeAdapter):
|
|
|
64
64
|
|
|
65
65
|
def finalize(
|
|
66
66
|
self,
|
|
67
|
-
resolve_type_fn: Callable[[
|
|
67
|
+
resolve_type_fn: Callable[[_spec.Type], "TypeAdapter"],
|
|
68
68
|
) -> None:
|
|
69
69
|
self.other_adapter.finalize(resolve_type_fn)
|
|
70
70
|
|
|
71
|
-
def get_type(self) ->
|
|
72
|
-
return
|
|
71
|
+
def get_type(self) -> reflection.Type:
|
|
72
|
+
return reflection.OptionalType(
|
|
73
73
|
kind="optional",
|
|
74
74
|
value=self.other_adapter.get_type(),
|
|
75
75
|
)
|
|
76
76
|
|
|
77
77
|
def register_records(
|
|
78
78
|
self,
|
|
79
|
-
registry: dict[str,
|
|
79
|
+
registry: dict[str, reflection.Record],
|
|
80
80
|
) -> None:
|
|
81
81
|
self.other_adapter.register_records(registry)
|
|
82
82
|
|
|
@@ -2,25 +2,25 @@ from collections.abc import Callable
|
|
|
2
2
|
from dataclasses import dataclass
|
|
3
3
|
from typing import Any, Final, final
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
from
|
|
7
|
-
from
|
|
8
|
-
|
|
9
|
-
from
|
|
5
|
+
from soia._impl.function_maker import Expr, ExprLike
|
|
6
|
+
from soia._impl.timestamp import Timestamp
|
|
7
|
+
from soia._impl.type_adapter import TypeAdapter
|
|
8
|
+
|
|
9
|
+
from soia import _spec, reflection
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class AbstractPrimitiveAdapter(TypeAdapter):
|
|
13
13
|
@final
|
|
14
14
|
def finalize(
|
|
15
15
|
self,
|
|
16
|
-
resolve_type_fn: Callable[[
|
|
16
|
+
resolve_type_fn: Callable[[_spec.Type], "TypeAdapter"],
|
|
17
17
|
) -> None:
|
|
18
18
|
pass
|
|
19
19
|
|
|
20
20
|
@final
|
|
21
21
|
def register_records(
|
|
22
22
|
self,
|
|
23
|
-
|
|
23
|
+
registry: dict[str, reflection.Record],
|
|
24
24
|
) -> None:
|
|
25
25
|
pass
|
|
26
26
|
|
|
@@ -48,8 +48,8 @@ class _BoolAdapter(AbstractPrimitiveAdapter):
|
|
|
48
48
|
def from_json_expr(self, json_expr: ExprLike) -> Expr:
|
|
49
49
|
return Expr.join("(True if ", json_expr, " else False)")
|
|
50
50
|
|
|
51
|
-
def get_type(self) ->
|
|
52
|
-
return
|
|
51
|
+
def get_type(self) -> reflection.Type:
|
|
52
|
+
return reflection.PrimitiveType(
|
|
53
53
|
kind="primitive",
|
|
54
54
|
value="bool",
|
|
55
55
|
)
|
|
@@ -94,8 +94,8 @@ class _Int32Adapter(_AbstractIntAdapter):
|
|
|
94
94
|
" < 2147483647 else 2147483647)",
|
|
95
95
|
)
|
|
96
96
|
|
|
97
|
-
def get_type(self) ->
|
|
98
|
-
return
|
|
97
|
+
def get_type(self) -> reflection.Type:
|
|
98
|
+
return reflection.PrimitiveType(
|
|
99
99
|
kind="primitive",
|
|
100
100
|
value="int32",
|
|
101
101
|
)
|
|
@@ -120,8 +120,8 @@ class _Int64Adapter(_AbstractIntAdapter):
|
|
|
120
120
|
def to_json_expr(self, in_expr: ExprLike, readable: bool) -> Expr:
|
|
121
121
|
return Expr.join(Expr.local("int64_to_json", _int64_to_json), "(", in_expr, ")")
|
|
122
122
|
|
|
123
|
-
def get_type(self) ->
|
|
124
|
-
return
|
|
123
|
+
def get_type(self) -> reflection.Type:
|
|
124
|
+
return reflection.PrimitiveType(
|
|
125
125
|
kind="primitive",
|
|
126
126
|
value="int64",
|
|
127
127
|
)
|
|
@@ -145,8 +145,8 @@ class _Uint64Adapter(_AbstractIntAdapter):
|
|
|
145
145
|
Expr.local("uint64_to_json", _uint64_to_json), "(", in_expr, ")"
|
|
146
146
|
)
|
|
147
147
|
|
|
148
|
-
def get_type(self) ->
|
|
149
|
-
return
|
|
148
|
+
def get_type(self) -> reflection.Type:
|
|
149
|
+
return reflection.PrimitiveType(
|
|
150
150
|
kind="primitive",
|
|
151
151
|
value="uint64",
|
|
152
152
|
)
|
|
@@ -181,8 +181,8 @@ class _AbstractFloatAdapter(AbstractPrimitiveAdapter):
|
|
|
181
181
|
class _Float32Adapter(_AbstractFloatAdapter):
|
|
182
182
|
"""Type adapter implementation for float32."""
|
|
183
183
|
|
|
184
|
-
def get_type(self) ->
|
|
185
|
-
return
|
|
184
|
+
def get_type(self) -> reflection.Type:
|
|
185
|
+
return reflection.PrimitiveType(
|
|
186
186
|
kind="primitive",
|
|
187
187
|
value="float32",
|
|
188
188
|
)
|
|
@@ -192,8 +192,8 @@ class _Float32Adapter(_AbstractFloatAdapter):
|
|
|
192
192
|
class _Float64Adapter(_AbstractFloatAdapter):
|
|
193
193
|
"""Type adapter implementation for float32."""
|
|
194
194
|
|
|
195
|
-
def get_type(self) ->
|
|
196
|
-
return
|
|
195
|
+
def get_type(self) -> reflection.Type:
|
|
196
|
+
return reflection.PrimitiveType(
|
|
197
197
|
kind="primitive",
|
|
198
198
|
value="float64",
|
|
199
199
|
)
|
|
@@ -236,8 +236,8 @@ class _TimestampAdapter(AbstractPrimitiveAdapter):
|
|
|
236
236
|
fn = Expr.local("_timestamp_from_json", _timestamp_from_json)
|
|
237
237
|
return Expr.join(fn, "(", json_expr, ")")
|
|
238
238
|
|
|
239
|
-
def get_type(self) ->
|
|
240
|
-
return
|
|
239
|
+
def get_type(self) -> reflection.Type:
|
|
240
|
+
return reflection.PrimitiveType(
|
|
241
241
|
kind="primitive",
|
|
242
242
|
value="timestamp",
|
|
243
243
|
)
|
|
@@ -269,8 +269,8 @@ class _StringAdapter(AbstractPrimitiveAdapter):
|
|
|
269
269
|
def from_json_expr(self, json_expr: ExprLike) -> Expr:
|
|
270
270
|
return Expr.join("('' + (", json_expr, " or ''))")
|
|
271
271
|
|
|
272
|
-
def get_type(self) ->
|
|
273
|
-
return
|
|
272
|
+
def get_type(self) -> reflection.Type:
|
|
273
|
+
return reflection.PrimitiveType(
|
|
274
274
|
kind="primitive",
|
|
275
275
|
value="string",
|
|
276
276
|
)
|
|
@@ -303,8 +303,8 @@ class _BytesAdapter(AbstractPrimitiveAdapter):
|
|
|
303
303
|
Expr.local("fromhex", _BytesAdapter._fromhex_fn), "(", json_expr, ' or "")'
|
|
304
304
|
)
|
|
305
305
|
|
|
306
|
-
def get_type(self) ->
|
|
307
|
-
return
|
|
306
|
+
def get_type(self) -> reflection.Type:
|
|
307
|
+
return reflection.PrimitiveType(
|
|
308
308
|
kind="primitive",
|
|
309
309
|
value="bytes",
|
|
310
310
|
)
|
|
@@ -5,10 +5,11 @@ from functools import cached_property
|
|
|
5
5
|
from typing import Any, Generic, TypeVar, cast, final
|
|
6
6
|
from weakref import WeakValueDictionary
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
from
|
|
10
|
-
from
|
|
11
|
-
|
|
8
|
+
from soia._impl.function_maker import Expr, LineSpan, make_function
|
|
9
|
+
from soia._impl.never import Never
|
|
10
|
+
from soia._impl.type_adapter import TypeAdapter
|
|
11
|
+
|
|
12
|
+
from soia import reflection
|
|
12
13
|
|
|
13
14
|
T = TypeVar("T")
|
|
14
15
|
|
|
@@ -61,10 +62,10 @@ class Serializer(Generic[T]):
|
|
|
61
62
|
return self._from_json_fn(jsonlib.loads(json_code))
|
|
62
63
|
|
|
63
64
|
@cached_property
|
|
64
|
-
def type_descriptor(self) ->
|
|
65
|
-
records: dict[str,
|
|
65
|
+
def type_descriptor(self) -> reflection.TypeDescriptor:
|
|
66
|
+
records: dict[str, reflection.Record] = {}
|
|
66
67
|
self._adapter.register_records(records)
|
|
67
|
-
return
|
|
68
|
+
return reflection.TypeDescriptor(
|
|
68
69
|
type=self._adapter.get_type(),
|
|
69
70
|
records=tuple(records.values()),
|
|
70
71
|
)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from typing import Final, Literal, TypeVar, overload
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from
|
|
5
|
-
from
|
|
6
|
-
from
|
|
7
|
-
from
|
|
3
|
+
from soia._impl import primitives
|
|
4
|
+
from soia._impl.arrays import get_array_adapter
|
|
5
|
+
from soia._impl.optionals import get_optional_adapter
|
|
6
|
+
from soia._impl.serializer import Serializer, make_serializer
|
|
7
|
+
from soia._impl.timestamp import Timestamp
|
|
8
8
|
|
|
9
9
|
Item = TypeVar("Item")
|
|
10
10
|
Other = TypeVar("Other")
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
import json
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
-
from typing import Any, Callable, Generic, Literal,
|
|
4
|
+
from typing import Any, Callable, Generic, Literal, Protocol, TypeAlias, Union, cast
|
|
5
|
+
|
|
6
|
+
from soia._impl.method import Method, Request, Response
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RequestHeaders(Protocol):
|
|
10
|
+
def __getitem__(self, key: str, /) -> str | None: ...
|
|
5
11
|
|
|
6
|
-
from soialib.method import Method, Request, Response
|
|
7
12
|
|
|
8
|
-
RequestHeaders: TypeAlias = Mapping[str, str]
|
|
9
13
|
ResponseHeaders: TypeAlias = dict[str, str]
|
|
10
14
|
|
|
11
15
|
|
|
12
|
-
class
|
|
16
|
+
class Service:
|
|
13
17
|
_number_to_method_impl: dict[int, "_MethodImpl"]
|
|
14
18
|
|
|
15
19
|
def __init__(self):
|
|
@@ -23,7 +27,7 @@ class ServiceImpl:
|
|
|
23
27
|
Callable[[Request, RequestHeaders], Response],
|
|
24
28
|
Callable[[Request, RequestHeaders, ResponseHeaders], Response],
|
|
25
29
|
],
|
|
26
|
-
) -> "
|
|
30
|
+
) -> "Service":
|
|
27
31
|
signature = inspect.Signature.from_callable(impl)
|
|
28
32
|
num_positional_params = 0
|
|
29
33
|
for param in signature.parameters.values():
|
|
@@ -69,6 +73,26 @@ class ServiceImpl:
|
|
|
69
73
|
data: str
|
|
70
74
|
type: Literal["ok-json", "bad-request", "server-error"]
|
|
71
75
|
|
|
76
|
+
@property
|
|
77
|
+
def status_code(self):
|
|
78
|
+
if self.type == "ok-json":
|
|
79
|
+
return 200
|
|
80
|
+
elif self.type == "bad-request":
|
|
81
|
+
return 400
|
|
82
|
+
elif self.type == "server-error":
|
|
83
|
+
return 500
|
|
84
|
+
else:
|
|
85
|
+
raise TypeError(f"Unknown response type: {self.type}")
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def content_type(self):
|
|
89
|
+
if self.type == "ok-json":
|
|
90
|
+
return "application/json"
|
|
91
|
+
elif self.type == "bad-request" or self.type == "server-error":
|
|
92
|
+
return "text/plain; charset=utf-8"
|
|
93
|
+
else:
|
|
94
|
+
raise TypeError(f"Unknown response type: {self.type}")
|
|
95
|
+
|
|
72
96
|
def handle_request(
|
|
73
97
|
self,
|
|
74
98
|
req_body: str,
|
|
@@ -3,9 +3,7 @@ from collections.abc import Callable, Sequence
|
|
|
3
3
|
from dataclasses import FrozenInstanceError, dataclass
|
|
4
4
|
from typing import Any, Final, Union, cast
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
from soialib import spec as _spec
|
|
8
|
-
from soialib.impl.function_maker import (
|
|
6
|
+
from soia._impl.function_maker import (
|
|
9
7
|
BodyBuilder,
|
|
10
8
|
Expr,
|
|
11
9
|
ExprLike,
|
|
@@ -16,8 +14,10 @@ from soialib.impl.function_maker import (
|
|
|
16
14
|
Params,
|
|
17
15
|
make_function,
|
|
18
16
|
)
|
|
19
|
-
from
|
|
20
|
-
from
|
|
17
|
+
from soia._impl.repr import repr_impl
|
|
18
|
+
from soia._impl.type_adapter import TypeAdapter
|
|
19
|
+
|
|
20
|
+
from soia import _spec, reflection
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class StructAdapter(TypeAdapter):
|
|
@@ -201,24 +201,24 @@ class StructAdapter(TypeAdapter):
|
|
|
201
201
|
Expr.local("_cls?", self.gen_class), f".{fn_name}(", json_expr, ")"
|
|
202
202
|
)
|
|
203
203
|
|
|
204
|
-
def get_type(self) ->
|
|
205
|
-
return
|
|
204
|
+
def get_type(self) -> reflection.Type:
|
|
205
|
+
return reflection.RecordType(
|
|
206
206
|
kind="record",
|
|
207
207
|
value=self.spec.id,
|
|
208
208
|
)
|
|
209
209
|
|
|
210
210
|
def register_records(
|
|
211
211
|
self,
|
|
212
|
-
registry: dict[str,
|
|
212
|
+
registry: dict[str, reflection.Record],
|
|
213
213
|
) -> None:
|
|
214
214
|
record_id = self.spec.id
|
|
215
215
|
if record_id in registry:
|
|
216
216
|
return
|
|
217
|
-
registry[record_id] =
|
|
217
|
+
registry[record_id] = reflection.Record(
|
|
218
218
|
kind="struct",
|
|
219
219
|
id=record_id,
|
|
220
220
|
fields=tuple(
|
|
221
|
-
|
|
221
|
+
reflection.Field(
|
|
222
222
|
name=field.field.name,
|
|
223
223
|
number=field.field.number,
|
|
224
224
|
type=field.type.get_type(),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from collections.abc import Callable
|
|
2
2
|
from typing import Protocol
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
from
|
|
4
|
+
from soia._impl.function_maker import ExprLike
|
|
5
|
+
|
|
6
|
+
from soia import _spec, reflection
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class TypeAdapter(Protocol):
|
|
@@ -52,12 +52,12 @@ class TypeAdapter(Protocol):
|
|
|
52
52
|
|
|
53
53
|
def finalize(
|
|
54
54
|
self,
|
|
55
|
-
resolve_type_fn: Callable[[
|
|
55
|
+
resolve_type_fn: Callable[[_spec.Type], "TypeAdapter"],
|
|
56
56
|
) -> None: ...
|
|
57
57
|
|
|
58
|
-
def get_type(self) ->
|
|
58
|
+
def get_type(self) -> reflection.Type: ...
|
|
59
59
|
|
|
60
60
|
def register_records(
|
|
61
61
|
self,
|
|
62
|
-
registry: dict[str,
|
|
62
|
+
registry: dict[str, reflection.Record],
|
|
63
63
|
) -> None: ...
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
from typing import Any, Union
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from
|
|
5
|
-
from
|
|
6
|
-
|
|
3
|
+
from soia._impl import arrays, enums, method, optionals, primitives, structs
|
|
4
|
+
from soia._impl.serializer import make_serializer
|
|
5
|
+
from soia._impl.type_adapter import TypeAdapter
|
|
6
|
+
|
|
7
|
+
from soia import _spec
|
|
7
8
|
|
|
8
9
|
RecordAdapter = Union[structs.StructAdapter, enums.EnumAdapter]
|
|
9
10
|
|
|
@@ -12,39 +13,39 @@ _record_id_to_adapter: dict[str, RecordAdapter] = {}
|
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
def init_module(
|
|
15
|
-
records: tuple[
|
|
16
|
-
methods: tuple[
|
|
17
|
-
constants: tuple[
|
|
16
|
+
records: tuple[_spec.Record, ...],
|
|
17
|
+
methods: tuple[_spec.Method, ...],
|
|
18
|
+
constants: tuple[_spec.Constant, ...],
|
|
18
19
|
globals: dict[str, Any],
|
|
19
20
|
# For testing
|
|
20
21
|
record_id_to_adapter: dict[str, RecordAdapter] = _record_id_to_adapter,
|
|
21
22
|
) -> None:
|
|
22
|
-
def resolve_type(type:
|
|
23
|
-
if isinstance(type,
|
|
24
|
-
if type ==
|
|
23
|
+
def resolve_type(type: _spec.Type) -> TypeAdapter:
|
|
24
|
+
if isinstance(type, _spec.PrimitiveType):
|
|
25
|
+
if type == _spec.PrimitiveType.BOOL:
|
|
25
26
|
return primitives.BOOL_ADAPTER
|
|
26
|
-
elif type ==
|
|
27
|
+
elif type == _spec.PrimitiveType.BYTES:
|
|
27
28
|
return primitives.BYTES_ADAPTER
|
|
28
|
-
elif type ==
|
|
29
|
+
elif type == _spec.PrimitiveType.FLOAT32:
|
|
29
30
|
return primitives.FLOAT32_ADAPTER
|
|
30
|
-
elif type ==
|
|
31
|
+
elif type == _spec.PrimitiveType.FLOAT64:
|
|
31
32
|
return primitives.FLOAT64_ADAPTER
|
|
32
|
-
elif type ==
|
|
33
|
+
elif type == _spec.PrimitiveType.INT32:
|
|
33
34
|
return primitives.INT32_ADAPTER
|
|
34
|
-
elif type ==
|
|
35
|
+
elif type == _spec.PrimitiveType.INT64:
|
|
35
36
|
return primitives.INT64_ADAPTER
|
|
36
|
-
elif type ==
|
|
37
|
+
elif type == _spec.PrimitiveType.STRING:
|
|
37
38
|
return primitives.STRING_ADAPTER
|
|
38
|
-
elif type ==
|
|
39
|
+
elif type == _spec.PrimitiveType.TIMESTAMP:
|
|
39
40
|
return primitives.TIMESTAMP_ADAPTER
|
|
40
|
-
elif type ==
|
|
41
|
+
elif type == _spec.PrimitiveType.UINT64:
|
|
41
42
|
return primitives.UINT64_ADAPTER
|
|
42
|
-
elif isinstance(type,
|
|
43
|
+
elif isinstance(type, _spec.ArrayType):
|
|
43
44
|
return arrays.get_array_adapter(
|
|
44
45
|
resolve_type(type.item),
|
|
45
46
|
type.key_attributes,
|
|
46
47
|
)
|
|
47
|
-
elif isinstance(type,
|
|
48
|
+
elif isinstance(type, _spec.OptionalType):
|
|
48
49
|
return optionals.get_optional_adapter(resolve_type(type.other))
|
|
49
50
|
elif isinstance(type, str):
|
|
50
51
|
# A record id.
|
|
@@ -55,7 +56,7 @@ def init_module(
|
|
|
55
56
|
if record.id in record_id_to_adapter:
|
|
56
57
|
raise AssertionError(record.id)
|
|
57
58
|
adapter: RecordAdapter
|
|
58
|
-
if isinstance(record,
|
|
59
|
+
if isinstance(record, _spec.Struct):
|
|
59
60
|
adapter = structs.StructAdapter(record)
|
|
60
61
|
else:
|
|
61
62
|
adapter = enums.EnumAdapter(record)
|
|
@@ -67,7 +68,7 @@ def init_module(
|
|
|
67
68
|
gen_class = adapter.gen_class
|
|
68
69
|
# Add the class name to either globals() if the record is defined at the top
|
|
69
70
|
# level, or the parent class otherwise.
|
|
70
|
-
record_id =
|
|
71
|
+
record_id = _spec.RecordId.parse(adapter.spec.id)
|
|
71
72
|
parent_id = record_id.parent
|
|
72
73
|
class_name = adapter.spec.class_name
|
|
73
74
|
if parent_id:
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
soia/__init__.py,sha256=mI-PNb0RHa0mq4m0e6NKIcQsR8EFkTeKHzh6bVbnRYg,722
|
|
2
|
+
soia/_module_initializer.py,sha256=1TWnc0qUO7_iljQR2ywVERrrkY5jIkT3zucc-AYZyrQ,4221
|
|
3
|
+
soia/_spec.py,sha256=Y5EHHQa6qNeJc29aaqGrFPnPFXxlL7TED9_AXUGBjf0,3663
|
|
4
|
+
soia/reflection.py,sha256=U5knJGmawARCdcEhNxek4dvx48WLPETLqIqKBPWwT4Q,8771
|
|
5
|
+
soia/_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
soia/_impl/arrays.py,sha256=VjvO3-OpBIk6JvGFdTgKhpano1AeHcMCvr0FjeN-GxA,5443
|
|
7
|
+
soia/_impl/enums.py,sha256=Pc9ngDPNfDtUKl0tXRTti6hfqMW1-6SA3SogkOa389A,16962
|
|
8
|
+
soia/_impl/function_maker.py,sha256=MvCDv1WwzKGJzZbNCnJ_8-MP3m1xTIabumXA-9Ydd9M,5639
|
|
9
|
+
soia/_impl/keyed_items.py,sha256=EoPrdeLJ8i7zCH-oW-7qOcyadyrzykB6lkrf3xRVmyk,337
|
|
10
|
+
soia/_impl/method.py,sha256=C6ygh-Li4zADxFR_gfeBTuPUzLjZ1XHCp0ZI4-uiRYs,455
|
|
11
|
+
soia/_impl/never.py,sha256=T7PHtIipuXlici4wa0yuJKrn9JgcT-ODC3QVCwsPprY,46
|
|
12
|
+
soia/_impl/optionals.py,sha256=KTgmbfYLJLrju5v10jgnnnW98QG6NYw2We3gdgi9i2E,2414
|
|
13
|
+
soia/_impl/primitives.py,sha256=Xk26Fv4oQG2oXd3tS_2sAnJYQdXYX9nva09713AcJvs,8940
|
|
14
|
+
soia/_impl/repr.py,sha256=7WX0bEAVENTjlyZIcbT8TcJylS7IRIyafGCmqaIMxFM,1413
|
|
15
|
+
soia/_impl/serializer.py,sha256=28IwkjtUnLpbnPQfVNfJXkApCK4JhXHwLkC5MVhF8xo,3529
|
|
16
|
+
soia/_impl/serializers.py,sha256=IL9jHHMo11pgrL1-crarOEElvTyV5YM6FTcgumjW6IU,2564
|
|
17
|
+
soia/_impl/service.py,sha256=Z0HZlitdEyosbrTXK8OQMnqvahywUJPi7GRTnyRE8B4,6004
|
|
18
|
+
soia/_impl/service_client.py,sha256=5gS7tUt0LJdKGxJsjNU6-aQaZk4dRg1alT83oJfqIZo,2218
|
|
19
|
+
soia/_impl/structs.py,sha256=YTc3Ykj2TxPquar2XsP2DhFfkfIoELXOveyd8yTqN90,26545
|
|
20
|
+
soia/_impl/timestamp.py,sha256=lXBNH8mPmzflkNjSKZSBl2XS-ot9N8N92B_zGO2SMtU,4078
|
|
21
|
+
soia/_impl/type_adapter.py,sha256=RyIyh4Fnt9rMy0HRzC-a2v2JAdZsV9FBzoGEUVygVRE,2101
|
|
22
|
+
soia_client-1.0.16.dist-info/licenses/LICENSE,sha256=SaAftKkX6hfSOiPdENQPS70tifH3PDHgazq8eK2Pwfw,1064
|
|
23
|
+
soia_client-1.0.16.dist-info/METADATA,sha256=mAhZErll3dmFwg-rMhQWEwd-EWFi9yf2rvCpBjS3a14,1667
|
|
24
|
+
soia_client-1.0.16.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
25
|
+
soia_client-1.0.16.dist-info/top_level.txt,sha256=lsYG9JrvauFe1oIV5zvnwsS9hsx3ztwfK_937op9mxc,5
|
|
26
|
+
soia_client-1.0.16.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
soia
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
soia_client-1.0.14.dist-info/licenses/LICENSE,sha256=SaAftKkX6hfSOiPdENQPS70tifH3PDHgazq8eK2Pwfw,1064
|
|
2
|
-
soialib/_.py,sha256=I4SxBM3brmE9D6hyrDrdkbfVnDLVRWaGwnj0C9Zxh54,52
|
|
3
|
-
soialib/__init__.py,sha256=pUvVymO9x1rI68xZkbVvrhO1sHs4ECQ5pu2R2xHjoio,636
|
|
4
|
-
soialib/keyed_items.py,sha256=q7MCn82obf-0jh7FcAhuw4eh9-wtuHIpkEFcSfc8EaY,338
|
|
5
|
-
soialib/method.py,sha256=2qWG4jMqYhS3hA8y8YDu3iqzhXA_AKebpB38RWNmsYQ,452
|
|
6
|
-
soialib/module_initializer.py,sha256=Riq6B6cS9HUG1W8tyaa0GkiG3F4fGX70bKU0UOCnrRw,4205
|
|
7
|
-
soialib/never.py,sha256=bYU63XyNX4e2wOUXQHhHWGO-an4IFr9_ur1ut6GmGN0,47
|
|
8
|
-
soialib/reflection.py,sha256=U5knJGmawARCdcEhNxek4dvx48WLPETLqIqKBPWwT4Q,8771
|
|
9
|
-
soialib/serializer.py,sha256=Lprzy8RTWjwpQ5D4L0lj8NTpUAZxpzjfc-qUQs9egHs,3551
|
|
10
|
-
soialib/serializers.py,sha256=vNLNsfuu6dF0ivJF6v7wQj5Yr6uo2kZHXG5tMrYiVTA,2564
|
|
11
|
-
soialib/service.py,sha256=LWNlf2fH8ZgtssjXJnLiFQmtWTg4CrWo20y-Qlf2HXA,5263
|
|
12
|
-
soialib/service_client.py,sha256=zJ7MhrTiF-T1yXJwCXcHyKbiD19QfUSAoxfj32B62a0,2234
|
|
13
|
-
soialib/spec.py,sha256=Y5EHHQa6qNeJc29aaqGrFPnPFXxlL7TED9_AXUGBjf0,3663
|
|
14
|
-
soialib/timestamp.py,sha256=lXBNH8mPmzflkNjSKZSBl2XS-ot9N8N92B_zGO2SMtU,4078
|
|
15
|
-
soialib/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
-
soialib/impl/arrays.py,sha256=jvyaCAralf-gmdbQxVd5-KobEs32LcMN6DUlBo3m9A8,5490
|
|
17
|
-
soialib/impl/enums.py,sha256=xzBfpN5lQDzulPicZNRuqe4eAZ82DxCd_zWr8XxCUDw,17032
|
|
18
|
-
soialib/impl/function_maker.py,sha256=MvCDv1WwzKGJzZbNCnJ_8-MP3m1xTIabumXA-9Ydd9M,5639
|
|
19
|
-
soialib/impl/optionals.py,sha256=rAtylhc6LM4kNLYkbLF5kVLCxNa0A1tYglHvlQszLMQ,2456
|
|
20
|
-
soialib/impl/primitives.py,sha256=E3rd6TZWDGqBzmrFwVGG2DZLMwDVoznLmilAgoCTT5Q,9106
|
|
21
|
-
soialib/impl/repr.py,sha256=7WX0bEAVENTjlyZIcbT8TcJylS7IRIyafGCmqaIMxFM,1413
|
|
22
|
-
soialib/impl/structs.py,sha256=3YW05rDRmp3G38FZ4CbIjudz6Txog3ymcD28NHf0uGA,26615
|
|
23
|
-
soialib/impl/type_adapter.py,sha256=Q-PacpFKXfYBRF6dqHaf3VO7BcvqG7C6k5aXDFACMGY,2133
|
|
24
|
-
soia_client-1.0.14.dist-info/METADATA,sha256=CeNC9i68qb1GPp5eH8FMDYDm4_lDmjDHjZ9CxsY_yQI,1667
|
|
25
|
-
soia_client-1.0.14.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
26
|
-
soia_client-1.0.14.dist-info/top_level.txt,sha256=2vPmAo5G0SrCxYrNdJKJJVdpalYppgjO2mmz2PtsFUI,8
|
|
27
|
-
soia_client-1.0.14.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
soialib
|
soialib/_.py
DELETED
soialib/__init__.py
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
from soialib.keyed_items import KeyedItems
|
|
2
|
-
from soialib.method import Method
|
|
3
|
-
from soialib.serializer import Serializer
|
|
4
|
-
from soialib.serializers import (
|
|
5
|
-
array_serializer,
|
|
6
|
-
optional_serializer,
|
|
7
|
-
primitive_serializer,
|
|
8
|
-
)
|
|
9
|
-
from soialib.service import RequestHeaders, ResponseHeaders, ServiceImpl
|
|
10
|
-
from soialib.service_client import ServiceClient
|
|
11
|
-
from soialib.timestamp import Timestamp
|
|
12
|
-
|
|
13
|
-
__all__ = [
|
|
14
|
-
"KeyedItems",
|
|
15
|
-
"Method",
|
|
16
|
-
"RequestHeaders",
|
|
17
|
-
"ResponseHeaders",
|
|
18
|
-
"Serializer",
|
|
19
|
-
"ServiceImpl",
|
|
20
|
-
"ServiceClient",
|
|
21
|
-
"Timestamp",
|
|
22
|
-
"array_serializer",
|
|
23
|
-
"optional_serializer",
|
|
24
|
-
"primitive_serializer",
|
|
25
|
-
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{soialib → soia}/reflection.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|