soia-client 1.0.17__tar.gz → 1.0.19__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.17 → soia_client-1.0.19}/PKG-INFO +1 -1
  2. {soia_client-1.0.17 → soia_client-1.0.19}/pyproject.toml +1 -1
  3. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/service.py +16 -12
  4. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/service_client.py +4 -3
  5. {soia_client-1.0.17 → soia_client-1.0.19}/soia_client.egg-info/PKG-INFO +1 -1
  6. {soia_client-1.0.17 → soia_client-1.0.19}/LICENSE +0 -0
  7. {soia_client-1.0.17 → soia_client-1.0.19}/README +0 -0
  8. {soia_client-1.0.17 → soia_client-1.0.19}/setup.cfg +0 -0
  9. {soia_client-1.0.17 → soia_client-1.0.19}/soia/__init__.py +0 -0
  10. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/__init__.py +0 -0
  11. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/arrays.py +0 -0
  12. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/enums.py +0 -0
  13. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/function_maker.py +0 -0
  14. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/keyed_items.py +0 -0
  15. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/method.py +0 -0
  16. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/never.py +0 -0
  17. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/optionals.py +0 -0
  18. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/primitives.py +0 -0
  19. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/repr.py +0 -0
  20. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/serializer.py +0 -0
  21. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/serializers.py +0 -0
  22. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/structs.py +0 -0
  23. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/timestamp.py +0 -0
  24. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_impl/type_adapter.py +0 -0
  25. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_module_initializer.py +0 -0
  26. {soia_client-1.0.17 → soia_client-1.0.19}/soia/_spec.py +0 -0
  27. {soia_client-1.0.17 → soia_client-1.0.19}/soia/reflection.py +0 -0
  28. {soia_client-1.0.17 → soia_client-1.0.19}/soia_client.egg-info/SOURCES.txt +0 -0
  29. {soia_client-1.0.17 → soia_client-1.0.19}/soia_client.egg-info/dependency_links.txt +0 -0
  30. {soia_client-1.0.17 → soia_client-1.0.19}/soia_client.egg-info/top_level.txt +0 -0
  31. {soia_client-1.0.17 → soia_client-1.0.19}/tests/test_module_initializer.py +0 -0
  32. {soia_client-1.0.17 → soia_client-1.0.19}/tests/test_serializers.py +0 -0
  33. {soia_client-1.0.17 → soia_client-1.0.19}/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.17
3
+ Version: 1.0.19
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.17"
7
+ version = "1.0.19"
8
8
  description = ""
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Tyler Fibonacci", email = "gepheum@gmail.com" }]
@@ -1,13 +1,12 @@
1
1
  import inspect
2
2
  import json
3
+ from collections.abc import Mapping
3
4
  from dataclasses import dataclass
4
- from typing import Any, Callable, Generic, Literal, Protocol, TypeAlias, Union, cast
5
+ from typing import Any, Callable, Generic, Literal, TypeAlias, Union, cast
5
6
 
6
7
  from soia._impl.method import Method, Request, Response
7
8
 
8
-
9
- class RequestHeaders(Protocol):
10
- def __getitem__(self, key: str, /) -> str | None: ...
9
+ RequestHeaders: TypeAlias = Mapping[str, str]
11
10
 
12
11
 
13
12
  ResponseHeaders: TypeAlias = dict[str, str]
@@ -18,27 +17,31 @@ class Service:
18
17
 
19
18
  Usage: call '.add_method()' to register method implementations, then call
20
19
  '.handle_request()' from the function called by your web framework when an
21
- HTTP request is sent to your service's URL.
20
+ HTTP request is received at your service's endpoint.
22
21
 
23
22
  Example with Flask:
24
23
 
25
24
  from flask import Response, request
26
25
 
27
- soia_service = soia.Service()
28
- soia_service.add_method(...)
29
- soia_service.add_method(...)
26
+ s = soia.Service()
27
+ s.add_method(...)
28
+ s.add_method(...)
30
29
 
31
30
  @app.route("/myapi", methods=["GET", "POST"])
32
31
  def myapi():
33
32
  if request.method == "POST":
34
33
  req_body = request.get_data(as_text=True)
35
34
  else:
36
- req_body = urllib.parse.unquote(request.query_string.decode("utf-8"))
37
- raw_response = soia_service.handle_request(req_body, request.headers, {})
35
+ query_string = request.query_string.decode("utf-8")
36
+ req_body = urllib.parse.unquote(query_string)
37
+ req_headers = dict(request.headers)
38
+ res_headers: dict[str, str] = {}
39
+ raw_response = s.handle_request(req_body, req_headers, res_headers)
38
40
  return Response(
39
41
  raw_response.data,
40
42
  status=raw_response.status_code,
41
43
  content_type=raw_response.content_type,
44
+ headers=res_headers,
42
45
  )
43
46
  """
44
47
 
@@ -125,7 +128,7 @@ class Service:
125
128
  self,
126
129
  req_body: str,
127
130
  req_headers: RequestHeaders,
128
- res_headers: ResponseHeaders | None,
131
+ res_headers: ResponseHeaders,
129
132
  ) -> RawResponse:
130
133
  if req_body == "list":
131
134
 
@@ -179,8 +182,9 @@ class Service:
179
182
  f"bad request: can't parse JSON: {e}", "bad-request"
180
183
  )
181
184
 
185
+ res_headers.clear()
182
186
  try:
183
- res: Any = method_impl.impl(req, req_headers, res_headers or {})
187
+ res: Any = method_impl.impl(req, req_headers, res_headers)
184
188
  except Exception as e:
185
189
  return self.RawResponse(f"server error: {e}", "server-error")
186
190
 
@@ -1,4 +1,5 @@
1
1
  import http.client
2
+ import re
2
3
  from typing import Any, Final, Mapping
3
4
  from urllib.parse import urlparse
4
5
 
@@ -65,14 +66,14 @@ class ServiceClient:
65
66
  res_headers.clear()
66
67
  res_headers.extend(response.getheaders())
67
68
  status_code = response.status
68
- content_type = response.getheader("Content-Type")
69
+ content_type = response.getheader("Content-Type") or ""
69
70
  response_data = response.read().decode("utf-8", errors="ignore")
70
71
  finally:
71
72
  conn.close()
72
73
  if status_code in range(200, 300):
73
74
  return method.response_serializer.from_json_code(response_data)
74
75
  else:
75
- message = f"HTTP response status {status_code}"
76
- if content_type == "text/plain":
76
+ message = f"HTTP status {status_code}"
77
+ if re.match(r"text/plain\b", content_type):
77
78
  message = f"{message}: {response_data}"
78
79
  raise RuntimeError(message)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: soia-client
3
- Version: 1.0.17
3
+ Version: 1.0.19
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