muffin-rest 10.0.0__py3-none-any.whl → 10.1.0__py3-none-any.whl
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.
- muffin_rest/handler.py +12 -3
- muffin_rest/marshmallow.py +4 -10
- {muffin_rest-10.0.0.dist-info → muffin_rest-10.1.0.dist-info}/METADATA +1 -1
- {muffin_rest-10.0.0.dist-info → muffin_rest-10.1.0.dist-info}/RECORD +6 -6
- {muffin_rest-10.0.0.dist-info → muffin_rest-10.1.0.dist-info}/WHEEL +1 -1
- {muffin_rest-10.0.0.dist-info → muffin_rest-10.1.0.dist-info}/LICENSE +0 -0
muffin_rest/handler.py
CHANGED
|
@@ -8,6 +8,7 @@ from typing import (
|
|
|
8
8
|
Generic,
|
|
9
9
|
Iterable,
|
|
10
10
|
Literal,
|
|
11
|
+
Mapping,
|
|
11
12
|
Optional,
|
|
12
13
|
Sequence,
|
|
13
14
|
Union,
|
|
@@ -222,14 +223,22 @@ class RESTBase(Generic[TVResource], Handler, metaclass=RESTHandlerMeta):
|
|
|
222
223
|
schema_options.setdefault("exclude", query.get("schema_exclude", ()))
|
|
223
224
|
return self.meta.Schema(**schema_options)
|
|
224
225
|
|
|
226
|
+
async def load_data(self, request: Request):
|
|
227
|
+
"""Load data from request and create/update a resource."""
|
|
228
|
+
try:
|
|
229
|
+
data = await request.data(raise_errors=True)
|
|
230
|
+
except (ValueError, TypeError) as err:
|
|
231
|
+
raise APIError.BAD_REQUEST(str(err)) from err
|
|
232
|
+
|
|
233
|
+
return data
|
|
234
|
+
|
|
225
235
|
async def load(
|
|
226
236
|
self, request: Request, resource: Optional[TVResource] = None, **schema_options
|
|
227
237
|
) -> TVData[TVResource]:
|
|
228
238
|
"""Load data from request and create/update a resource."""
|
|
229
239
|
schema = self.get_schema(request, resource=resource, **schema_options)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
)
|
|
240
|
+
data = cast(Union[Mapping, list], await self.load_data(request))
|
|
241
|
+
return cast(TVData[TVResource], await load_data(data, schema, partial=resource is not None))
|
|
233
242
|
|
|
234
243
|
@overload
|
|
235
244
|
async def dump( # type: ignore[misc]
|
muffin_rest/marshmallow.py
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from typing import TYPE_CHECKING, Optional, Union, cast
|
|
3
|
+
from typing import TYPE_CHECKING, Optional, Union
|
|
5
4
|
|
|
6
5
|
from marshmallow import Schema, ValidationError
|
|
7
6
|
|
|
8
7
|
from muffin_rest.errors import APIError
|
|
9
8
|
|
|
10
9
|
if TYPE_CHECKING:
|
|
11
|
-
from
|
|
10
|
+
from collections.abc import Mapping
|
|
12
11
|
|
|
13
12
|
|
|
14
|
-
async def load_data(
|
|
15
|
-
try:
|
|
16
|
-
data = await request.data(raise_errors=True)
|
|
17
|
-
except (ValueError, TypeError) as err:
|
|
18
|
-
raise APIError.BAD_REQUEST(str(err)) from err
|
|
19
|
-
|
|
13
|
+
async def load_data(data: Union[Mapping, list], schema: Optional[Schema] = None, **params):
|
|
20
14
|
if schema is None:
|
|
21
15
|
return data
|
|
22
16
|
|
|
23
17
|
try:
|
|
24
|
-
return schema.load(
|
|
18
|
+
return schema.load(data, many=isinstance(data, list), **params)
|
|
25
19
|
except ValidationError as err:
|
|
26
20
|
raise APIError.BAD_REQUEST("Bad request data", errors=err.messages) from err
|
|
@@ -2,9 +2,9 @@ muffin_rest/__init__.py,sha256=NBZeOEJgQHtFFhVgd9d0fpApFRgU405sbm0cu1y1MOU,1242
|
|
|
2
2
|
muffin_rest/api.py,sha256=zssoHjqTsa8UCAyxj6TxQVluYPX9Sigyiph6SRxBY6I,3870
|
|
3
3
|
muffin_rest/errors.py,sha256=mxEBhNPo3pwpG2em6zaQonbfRgHFBJ3I8WunVYWDjvM,1163
|
|
4
4
|
muffin_rest/filters.py,sha256=hc-fhBODwrgJM_CvXNtTVH6jIOkjLog8En0iKKYXAGU,5947
|
|
5
|
-
muffin_rest/handler.py,sha256=
|
|
5
|
+
muffin_rest/handler.py,sha256=xRKUMzR2zISva0SbXS-piQ3Xq3d1zu-rZg6H2K7Oy0I,10824
|
|
6
6
|
muffin_rest/limits.py,sha256=Fnlu4Wj3B-BzpahLK-rDbd1GEd7CEQ3zxyOD0vee7GE,2007
|
|
7
|
-
muffin_rest/marshmallow.py,sha256=
|
|
7
|
+
muffin_rest/marshmallow.py,sha256=UeHxZLtETlrheDAlMZn7Xv_7vWPxvJQo-sj05nql9gM,574
|
|
8
8
|
muffin_rest/mongo/__init__.py,sha256=SiYSbX6ySJl43fw9aGREIs8ZsS8Qk_ieizoPOj4DjJc,4656
|
|
9
9
|
muffin_rest/mongo/filters.py,sha256=yIxIDVqMn6SoDgVhCqiTxYetw0hoaf_3jIvX2Vnizok,964
|
|
10
10
|
muffin_rest/mongo/schema.py,sha256=y4OEPQnlV_COTIIQ3cKmpqDpD2r18eAWn0rijQldWm0,1205
|
|
@@ -33,7 +33,7 @@ muffin_rest/sqlalchemy/types.py,sha256=Exm-zAQCtPAwXvYcCTtPRqSa-wTEWRcH_v2YSsJkB
|
|
|
33
33
|
muffin_rest/swagger.html,sha256=2uGLu_KpkYf925KnDKHBJmV9pm6OHn5C3BWScESsUS8,1736
|
|
34
34
|
muffin_rest/types.py,sha256=m27-g6BI7qdSWGym4fWALBJa2ZpWR0_m0nlrDx7iTCo,566
|
|
35
35
|
muffin_rest/utils.py,sha256=c08E4HJ4SLYC-91GKPEbsyKTZ4sZbTN4qDqJbNg_HTE,2076
|
|
36
|
-
muffin_rest-10.
|
|
37
|
-
muffin_rest-10.
|
|
38
|
-
muffin_rest-10.
|
|
39
|
-
muffin_rest-10.
|
|
36
|
+
muffin_rest-10.1.0.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
|
|
37
|
+
muffin_rest-10.1.0.dist-info/METADATA,sha256=eZeEf9-ojFMBHyyQLX1tkRurpNj1NMufQda6B1d6I7o,4147
|
|
38
|
+
muffin_rest-10.1.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
39
|
+
muffin_rest-10.1.0.dist-info/RECORD,,
|
|
File without changes
|