soia-client 1.0.27__py3-none-any.whl → 1.0.29__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/_impl/enums.py +3 -0
- soia/_impl/service.py +108 -39
- soia/_impl/service_client.py +1 -1
- {soia_client-1.0.27.dist-info → soia_client-1.0.29.dist-info}/METADATA +1 -1
- {soia_client-1.0.27.dist-info → soia_client-1.0.29.dist-info}/RECORD +8 -8
- {soia_client-1.0.27.dist-info → soia_client-1.0.29.dist-info}/WHEEL +0 -0
- {soia_client-1.0.27.dist-info → soia_client-1.0.29.dist-info}/licenses/LICENSE +0 -0
- {soia_client-1.0.27.dist-info → soia_client-1.0.29.dist-info}/top_level.txt +0 -0
soia/_impl/enums.py
CHANGED
|
@@ -41,6 +41,9 @@ class EnumAdapter(TypeAdapter):
|
|
|
41
41
|
constant = constant_class()
|
|
42
42
|
setattr(base_class, constant_field.attribute, constant)
|
|
43
43
|
|
|
44
|
+
# Add the Kind type alias.
|
|
45
|
+
setattr(base_class, "Kind", str)
|
|
46
|
+
|
|
44
47
|
def finalize(
|
|
45
48
|
self,
|
|
46
49
|
resolve_type_fn: Callable[[_spec.Type], TypeAdapter],
|
soia/_impl/service.py
CHANGED
|
@@ -5,6 +5,7 @@ from dataclasses import dataclass
|
|
|
5
5
|
from typing import Any, Generic, Literal, TypeVar, Union, cast
|
|
6
6
|
|
|
7
7
|
from soia._impl.method import Method, Request, Response
|
|
8
|
+
from soia._impl.never import Never
|
|
8
9
|
|
|
9
10
|
RequestHeaders = TypeVar("RequestHeaders")
|
|
10
11
|
|
|
@@ -90,42 +91,84 @@ class _HandleRequestFlow(Generic[Request, Response, RequestHeaders, ResponseHead
|
|
|
90
91
|
tuple[Any, _MethodImpl[Request, Response, RequestHeaders, ResponseHeaders]],
|
|
91
92
|
RawServiceResponse,
|
|
92
93
|
]:
|
|
93
|
-
if self.req_body
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
)
|
|
94
|
+
if self.req_body in ["", "list"]:
|
|
95
|
+
return self._handle_list()
|
|
96
|
+
|
|
97
|
+
# Method invokation
|
|
98
|
+
method_name: str
|
|
99
|
+
method_number: int | None
|
|
100
|
+
format: str
|
|
101
|
+
request_data: tuple[Literal["json-code"], str] | tuple[Literal["json"], Any]
|
|
102
|
+
|
|
103
|
+
first_char = self.req_body[0]
|
|
104
|
+
if first_char.isspace() or first_char == "{":
|
|
105
|
+
# A JSON object
|
|
106
|
+
try:
|
|
107
|
+
req_body_json = json.loads(self.req_body)
|
|
108
|
+
except json.JSONDecodeError:
|
|
109
|
+
return RawServiceResponse(
|
|
110
|
+
"bad request: invalid JSON", "bad-request"
|
|
111
|
+
)
|
|
112
|
+
method = req_body_json.get("method", ())
|
|
113
|
+
if method == ():
|
|
114
|
+
return RawServiceResponse(
|
|
115
|
+
"bad request: missing 'method' field in JSON", "bad-request"
|
|
116
|
+
)
|
|
117
|
+
if isinstance(method, str):
|
|
118
|
+
method_name = method
|
|
119
|
+
method_number = None
|
|
120
|
+
elif isinstance(method, int):
|
|
121
|
+
method_name = "?"
|
|
122
|
+
method_number = method
|
|
123
|
+
else:
|
|
124
|
+
return RawServiceResponse(
|
|
125
|
+
"bad request: 'method' field must be a string or an integer",
|
|
126
|
+
"bad-request",
|
|
127
|
+
)
|
|
128
|
+
format = "readable"
|
|
129
|
+
data = req_body_json.get("request", ())
|
|
130
|
+
if data == ():
|
|
131
|
+
return RawServiceResponse(
|
|
132
|
+
"bad request: missing 'request' field in JSON", "bad-request"
|
|
133
|
+
)
|
|
134
|
+
request_data = ("json", data)
|
|
135
|
+
else:
|
|
136
|
+
# A colon-separated string
|
|
137
|
+
parts = self.req_body.split(":", 3)
|
|
138
|
+
if len(parts) != 4:
|
|
139
|
+
return RawServiceResponse(
|
|
140
|
+
"bad request: invalid request format", "bad-request"
|
|
141
|
+
)
|
|
142
|
+
method_name = parts[0]
|
|
143
|
+
method_number_str = parts[1]
|
|
144
|
+
format = parts[2]
|
|
145
|
+
request_data = ("json-code", parts[3])
|
|
146
|
+
if method_number_str:
|
|
147
|
+
try:
|
|
148
|
+
method_number = int(method_number_str)
|
|
149
|
+
except Exception:
|
|
150
|
+
return RawServiceResponse(
|
|
151
|
+
"bad request: can't parse method number", "bad-request"
|
|
152
|
+
)
|
|
153
|
+
else:
|
|
154
|
+
method_number = None
|
|
155
|
+
self.format = format
|
|
156
|
+
if method_number is None:
|
|
157
|
+
# Try to get the method number by name
|
|
158
|
+
all_methods = self.number_to_method_impl.values()
|
|
159
|
+
name_matches = [m for m in all_methods if m.method.name == method_name]
|
|
160
|
+
if not name_matches:
|
|
161
|
+
return RawServiceResponse(
|
|
162
|
+
f"bad request: method not found: {method_name}",
|
|
163
|
+
"bad-request",
|
|
164
|
+
)
|
|
165
|
+
elif len(name_matches) != 1:
|
|
166
|
+
return RawServiceResponse(
|
|
167
|
+
f"bad request: method name '{method_name}' is ambiguous; "
|
|
168
|
+
"use method number instead",
|
|
169
|
+
"bad-request",
|
|
170
|
+
)
|
|
171
|
+
method_number = name_matches[0].method.number
|
|
129
172
|
method_impl = self.number_to_method_impl.get(method_number)
|
|
130
173
|
if not method_impl:
|
|
131
174
|
return RawServiceResponse(
|
|
@@ -133,15 +176,41 @@ class _HandleRequestFlow(Generic[Request, Response, RequestHeaders, ResponseHead
|
|
|
133
176
|
"bad-request",
|
|
134
177
|
)
|
|
135
178
|
try:
|
|
136
|
-
req: Any
|
|
137
|
-
|
|
138
|
-
|
|
179
|
+
req: Any
|
|
180
|
+
request_serializer = method_impl.method.request_serializer
|
|
181
|
+
if request_data[0] == "json-code":
|
|
182
|
+
req = request_serializer.from_json_code(request_data[1])
|
|
183
|
+
elif request_data[0] == "json":
|
|
184
|
+
req = request_serializer.from_json(request_data[1])
|
|
185
|
+
else:
|
|
186
|
+
_: Never = request_data[0]
|
|
187
|
+
del _
|
|
139
188
|
except Exception as e:
|
|
140
189
|
return RawServiceResponse(
|
|
141
190
|
f"bad request: can't parse JSON: {e}", "bad-request"
|
|
142
191
|
)
|
|
143
192
|
return (req, method_impl)
|
|
144
193
|
|
|
194
|
+
def _handle_list(self) -> RawServiceResponse:
|
|
195
|
+
def method_to_json(method: Method) -> Any:
|
|
196
|
+
return {
|
|
197
|
+
"method": method.name,
|
|
198
|
+
"number": method.number,
|
|
199
|
+
"request": method.request_serializer.type_descriptor.as_json(),
|
|
200
|
+
"response": method.response_serializer.type_descriptor.as_json(),
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
json_code = json.dumps(
|
|
204
|
+
{
|
|
205
|
+
"methods": [
|
|
206
|
+
method_to_json(method_impl.method)
|
|
207
|
+
for method_impl in self.number_to_method_impl.values()
|
|
208
|
+
]
|
|
209
|
+
},
|
|
210
|
+
indent=2,
|
|
211
|
+
)
|
|
212
|
+
return RawServiceResponse(json_code, "ok-json")
|
|
213
|
+
|
|
145
214
|
def _response_to_json(
|
|
146
215
|
self,
|
|
147
216
|
res: Response,
|
soia/_impl/service_client.py
CHANGED
|
@@ -4,7 +4,7 @@ soia/_spec.py,sha256=Y5EHHQa6qNeJc29aaqGrFPnPFXxlL7TED9_AXUGBjf0,3663
|
|
|
4
4
|
soia/reflection.py,sha256=U5knJGmawARCdcEhNxek4dvx48WLPETLqIqKBPWwT4Q,8771
|
|
5
5
|
soia/_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
soia/_impl/arrays.py,sha256=C3j3RZdSvqmogbGAi3EprLkUYMFfO-IJhoCOte5blAw,5477
|
|
7
|
-
soia/_impl/enums.py,sha256=
|
|
7
|
+
soia/_impl/enums.py,sha256=jlg2YYGgMg6BMmSy0v0MBgZmZYzLvVS0j68TxOCiSm8,17039
|
|
8
8
|
soia/_impl/function_maker.py,sha256=MvCDv1WwzKGJzZbNCnJ_8-MP3m1xTIabumXA-9Ydd9M,5639
|
|
9
9
|
soia/_impl/keyed_items.py,sha256=EoPrdeLJ8i7zCH-oW-7qOcyadyrzykB6lkrf3xRVmyk,337
|
|
10
10
|
soia/_impl/method.py,sha256=C6ygh-Li4zADxFR_gfeBTuPUzLjZ1XHCp0ZI4-uiRYs,455
|
|
@@ -14,13 +14,13 @@ soia/_impl/primitives.py,sha256=Xk26Fv4oQG2oXd3tS_2sAnJYQdXYX9nva09713AcJvs,8940
|
|
|
14
14
|
soia/_impl/repr.py,sha256=7WX0bEAVENTjlyZIcbT8TcJylS7IRIyafGCmqaIMxFM,1413
|
|
15
15
|
soia/_impl/serializer.py,sha256=28IwkjtUnLpbnPQfVNfJXkApCK4JhXHwLkC5MVhF8xo,3529
|
|
16
16
|
soia/_impl/serializers.py,sha256=IL9jHHMo11pgrL1-crarOEElvTyV5YM6FTcgumjW6IU,2564
|
|
17
|
-
soia/_impl/service.py,sha256=
|
|
18
|
-
soia/_impl/service_client.py,sha256=
|
|
17
|
+
soia/_impl/service.py,sha256=3dpcH4XEBTEShyjzxMA_zDGg9_amTFF5A49U6hivAdQ,14792
|
|
18
|
+
soia/_impl/service_client.py,sha256=0WgiN6Stg548FAdZQMuezZoooe4MYw2frEQ5KUE7xag,5311
|
|
19
19
|
soia/_impl/structs.py,sha256=KrqucOqSxXda4-3gKyCmx_Oj4osTFBLk9ORyRkV_7dk,26785
|
|
20
20
|
soia/_impl/timestamp.py,sha256=lXBNH8mPmzflkNjSKZSBl2XS-ot9N8N92B_zGO2SMtU,4078
|
|
21
21
|
soia/_impl/type_adapter.py,sha256=RyIyh4Fnt9rMy0HRzC-a2v2JAdZsV9FBzoGEUVygVRE,2101
|
|
22
|
-
soia_client-1.0.
|
|
23
|
-
soia_client-1.0.
|
|
24
|
-
soia_client-1.0.
|
|
25
|
-
soia_client-1.0.
|
|
26
|
-
soia_client-1.0.
|
|
22
|
+
soia_client-1.0.29.dist-info/licenses/LICENSE,sha256=SaAftKkX6hfSOiPdENQPS70tifH3PDHgazq8eK2Pwfw,1064
|
|
23
|
+
soia_client-1.0.29.dist-info/METADATA,sha256=Ku2iQYq_A0BOH0B4uW5H_8DoZdIXSbSwIUX3jTnP6iA,2122
|
|
24
|
+
soia_client-1.0.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
25
|
+
soia_client-1.0.29.dist-info/top_level.txt,sha256=lsYG9JrvauFe1oIV5zvnwsS9hsx3ztwfK_937op9mxc,5
|
|
26
|
+
soia_client-1.0.29.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|