soia-client 1.0.22__tar.gz → 1.0.23__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.
- {soia_client-1.0.22 → soia_client-1.0.23}/PKG-INFO +1 -1
- {soia_client-1.0.22 → soia_client-1.0.23}/pyproject.toml +1 -1
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/service_client.py +87 -1
- {soia_client-1.0.22 → soia_client-1.0.23}/soia_client.egg-info/PKG-INFO +1 -1
- {soia_client-1.0.22 → soia_client-1.0.23}/LICENSE +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/README.md +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/setup.cfg +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/__init__.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/__init__.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/arrays.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/enums.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/function_maker.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/keyed_items.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/method.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/never.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/optionals.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/primitives.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/repr.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/serializer.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/serializers.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/service.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/structs.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/timestamp.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_impl/type_adapter.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_module_initializer.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/_spec.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia/reflection.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia_client.egg-info/SOURCES.txt +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia_client.egg-info/dependency_links.txt +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/soia_client.egg-info/top_level.txt +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/tests/test_module_initializer.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/tests/test_serializers.py +0 -0
- {soia_client-1.0.22 → soia_client-1.0.23}/tests/test_timestamp.py +0 -0
@@ -1,6 +1,7 @@
|
|
1
1
|
import http.client
|
2
2
|
import re
|
3
|
-
|
3
|
+
import typing
|
4
|
+
from typing import Any, Final, Mapping, Protocol
|
4
5
|
from urllib.parse import urlparse
|
5
6
|
|
6
7
|
from soia._impl.method import Method, Request, Response
|
@@ -77,3 +78,88 @@ class ServiceClient:
|
|
77
78
|
if re.match(r"text/plain\b", content_type):
|
78
79
|
message = f"{message}: {response_data}"
|
79
80
|
raise RuntimeError(message)
|
81
|
+
|
82
|
+
async def invoke_remote_async(
|
83
|
+
self,
|
84
|
+
aiohttp_client_session: "_AiohttpClientSession",
|
85
|
+
method: Method[Request, Response],
|
86
|
+
request: Request,
|
87
|
+
headers: Mapping[str, str] = {},
|
88
|
+
*,
|
89
|
+
res_headers: list[tuple[str, str]] | None = None,
|
90
|
+
) -> Response:
|
91
|
+
"""
|
92
|
+
Asynchronously invokes the given method on the remote server through an RPC.
|
93
|
+
|
94
|
+
Usage:
|
95
|
+
import aiohttp
|
96
|
+
|
97
|
+
async with aiohttp.ClientSession() as session:
|
98
|
+
response = await service_client.invoke_remote_async(
|
99
|
+
session,
|
100
|
+
method,
|
101
|
+
request,
|
102
|
+
headers,
|
103
|
+
)
|
104
|
+
|
105
|
+
With timeout:
|
106
|
+
timeout = aiohttp.ClientTimeout(total=30)
|
107
|
+
async with aiohttp.ClientSession(timeout=timeout) as session:
|
108
|
+
response = await service_client.invoke_remote_async(
|
109
|
+
session,
|
110
|
+
method,
|
111
|
+
request,
|
112
|
+
headers,
|
113
|
+
)
|
114
|
+
"""
|
115
|
+
|
116
|
+
request_json = method.request_serializer.to_json_code(request)
|
117
|
+
body = ":".join(
|
118
|
+
[
|
119
|
+
method.name,
|
120
|
+
str(method.number),
|
121
|
+
"",
|
122
|
+
request_json,
|
123
|
+
]
|
124
|
+
)
|
125
|
+
|
126
|
+
request_headers = {
|
127
|
+
**headers,
|
128
|
+
"Content-Type": "text/plain; charset=utf-8",
|
129
|
+
"Content-Length": str(len(body)),
|
130
|
+
}
|
131
|
+
|
132
|
+
# Build the URL
|
133
|
+
url = f"{self._scheme}://{self._host}{self._path}"
|
134
|
+
|
135
|
+
async with aiohttp_client_session.post(
|
136
|
+
url,
|
137
|
+
data=body,
|
138
|
+
headers=request_headers,
|
139
|
+
) as response:
|
140
|
+
if res_headers is not None:
|
141
|
+
res_headers.clear()
|
142
|
+
res_headers.extend(response.headers.items())
|
143
|
+
|
144
|
+
status_code = response.status
|
145
|
+
content_type = response.headers.get("Content-Type", "")
|
146
|
+
response_data = await response.text(encoding="utf-8", errors="ignore")
|
147
|
+
|
148
|
+
if status_code in range(200, 300):
|
149
|
+
return method.response_serializer.from_json_code(response_data)
|
150
|
+
else:
|
151
|
+
message = f"HTTP status {status_code}"
|
152
|
+
if re.match(r"text/plain\b", content_type):
|
153
|
+
message = f"{message}: {response_data}"
|
154
|
+
raise RuntimeError(message)
|
155
|
+
|
156
|
+
|
157
|
+
class _AiohttpClientSession(Protocol):
|
158
|
+
def post(
|
159
|
+
self,
|
160
|
+
url: str,
|
161
|
+
*,
|
162
|
+
data: str,
|
163
|
+
headers: Mapping[str, str],
|
164
|
+
) -> Any:
|
165
|
+
...
|
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
|
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
|