soia-client 1.0.22__py3-none-any.whl → 1.0.24__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_client.py +86 -1
- soia/_impl/structs.py +1 -1
- {soia_client-1.0.22.dist-info → soia_client-1.0.24.dist-info}/METADATA +1 -1
- {soia_client-1.0.22.dist-info → soia_client-1.0.24.dist-info}/RECORD +7 -7
- {soia_client-1.0.22.dist-info → soia_client-1.0.24.dist-info}/WHEEL +1 -1
- {soia_client-1.0.22.dist-info → soia_client-1.0.24.dist-info}/licenses/LICENSE +0 -0
- {soia_client-1.0.22.dist-info → soia_client-1.0.24.dist-info}/top_level.txt +0 -0
soia/_impl/service_client.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import http.client
|
2
2
|
import re
|
3
|
-
from typing import Any, Final, Mapping
|
3
|
+
from typing import Any, Final, Mapping, Protocol
|
4
4
|
from urllib.parse import urlparse
|
5
5
|
|
6
6
|
from soia._impl.method import Method, Request, Response
|
@@ -77,3 +77,88 @@ class ServiceClient:
|
|
77
77
|
if re.match(r"text/plain\b", content_type):
|
78
78
|
message = f"{message}: {response_data}"
|
79
79
|
raise RuntimeError(message)
|
80
|
+
|
81
|
+
async def invoke_remote_async(
|
82
|
+
self,
|
83
|
+
aiohttp_client_session: "_AiohttpClientSession",
|
84
|
+
method: Method[Request, Response],
|
85
|
+
request: Request,
|
86
|
+
headers: Mapping[str, str] = {},
|
87
|
+
*,
|
88
|
+
res_headers: list[tuple[str, str]] | None = None,
|
89
|
+
) -> Response:
|
90
|
+
"""
|
91
|
+
Asynchronously invokes the given method on the remote server through an RPC.
|
92
|
+
|
93
|
+
Usage:
|
94
|
+
import aiohttp
|
95
|
+
|
96
|
+
async with aiohttp.ClientSession() as session:
|
97
|
+
response = await service_client.invoke_remote_async(
|
98
|
+
session,
|
99
|
+
method,
|
100
|
+
request,
|
101
|
+
headers,
|
102
|
+
)
|
103
|
+
|
104
|
+
With timeout:
|
105
|
+
timeout = aiohttp.ClientTimeout(total=30)
|
106
|
+
async with aiohttp.ClientSession(timeout=timeout) as session:
|
107
|
+
response = await service_client.invoke_remote_async(
|
108
|
+
session,
|
109
|
+
method,
|
110
|
+
request,
|
111
|
+
headers,
|
112
|
+
)
|
113
|
+
"""
|
114
|
+
|
115
|
+
request_json = method.request_serializer.to_json_code(request)
|
116
|
+
body = ":".join(
|
117
|
+
[
|
118
|
+
method.name,
|
119
|
+
str(method.number),
|
120
|
+
"",
|
121
|
+
request_json,
|
122
|
+
]
|
123
|
+
)
|
124
|
+
|
125
|
+
request_headers = {
|
126
|
+
**headers,
|
127
|
+
"Content-Type": "text/plain; charset=utf-8",
|
128
|
+
"Content-Length": str(len(body)),
|
129
|
+
}
|
130
|
+
|
131
|
+
# Build the URL
|
132
|
+
url = f"{self._scheme}://{self._host}{self._path}"
|
133
|
+
|
134
|
+
async with aiohttp_client_session.post(
|
135
|
+
url,
|
136
|
+
data=body,
|
137
|
+
headers=request_headers,
|
138
|
+
) as response:
|
139
|
+
if res_headers is not None:
|
140
|
+
res_headers.clear()
|
141
|
+
res_headers.extend(response.headers.items())
|
142
|
+
|
143
|
+
status_code = response.status
|
144
|
+
content_type = response.headers.get("Content-Type", "")
|
145
|
+
response_data = await response.text(encoding="utf-8", errors="ignore")
|
146
|
+
|
147
|
+
if status_code in range(200, 300):
|
148
|
+
return method.response_serializer.from_json_code(response_data)
|
149
|
+
else:
|
150
|
+
message = f"HTTP status {status_code}"
|
151
|
+
if re.match(r"text/plain\b", content_type):
|
152
|
+
message = f"{message}: {response_data}"
|
153
|
+
raise RuntimeError(message)
|
154
|
+
|
155
|
+
|
156
|
+
class _AiohttpClientSession(Protocol):
|
157
|
+
def post(
|
158
|
+
self,
|
159
|
+
url: str,
|
160
|
+
*,
|
161
|
+
data: str,
|
162
|
+
headers: Mapping[str, str],
|
163
|
+
) -> Any:
|
164
|
+
...
|
soia/_impl/structs.py
CHANGED
@@ -676,7 +676,7 @@ def _make_from_json_fn(
|
|
676
676
|
name = field.field.name
|
677
677
|
lvalue = f"ret.{field.field.attribute}"
|
678
678
|
builder.append_ln(f' if "{name}" in json:')
|
679
|
-
builder.append_ln(f" array_len = {field.field.number}")
|
679
|
+
builder.append_ln(f" array_len = {field.field.number + 1}")
|
680
680
|
builder.append_ln(
|
681
681
|
f" {lvalue} = ",
|
682
682
|
field.type.from_json_expr(f'json["{name}"]'),
|
@@ -15,12 +15,12 @@ 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
17
|
soia/_impl/service.py,sha256=PsV286BYMoJpXIjeBc__MHHakcqof0Pbb3B_Zha1PZI,11928
|
18
|
-
soia/_impl/service_client.py,sha256=
|
19
|
-
soia/_impl/structs.py,sha256=
|
18
|
+
soia/_impl/service_client.py,sha256=NtaJmkk7DShLKZm_QOzQtboXqmfKvdLRym1EZ-EbJQI,5319
|
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.24.dist-info/licenses/LICENSE,sha256=SaAftKkX6hfSOiPdENQPS70tifH3PDHgazq8eK2Pwfw,1064
|
23
|
+
soia_client-1.0.24.dist-info/METADATA,sha256=3-LeEFfA48rzfg5WOWINfM2baIXo3Saq7SzaFAOwZmk,2122
|
24
|
+
soia_client-1.0.24.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
25
|
+
soia_client-1.0.24.dist-info/top_level.txt,sha256=lsYG9JrvauFe1oIV5zvnwsS9hsx3ztwfK_937op9mxc,5
|
26
|
+
soia_client-1.0.24.dist-info/RECORD,,
|
File without changes
|
File without changes
|