soia-client 1.0.16__tar.gz → 1.0.17__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.
Files changed (33) hide show
  1. {soia_client-1.0.16 → soia_client-1.0.17}/PKG-INFO +1 -1
  2. {soia_client-1.0.16 → soia_client-1.0.17}/pyproject.toml +1 -1
  3. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/service.py +28 -0
  4. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/service_client.py +16 -5
  5. {soia_client-1.0.16 → soia_client-1.0.17}/soia_client.egg-info/PKG-INFO +1 -1
  6. {soia_client-1.0.16 → soia_client-1.0.17}/LICENSE +0 -0
  7. {soia_client-1.0.16 → soia_client-1.0.17}/README +0 -0
  8. {soia_client-1.0.16 → soia_client-1.0.17}/setup.cfg +0 -0
  9. {soia_client-1.0.16 → soia_client-1.0.17}/soia/__init__.py +0 -0
  10. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/__init__.py +0 -0
  11. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/arrays.py +0 -0
  12. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/enums.py +0 -0
  13. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/function_maker.py +0 -0
  14. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/keyed_items.py +0 -0
  15. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/method.py +0 -0
  16. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/never.py +0 -0
  17. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/optionals.py +0 -0
  18. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/primitives.py +0 -0
  19. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/repr.py +0 -0
  20. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/serializer.py +0 -0
  21. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/serializers.py +0 -0
  22. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/structs.py +0 -0
  23. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/timestamp.py +0 -0
  24. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_impl/type_adapter.py +0 -0
  25. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_module_initializer.py +0 -0
  26. {soia_client-1.0.16 → soia_client-1.0.17}/soia/_spec.py +0 -0
  27. {soia_client-1.0.16 → soia_client-1.0.17}/soia/reflection.py +0 -0
  28. {soia_client-1.0.16 → soia_client-1.0.17}/soia_client.egg-info/SOURCES.txt +0 -0
  29. {soia_client-1.0.16 → soia_client-1.0.17}/soia_client.egg-info/dependency_links.txt +0 -0
  30. {soia_client-1.0.16 → soia_client-1.0.17}/soia_client.egg-info/top_level.txt +0 -0
  31. {soia_client-1.0.16 → soia_client-1.0.17}/tests/test_module_initializer.py +0 -0
  32. {soia_client-1.0.16 → soia_client-1.0.17}/tests/test_serializers.py +0 -0
  33. {soia_client-1.0.16 → soia_client-1.0.17}/tests/test_timestamp.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: soia-client
3
- Version: 1.0.16
3
+ Version: 1.0.17
4
4
  Author-email: Tyler Fibonacci <gepheum@gmail.com>
5
5
  License: MIT License
6
6
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "soia-client"
7
- version = "1.0.16"
7
+ version = "1.0.17"
8
8
  description = ""
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Tyler Fibonacci", email = "gepheum@gmail.com" }]
@@ -14,6 +14,34 @@ ResponseHeaders: TypeAlias = dict[str, str]
14
14
 
15
15
 
16
16
  class Service:
17
+ """Wraps around the implementation of a soia service on the server side.
18
+
19
+ Usage: call '.add_method()' to register method implementations, then call
20
+ '.handle_request()' from the function called by your web framework when an
21
+ HTTP request is sent to your service's URL.
22
+
23
+ Example with Flask:
24
+
25
+ from flask import Response, request
26
+
27
+ soia_service = soia.Service()
28
+ soia_service.add_method(...)
29
+ soia_service.add_method(...)
30
+
31
+ @app.route("/myapi", methods=["GET", "POST"])
32
+ def myapi():
33
+ if request.method == "POST":
34
+ req_body = request.get_data(as_text=True)
35
+ else:
36
+ req_body = urllib.parse.unquote(request.query_string.decode("utf-8"))
37
+ raw_response = soia_service.handle_request(req_body, request.headers, {})
38
+ return Response(
39
+ raw_response.data,
40
+ status=raw_response.status_code,
41
+ content_type=raw_response.content_type,
42
+ )
43
+ """
44
+
17
45
  _number_to_method_impl: dict[int, "_MethodImpl"]
18
46
 
19
47
  def __init__(self):
@@ -1,5 +1,5 @@
1
1
  import http.client
2
- from typing import Final, Mapping
2
+ from typing import Any, Final, Mapping
3
3
  from urllib.parse import urlparse
4
4
 
5
5
  from soia._impl.method import Method, Request, Response
@@ -10,8 +10,8 @@ class ServiceClient:
10
10
  _host: Final[str] # May include the port
11
11
  _path: Final[str]
12
12
 
13
- def __init__(self, service_url: str):
14
- parsed_url = urlparse(service_url)
13
+ def __init__(self, url: str):
14
+ parsed_url = urlparse(url)
15
15
  if parsed_url.query:
16
16
  raise ValueError("Service URL must not contain a query string")
17
17
  scheme = parsed_url.scheme
@@ -26,7 +26,12 @@ class ServiceClient:
26
26
  method: Method[Request, Response],
27
27
  request: Request,
28
28
  headers: Mapping[str, str] = {},
29
+ *,
30
+ res_headers: list[tuple[str, str]] | None = None,
31
+ timeout_secs: float | None = None,
29
32
  ) -> Response:
33
+ """Invokes the given method on the remote server through an RPC."""
34
+
30
35
  request_json = method.request_serializer.to_json_code(request)
31
36
  body = ":".join(
32
37
  [
@@ -41,10 +46,13 @@ class ServiceClient:
41
46
  "Content-Type": "text/plain; charset=utf-8",
42
47
  "Content-Length": str(len(body)),
43
48
  }
49
+ connection_options: dict[str, Any] = {}
50
+ if timeout_secs is not None:
51
+ connection_options["timeout"] = timeout_secs
44
52
  if self._scheme == "https":
45
- conn = http.client.HTTPSConnection(self._host)
53
+ conn = http.client.HTTPSConnection(self._host, **connection_options)
46
54
  else:
47
- conn = http.client.HTTPConnection(self._host)
55
+ conn = http.client.HTTPConnection(self._host, **connection_options)
48
56
  try:
49
57
  conn.request(
50
58
  "POST",
@@ -53,6 +61,9 @@ class ServiceClient:
53
61
  headers=headers,
54
62
  )
55
63
  response = conn.getresponse()
64
+ if res_headers is not None:
65
+ res_headers.clear()
66
+ res_headers.extend(response.getheaders())
56
67
  status_code = response.status
57
68
  content_type = response.getheader("Content-Type")
58
69
  response_data = response.read().decode("utf-8", errors="ignore")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: soia-client
3
- Version: 1.0.16
3
+ Version: 1.0.17
4
4
  Author-email: Tyler Fibonacci <gepheum@gmail.com>
5
5
  License: MIT License
6
6
 
File without changes
File without changes
File without changes
File without changes