rapid-api-client 0.3.4__tar.gz → 0.3.6__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.
- {rapid_api_client-0.3.4 → rapid_api_client-0.3.6}/PKG-INFO +1 -1
- {rapid_api_client-0.3.4 → rapid_api_client-0.3.6}/pyproject.toml +1 -1
- {rapid_api_client-0.3.4 → rapid_api_client-0.3.6}/rapid_api_client/annotations.py +13 -4
- {rapid_api_client-0.3.4 → rapid_api_client-0.3.6}/rapid_api_client/client.py +16 -4
- {rapid_api_client-0.3.4 → rapid_api_client-0.3.6}/LICENSE +0 -0
- {rapid_api_client-0.3.4 → rapid_api_client-0.3.6}/README.md +0 -0
- {rapid_api_client-0.3.4 → rapid_api_client-0.3.6}/rapid_api_client/__init__.py +0 -0
- {rapid_api_client-0.3.4 → rapid_api_client-0.3.6}/rapid_api_client/decorator.py +0 -0
- {rapid_api_client-0.3.4 → rapid_api_client-0.3.6}/rapid_api_client/py.typed +0 -0
- {rapid_api_client-0.3.4 → rapid_api_client-0.3.6}/rapid_api_client/utils.py +0 -0
|
@@ -3,7 +3,7 @@ Model classes
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
|
-
from typing import Any
|
|
6
|
+
from typing import Any
|
|
7
7
|
|
|
8
8
|
from pydantic import BaseModel
|
|
9
9
|
|
|
@@ -49,8 +49,6 @@ class Body(BaseAnnotation):
|
|
|
49
49
|
Annotation to declare an argument used as http content for post/put/...
|
|
50
50
|
"""
|
|
51
51
|
|
|
52
|
-
target: Literal["content", "data", "files"] = "content"
|
|
53
|
-
|
|
54
52
|
def serialize(self, body: Any) -> str | bytes:
|
|
55
53
|
"""
|
|
56
54
|
Serialize the annotated parameter value
|
|
@@ -58,13 +56,24 @@ class Body(BaseAnnotation):
|
|
|
58
56
|
return body
|
|
59
57
|
|
|
60
58
|
|
|
59
|
+
@dataclass
|
|
60
|
+
class FormBody(Body):
|
|
61
|
+
"""
|
|
62
|
+
Annotation to declare an argument used as url-encoded parameter
|
|
63
|
+
If the annotated parameter is a Dict[str, str], its content will be merged to other form parameters,
|
|
64
|
+
else, its name (or alias) and its serialized value will be added to the the other form parameters.
|
|
65
|
+
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
alias: str | None = None
|
|
69
|
+
|
|
70
|
+
|
|
61
71
|
@dataclass
|
|
62
72
|
class FileBody(Body):
|
|
63
73
|
"""
|
|
64
74
|
Annotation to declare an argument used as file to be uploaded
|
|
65
75
|
"""
|
|
66
76
|
|
|
67
|
-
target: Literal["content", "data", "files"] = "files"
|
|
68
77
|
alias: str | None = None
|
|
69
78
|
|
|
70
79
|
|
|
@@ -16,9 +16,13 @@ from typing import (
|
|
|
16
16
|
|
|
17
17
|
from httpx import AsyncClient, Request, Response
|
|
18
18
|
from pydantic import BaseModel, TypeAdapter
|
|
19
|
-
from pydantic_xml import BaseXmlModel
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
try:
|
|
21
|
+
import pydantic_xml
|
|
22
|
+
except ImportError: # pragma: nocover
|
|
23
|
+
pydantic_xml = None # type: ignore
|
|
24
|
+
|
|
25
|
+
from .annotations import BaseAnnotation, Body, FileBody, FormBody, Header, Path, Query
|
|
22
26
|
from .utils import filter_none_values, find_annotation
|
|
23
27
|
|
|
24
28
|
BM = TypeVar("BM", bound=BaseModel)
|
|
@@ -103,8 +107,14 @@ class RapidApi:
|
|
|
103
107
|
if isinstance(annot, FileBody):
|
|
104
108
|
files = build_kwargs.setdefault("files", {})
|
|
105
109
|
files[annot.alias or param] = annot.serialize(value)
|
|
110
|
+
elif isinstance(annot, FormBody):
|
|
111
|
+
data = build_kwargs.setdefault("data", {})
|
|
112
|
+
if isinstance(value, dict):
|
|
113
|
+
data.update(value)
|
|
114
|
+
else:
|
|
115
|
+
data[annot.alias or param] = annot.serialize(value)
|
|
106
116
|
else:
|
|
107
|
-
build_kwargs[
|
|
117
|
+
build_kwargs["content"] = annot.serialize(value)
|
|
108
118
|
|
|
109
119
|
# handle extra optional kwargs
|
|
110
120
|
if timeout is not None:
|
|
@@ -131,7 +141,9 @@ class RapidApi:
|
|
|
131
141
|
return response.content
|
|
132
142
|
if isinstance(response_class, TypeAdapter):
|
|
133
143
|
return response_class.validate_json(response.content)
|
|
134
|
-
if issubclass(
|
|
144
|
+
if pydantic_xml is not None and issubclass(
|
|
145
|
+
response_class, pydantic_xml.BaseXmlModel
|
|
146
|
+
):
|
|
135
147
|
return response_class.from_xml(response.content)
|
|
136
148
|
if issubclass(response_class, BaseModel):
|
|
137
149
|
return response_class.model_validate_json(response.content)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|