soia-client 1.0.19__py3-none-any.whl → 1.0.20__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.
- soia/_impl/service.py +10 -11
- {soia_client-1.0.19.dist-info → soia_client-1.0.20.dist-info}/METADATA +16 -1
- {soia_client-1.0.19.dist-info → soia_client-1.0.20.dist-info}/RECORD +6 -6
- {soia_client-1.0.19.dist-info → soia_client-1.0.20.dist-info}/WHEEL +1 -1
- {soia_client-1.0.19.dist-info → soia_client-1.0.20.dist-info}/licenses/LICENSE +0 -0
- {soia_client-1.0.19.dist-info → soia_client-1.0.20.dist-info}/top_level.txt +0 -0
soia/_impl/service.py
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
import inspect
|
2
2
|
import json
|
3
|
-
from collections.abc import Mapping
|
4
3
|
from dataclasses import dataclass
|
5
|
-
from typing import Any, Callable, Generic, Literal,
|
4
|
+
from typing import Any, Callable, Generic, Literal, TypeVar, Union, cast
|
6
5
|
|
7
6
|
from soia._impl.method import Method, Request, Response
|
8
7
|
|
9
|
-
RequestHeaders
|
8
|
+
RequestHeaders = TypeVar("RequestHeaders")
|
10
9
|
|
10
|
+
ResponseHeaders = TypeVar("ResponseHeaders")
|
11
11
|
|
12
|
-
ResponseHeaders: TypeAlias = dict[str, str]
|
13
12
|
|
14
|
-
|
15
|
-
class Service:
|
13
|
+
class Service(Generic[RequestHeaders, ResponseHeaders]):
|
16
14
|
"""Wraps around the implementation of a soia service on the server side.
|
17
15
|
|
18
16
|
Usage: call '.add_method()' to register method implementations, then call
|
@@ -22,8 +20,10 @@ class Service:
|
|
22
20
|
Example with Flask:
|
23
21
|
|
24
22
|
from flask import Response, request
|
23
|
+
from werkzeug.datastructures import Headers
|
24
|
+
|
25
25
|
|
26
|
-
s = soia.Service()
|
26
|
+
s = soia.Service[Headers, Headers]()
|
27
27
|
s.add_method(...)
|
28
28
|
s.add_method(...)
|
29
29
|
|
@@ -34,8 +34,8 @@ class Service:
|
|
34
34
|
else:
|
35
35
|
query_string = request.query_string.decode("utf-8")
|
36
36
|
req_body = urllib.parse.unquote(query_string)
|
37
|
-
req_headers =
|
38
|
-
res_headers
|
37
|
+
req_headers = request.headers
|
38
|
+
res_headers = Headers()
|
39
39
|
raw_response = s.handle_request(req_body, req_headers, res_headers)
|
40
40
|
return Response(
|
41
41
|
raw_response.data,
|
@@ -182,7 +182,6 @@ class Service:
|
|
182
182
|
f"bad request: can't parse JSON: {e}", "bad-request"
|
183
183
|
)
|
184
184
|
|
185
|
-
res_headers.clear()
|
186
185
|
try:
|
187
186
|
res: Any = method_impl.impl(req, req_headers, res_headers)
|
188
187
|
except Exception as e:
|
@@ -201,6 +200,6 @@ class Service:
|
|
201
200
|
|
202
201
|
|
203
202
|
@dataclass(frozen=True)
|
204
|
-
class _MethodImpl(Generic[Request, Response]):
|
203
|
+
class _MethodImpl(Generic[Request, Response, RequestHeaders, ResponseHeaders]):
|
205
204
|
method: Method[Request, Response]
|
206
205
|
impl: Callable[[Request, RequestHeaders, ResponseHeaders], Response]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: soia-client
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.20
|
4
4
|
Author-email: Tyler Fibonacci <gepheum@gmail.com>
|
5
5
|
License: MIT License
|
6
6
|
|
@@ -32,3 +32,18 @@ Requires-Python: >=3.10
|
|
32
32
|
Description-Content-Type: text/markdown
|
33
33
|
License-File: LICENSE
|
34
34
|
Dynamic: license-file
|
35
|
+
|
36
|
+
# Soia Python Client
|
37
|
+
|
38
|
+
Library imported from Python code generated from soia files.
|
39
|
+
|
40
|
+
Install with:
|
41
|
+
```shell
|
42
|
+
pip install soia-client
|
43
|
+
```
|
44
|
+
|
45
|
+
See:
|
46
|
+
|
47
|
+
* [soia](https://github.com/gepheum/soia): home of the soia compiler
|
48
|
+
* [soia-python-gen](https://github.com/gepheum/soia-python-gen): soia to Python code generator
|
49
|
+
* [soia-python-example](https://github.com/gepheum/soia-python-example): example showing how to use soia's Python code generator in a project
|
@@ -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=
|
17
|
+
soia/_impl/service.py,sha256=GH0vujMDaqRpX8bNQATUPdzJ1V_fjt4eHGCBAjLjlaY,7229
|
18
18
|
soia/_impl/service_client.py,sha256=qDntwRyXfLsmXl4ELfOkh-fgv553nrGy72K0JghLM80,2734
|
19
19
|
soia/_impl/structs.py,sha256=YTc3Ykj2TxPquar2XsP2DhFfkfIoELXOveyd8yTqN90,26545
|
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.20.dist-info/licenses/LICENSE,sha256=SaAftKkX6hfSOiPdENQPS70tifH3PDHgazq8eK2Pwfw,1064
|
23
|
+
soia_client-1.0.20.dist-info/METADATA,sha256=7HocgiYValsPhLrZnucq5U1m-AIF3aRBQn5RZjXLl0o,2122
|
24
|
+
soia_client-1.0.20.dist-info/WHEEL,sha256=GHB6lJx2juba1wDgXDNlMTyM13ckjBMKf-OnwgKOCtA,91
|
25
|
+
soia_client-1.0.20.dist-info/top_level.txt,sha256=lsYG9JrvauFe1oIV5zvnwsS9hsx3ztwfK_937op9mxc,5
|
26
|
+
soia_client-1.0.20.dist-info/RECORD,,
|
File without changes
|
File without changes
|