apexdevkit 1.18.11__tar.gz → 1.19.1__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.
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/PKG-INFO +1 -1
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/builder.py +1 -1
- apexdevkit-1.19.1/apexdevkit/http/httpx/__init__.py +6 -0
- apexdevkit-1.18.11/apexdevkit/http/httpx.py → apexdevkit-1.19.1/apexdevkit/http/httpx/client.py +56 -6
- apexdevkit-1.19.1/apexdevkit/http/httpx/hooks.py +72 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/pyproject.toml +1 -1
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/LICENSE +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/README.md +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/environment.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/error.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/name.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/request.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/resource.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/fluent.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/id.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/key_fn.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/query/__init__.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/query/generator.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/query/query.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/decorator.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/mongo.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/mssql.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/sql.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/repository/sqlite.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/server.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/synchronization.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/testing/fake.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/testing/rest.py +0 -0
- {apexdevkit-1.18.11 → apexdevkit-1.19.1}/apexdevkit/value.py +0 -0
apexdevkit-1.18.11/apexdevkit/http/httpx.py → apexdevkit-1.19.1/apexdevkit/http/httpx/client.py
RENAMED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass, field
|
|
4
|
-
from typing import Any, Iterator, Mapping
|
|
4
|
+
from typing import Any, Callable, Iterator, Mapping
|
|
5
5
|
|
|
6
6
|
import httpx
|
|
7
|
-
from httpx import Client
|
|
8
7
|
|
|
9
8
|
from apexdevkit.http.fluent import HttpMethod, HttpResponse
|
|
9
|
+
from apexdevkit.http.httpx.hooks import (
|
|
10
|
+
AfterResponseHook,
|
|
11
|
+
BeforeRequestHook,
|
|
12
|
+
HttpxHandler,
|
|
13
|
+
)
|
|
10
14
|
from apexdevkit.http.json import JsonDict
|
|
11
15
|
from apexdevkit.http.url import HttpUrl
|
|
12
16
|
|
|
17
|
+
_RequestHandler = HttpxHandler[httpx.Request]
|
|
18
|
+
_ResponseHandler = HttpxHandler[httpx.Response]
|
|
19
|
+
|
|
13
20
|
|
|
14
21
|
def default_config() -> HttpxConfig:
|
|
15
22
|
return HttpxConfig()
|
|
@@ -21,10 +28,6 @@ class Httpx:
|
|
|
21
28
|
|
|
22
29
|
config: HttpxConfig = field(default_factory=default_config)
|
|
23
30
|
|
|
24
|
-
@classmethod
|
|
25
|
-
def create_for(cls, url: str) -> Self:
|
|
26
|
-
return cls(Client(base_url=url))
|
|
27
|
-
|
|
28
31
|
def with_endpoint(self, value: str) -> Httpx:
|
|
29
32
|
return Httpx(self.client, self.config.with_endpoint(value))
|
|
30
33
|
|
|
@@ -45,6 +48,53 @@ class Httpx:
|
|
|
45
48
|
)
|
|
46
49
|
)
|
|
47
50
|
|
|
51
|
+
@dataclass
|
|
52
|
+
class Builder:
|
|
53
|
+
config: HttpxConfig = field(default_factory=default_config)
|
|
54
|
+
|
|
55
|
+
request_handlers: list[_RequestHandler] = field(default_factory=list)
|
|
56
|
+
response_handlers: list[_ResponseHandler] = field(default_factory=list)
|
|
57
|
+
|
|
58
|
+
url: str = field(init=False)
|
|
59
|
+
|
|
60
|
+
def with_url(self, value: str) -> Httpx.Builder:
|
|
61
|
+
self.url = value
|
|
62
|
+
|
|
63
|
+
return self
|
|
64
|
+
|
|
65
|
+
def and_config(self, value: HttpxConfig) -> Httpx.Builder:
|
|
66
|
+
self.config = value
|
|
67
|
+
|
|
68
|
+
return self
|
|
69
|
+
|
|
70
|
+
def before_request(self, handler: _RequestHandler) -> Httpx.Builder:
|
|
71
|
+
self.request_handlers.append(handler)
|
|
72
|
+
|
|
73
|
+
return self
|
|
74
|
+
|
|
75
|
+
def after_response(self, handler: _ResponseHandler) -> Httpx.Builder:
|
|
76
|
+
self.response_handlers.append(handler)
|
|
77
|
+
|
|
78
|
+
return self
|
|
79
|
+
|
|
80
|
+
def build(self) -> Httpx:
|
|
81
|
+
return Httpx(self._build_client(), self.config)
|
|
82
|
+
|
|
83
|
+
def _build_client(self) -> httpx.Client:
|
|
84
|
+
return httpx.Client(
|
|
85
|
+
base_url=self.url,
|
|
86
|
+
event_hooks={
|
|
87
|
+
"request": self._build_before_request_hooks(),
|
|
88
|
+
"response": self._build_after_response_hooks(),
|
|
89
|
+
},
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
def _build_before_request_hooks(self) -> list[Callable[..., Any]]:
|
|
93
|
+
return [BeforeRequestHook(handler) for handler in self.request_handlers]
|
|
94
|
+
|
|
95
|
+
def _build_after_response_hooks(self) -> list[Callable[..., Any]]:
|
|
96
|
+
return [AfterResponseHook(handler) for handler in self.response_handlers]
|
|
97
|
+
|
|
48
98
|
|
|
49
99
|
@dataclass(frozen=True)
|
|
50
100
|
class _HttpxResponse:
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Generic, Protocol, TypeVar
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
ContextT = TypeVar("ContextT", contravariant=True)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class HttpxHandler(Protocol[ContextT]):
|
|
12
|
+
def on_get(self, context: ContextT) -> None:
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
def on_post(self, context: ContextT) -> None:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
def on_patch(self, context: ContextT) -> None:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
def on_delete(self, context: ContextT) -> None:
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class DefaultHandler(Generic[ContextT]):
|
|
26
|
+
def on_get(self, context: ContextT) -> None:
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
def on_post(self, context: ContextT) -> None:
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
def on_patch(self, context: ContextT) -> None:
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
def on_delete(self, context: ContextT) -> None:
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class BeforeRequestHook:
|
|
41
|
+
handler: HttpxHandler[httpx.Request]
|
|
42
|
+
|
|
43
|
+
def __call__(self, request: httpx.Request) -> None:
|
|
44
|
+
match request.method.upper():
|
|
45
|
+
case "GET":
|
|
46
|
+
self.handler.on_get(request)
|
|
47
|
+
case "POST":
|
|
48
|
+
self.handler.on_post(request)
|
|
49
|
+
case "PATCH":
|
|
50
|
+
self.handler.on_patch(request)
|
|
51
|
+
case "DELETE":
|
|
52
|
+
self.handler.on_delete(request)
|
|
53
|
+
case _:
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class AfterResponseHook:
|
|
59
|
+
handler: HttpxHandler[httpx.Response]
|
|
60
|
+
|
|
61
|
+
def __call__(self, response: httpx.Response) -> None:
|
|
62
|
+
match response.request.method.upper():
|
|
63
|
+
case "GET":
|
|
64
|
+
self.handler.on_get(response)
|
|
65
|
+
case "POST":
|
|
66
|
+
self.handler.on_post(response)
|
|
67
|
+
case "PATCH":
|
|
68
|
+
self.handler.on_patch(response)
|
|
69
|
+
case "DELETE":
|
|
70
|
+
self.handler.on_delete(response)
|
|
71
|
+
case _:
|
|
72
|
+
pass
|
|
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
|
|
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
|