finalsa-common-http-client 0.0.2__tar.gz → 0.0.3__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.
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/PKG-INFO +4 -3
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/finalsa/http/async_client/base.py +29 -14
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/finalsa/http/sync_client/base.py +25 -14
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/pyproject.toml +4 -3
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/.gitignore +0 -0
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/LICENSE.md +0 -0
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/README.md +0 -0
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/finalsa/http/__init__.py +0 -0
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/finalsa/http/_shared.py +0 -0
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/finalsa/http/async_client/__init__.py +0 -0
- {finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/finalsa/http/sync_client/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: finalsa-common-http-client
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Summary: HTTP client library for common data types used in business applications
|
|
5
5
|
Project-URL: Homepage, https://github.com/finalsa/finalsa-http-client
|
|
6
6
|
Project-URL: Documentation, https://github.com/finalsa/finalsa-http-client#readme
|
|
@@ -36,17 +36,18 @@ Classifier: Intended Audience :: Developers
|
|
|
36
36
|
Classifier: License :: OSI Approved :: MIT License
|
|
37
37
|
Classifier: Operating System :: OS Independent
|
|
38
38
|
Classifier: Programming Language :: Python :: 3
|
|
39
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
40
39
|
Classifier: Programming Language :: Python :: 3.10
|
|
41
40
|
Classifier: Programming Language :: Python :: 3.11
|
|
42
41
|
Classifier: Programming Language :: Python :: 3.12
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
43
43
|
Classifier: Topic :: Software Development :: Internationalization
|
|
44
44
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
45
45
|
Classifier: Topic :: Software Development :: Localization
|
|
46
46
|
Classifier: Typing :: Typed
|
|
47
|
-
Requires-Python: >=3.
|
|
47
|
+
Requires-Python: >=3.10
|
|
48
48
|
Requires-Dist: aiohttp>=3.10.5
|
|
49
49
|
Requires-Dist: fastapi>=0.116.1
|
|
50
|
+
Requires-Dist: finalsa-common-models>=2.0.4
|
|
50
51
|
Requires-Dist: finalsa-traceability>=1.0.1
|
|
51
52
|
Requires-Dist: requests>=2.32.4
|
|
52
53
|
Description-Content-Type: text/markdown
|
|
@@ -4,7 +4,8 @@ from collections.abc import Mapping
|
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
6
|
import aiohttp
|
|
7
|
-
from aiohttp import ClientSession, ClientTimeout
|
|
7
|
+
from aiohttp import ClientResponseError, ClientSession, ClientTimeout
|
|
8
|
+
from finalsa.common.models import BaseDomainException
|
|
8
9
|
|
|
9
10
|
from finalsa.http import _shared as shared
|
|
10
11
|
|
|
@@ -46,7 +47,8 @@ class BaseAsyncHttpClient:
|
|
|
46
47
|
await self._ensure_session()
|
|
47
48
|
return self
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
# type: ignore[override]
|
|
51
|
+
async def __aexit__(self, exc_type, exc, tb) -> None:
|
|
50
52
|
await self.close()
|
|
51
53
|
|
|
52
54
|
@property
|
|
@@ -100,17 +102,31 @@ class BaseAsyncHttpClient:
|
|
|
100
102
|
)
|
|
101
103
|
merged_headers = shared.merge_headers(self._default_headers, headers)
|
|
102
104
|
request_timeout = self._normalize_timeout(timeout) or self._timeout
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
response = None
|
|
106
|
+
try:
|
|
107
|
+
|
|
108
|
+
response = await session.request(
|
|
109
|
+
method.upper(),
|
|
110
|
+
resolved_url,
|
|
111
|
+
headers=merged_headers,
|
|
112
|
+
params=params,
|
|
113
|
+
json=json,
|
|
114
|
+
data=data,
|
|
115
|
+
timeout=request_timeout,
|
|
116
|
+
**kwargs,
|
|
117
|
+
)
|
|
118
|
+
response.raise_for_status()
|
|
119
|
+
return response
|
|
120
|
+
except ClientResponseError as e:
|
|
121
|
+
if "Content-Type" in e.headers and e.headers["Content-Type"] == "application/json" and response is not None:
|
|
122
|
+
data = await response.json()
|
|
123
|
+
if data.get("message") and data.get("name"):
|
|
124
|
+
raise BaseDomainException(
|
|
125
|
+
message=data.get("message"),
|
|
126
|
+
response_code=response.status_code,
|
|
127
|
+
name=data.get("name")
|
|
128
|
+
) from e
|
|
129
|
+
raise e
|
|
114
130
|
|
|
115
131
|
async def get(self, path: str, **kwargs: Any) -> aiohttp.ClientResponse:
|
|
116
132
|
return await self.request("GET", path, **kwargs)
|
|
@@ -139,7 +155,6 @@ class BaseAsyncHttpClient:
|
|
|
139
155
|
self._session = aiohttp.ClientSession(
|
|
140
156
|
timeout=self._timeout,
|
|
141
157
|
trust_env=self._trust_env,
|
|
142
|
-
raise_for_status=self._raise_for_status,
|
|
143
158
|
)
|
|
144
159
|
return self._session
|
|
145
160
|
|
|
@@ -4,6 +4,7 @@ from collections.abc import Mapping
|
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
6
|
import requests
|
|
7
|
+
from finalsa.common.models import BaseDomainException
|
|
7
8
|
|
|
8
9
|
from finalsa.http import _shared as shared
|
|
9
10
|
|
|
@@ -99,20 +100,30 @@ class BaseSyncHttpClient:
|
|
|
99
100
|
)
|
|
100
101
|
merged_headers = shared.merge_headers(self._default_headers, headers)
|
|
101
102
|
request_timeout = timeout if timeout is not None else self._timeout
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
103
|
+
try:
|
|
104
|
+
response = session.request(
|
|
105
|
+
method.upper(),
|
|
106
|
+
resolved_url,
|
|
107
|
+
headers=merged_headers,
|
|
108
|
+
params=params,
|
|
109
|
+
json=json,
|
|
110
|
+
data=data,
|
|
111
|
+
timeout=request_timeout,
|
|
112
|
+
**kwargs,
|
|
113
|
+
)
|
|
114
|
+
if self._raise_for_status:
|
|
115
|
+
response.raise_for_status()
|
|
116
|
+
return response
|
|
117
|
+
except requests.RequestException as e:
|
|
118
|
+
if e.response is not None and "Content-Type" in e.response.headers and e.response.headers["Content-Type"] == "application/json":
|
|
119
|
+
data = e.response.json()
|
|
120
|
+
if data.get("message") and data.get("name"):
|
|
121
|
+
raise BaseDomainException(
|
|
122
|
+
message=data.get("message"),
|
|
123
|
+
response_code=e.response.status_code,
|
|
124
|
+
name=data.get("name")
|
|
125
|
+
) from e
|
|
126
|
+
raise e
|
|
116
127
|
|
|
117
128
|
def get(self, path: str, **kwargs: Any) -> requests.Response:
|
|
118
129
|
return self.request("GET", path, **kwargs)
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "finalsa-common-http-client"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.3"
|
|
4
4
|
description = "HTTP client library for common data types used in business applications"
|
|
5
5
|
readme = "README.md"
|
|
6
|
-
requires-python = ">=3.
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
7
|
dependencies = [
|
|
8
8
|
"aiohttp>=3.10.5",
|
|
9
9
|
"fastapi>=0.116.1",
|
|
10
|
+
"finalsa-common-models>=2.0.4",
|
|
10
11
|
"finalsa-traceability>=1.0.1",
|
|
11
12
|
"requests>=2.32.4",
|
|
12
13
|
]
|
|
@@ -24,10 +25,10 @@ classifiers = [
|
|
|
24
25
|
"License :: OSI Approved :: MIT License",
|
|
25
26
|
"Operating System :: OS Independent",
|
|
26
27
|
"Programming Language :: Python :: 3",
|
|
27
|
-
"Programming Language :: Python :: 3.9",
|
|
28
28
|
"Programming Language :: Python :: 3.10",
|
|
29
29
|
"Programming Language :: Python :: 3.11",
|
|
30
30
|
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
31
32
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
32
33
|
"Topic :: Software Development :: Internationalization",
|
|
33
34
|
"Topic :: Software Development :: Localization",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/finalsa/http/__init__.py
RENAMED
|
File without changes
|
{finalsa_common_http_client-0.0.2 → finalsa_common_http_client-0.0.3}/finalsa/http/_shared.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|