muffin-rest 8.1.0__py3-none-any.whl → 9.1.1__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 +23 -10
- muffin_rest/peewee/handler.py +10 -10
- {muffin_rest-8.1.0.dist-info → muffin_rest-9.1.1.dist-info}/METADATA +5 -4
- {muffin_rest-8.1.0.dist-info → muffin_rest-9.1.1.dist-info}/RECORD +6 -6
- {muffin_rest-8.1.0.dist-info → muffin_rest-9.1.1.dist-info}/WHEEL +1 -1
- {muffin_rest-8.1.0.dist-info → muffin_rest-9.1.1.dist-info}/LICENSE +0 -0
muffin_rest/handler.py
CHANGED
|
@@ -29,7 +29,7 @@ from muffin_rest.types import TSchemaRes
|
|
|
29
29
|
|
|
30
30
|
from .errors import HandlerNotBindedError
|
|
31
31
|
from .options import RESTOptions
|
|
32
|
-
from .types import TVData, TVResource
|
|
32
|
+
from .types import TVCollection, TVData, TVResource
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
class RESTHandlerMeta(HandlerMeta):
|
|
@@ -94,28 +94,26 @@ class RESTBase(Generic[TVResource], Handler, metaclass=RESTHandlerMeta):
|
|
|
94
94
|
|
|
95
95
|
async def __call__(self, request: Request, *, method_name: Optional[str] = None, **_) -> Any:
|
|
96
96
|
"""Dispatch the given request by HTTP method."""
|
|
97
|
-
method = getattr(self, method_name or request.method.lower())
|
|
98
|
-
meta = self.meta
|
|
99
97
|
self.auth = await self.authorize(request)
|
|
98
|
+
|
|
99
|
+
meta = self.meta
|
|
100
100
|
if meta.rate_limit:
|
|
101
101
|
await self.rate_limit(request)
|
|
102
102
|
|
|
103
103
|
self.collection = await self.prepare_collection(request)
|
|
104
104
|
resource = await self.prepare_resource(request)
|
|
105
|
-
|
|
105
|
+
method = getattr(self, method_name or request.method.lower())
|
|
106
|
+
if not (request.method == "GET" and resource is None and not method_name):
|
|
106
107
|
return await method(request, resource=resource)
|
|
107
108
|
|
|
108
|
-
headers = None
|
|
109
|
-
|
|
110
109
|
# Filter collection
|
|
111
|
-
|
|
112
|
-
self.collection, self.filters = await meta.filters.apply(request, self.collection)
|
|
110
|
+
self.collection, self.filters = await self.filter(request, self.collection)
|
|
113
111
|
|
|
114
112
|
# Sort collection
|
|
115
|
-
|
|
116
|
-
self.collection, self.sorting = await meta.sorting.apply(request, self.collection)
|
|
113
|
+
self.collection, self.sorting = await self.sort(request, self.collection)
|
|
117
114
|
|
|
118
115
|
# Paginate the collection
|
|
116
|
+
headers = None
|
|
119
117
|
if meta.limit:
|
|
120
118
|
limit, offset = self.paginate_prepare_params(request)
|
|
121
119
|
if limit and offset >= 0:
|
|
@@ -160,6 +158,21 @@ class RESTBase(Generic[TVResource], Handler, metaclass=RESTHandlerMeta):
|
|
|
160
158
|
"""Load a resource."""
|
|
161
159
|
return request["path_params"].get(self.meta.name_id)
|
|
162
160
|
|
|
161
|
+
async def filter(self, request: Request, collection: TVCollection) -> tuple[TVCollection, Any]:
|
|
162
|
+
"""Filter the collection."""
|
|
163
|
+
filters = self.meta.filters
|
|
164
|
+
if filters:
|
|
165
|
+
return await filters.apply(request, collection)
|
|
166
|
+
|
|
167
|
+
return collection, None
|
|
168
|
+
|
|
169
|
+
async def sort(self, request: Request, collection: TVCollection) -> tuple[TVCollection, Any]:
|
|
170
|
+
sorting = self.meta.sorting
|
|
171
|
+
if sorting:
|
|
172
|
+
return await sorting.apply(request, collection)
|
|
173
|
+
|
|
174
|
+
return collection, None
|
|
175
|
+
|
|
163
176
|
# Paginate
|
|
164
177
|
# --------
|
|
165
178
|
def paginate_prepare_headers(self, limit, offset, total=None):
|
muffin_rest/peewee/handler.py
CHANGED
|
@@ -92,18 +92,18 @@ class PWRESTBase(RESTBase[TVModel], PeeweeOpenAPIMixin):
|
|
|
92
92
|
|
|
93
93
|
async def paginate(self, _: Request, *, limit: int = 0, offset: int = 0):
|
|
94
94
|
"""Paginate the collection."""
|
|
95
|
-
cqs = cast(pw.ModelSelect, self.collection.order_by())
|
|
96
|
-
if cqs._group_by: # type: ignore[misc]
|
|
97
|
-
cqs._returning = cqs._group_by # type: ignore[misc]
|
|
98
|
-
cqs._having = None # type: ignore[misc]
|
|
99
|
-
count = None
|
|
100
95
|
if self.meta.limit_total:
|
|
101
|
-
|
|
96
|
+
cqs = cast(pw.ModelSelect, self.collection.order_by())
|
|
97
|
+
if cqs._group_by: # type: ignore[misc]
|
|
98
|
+
cqs._returning = cqs._group_by # type: ignore[misc]
|
|
99
|
+
cqs._having = None # type: ignore[misc]
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
count = await self.meta.manager.count(cqs)
|
|
102
|
+
|
|
103
|
+
else:
|
|
104
|
+
count = None
|
|
105
|
+
|
|
106
|
+
return self.collection.offset(offset).limit(limit), count
|
|
107
107
|
|
|
108
108
|
async def get(self, request, *, resource: Optional[TVModel] = None) -> Any:
|
|
109
109
|
"""Get resource or collection of resources."""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: muffin-rest
|
|
3
|
-
Version:
|
|
3
|
+
Version: 9.1.1
|
|
4
4
|
Summary: The package provides enhanced support for writing REST APIs with Muffin framework
|
|
5
5
|
Home-page: https://github.com/klen/muffin-rest
|
|
6
6
|
License: MIT
|
|
@@ -19,17 +19,18 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.10
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
23
|
Classifier: Topic :: Internet :: WWW/HTTP
|
|
23
24
|
Provides-Extra: peewee
|
|
24
25
|
Provides-Extra: sqlalchemy
|
|
25
26
|
Provides-Extra: yaml
|
|
26
27
|
Requires-Dist: apispec (>=6,<7)
|
|
27
28
|
Requires-Dist: marshmallow (>=3,<4)
|
|
28
|
-
Requires-Dist: marshmallow-peewee
|
|
29
|
+
Requires-Dist: marshmallow-peewee ; extra == "peewee"
|
|
29
30
|
Requires-Dist: marshmallow-sqlalchemy ; extra == "sqlalchemy"
|
|
30
31
|
Requires-Dist: muffin (>=0,<1)
|
|
31
|
-
Requires-Dist: muffin-databases
|
|
32
|
-
Requires-Dist: muffin-peewee-aio
|
|
32
|
+
Requires-Dist: muffin-databases ; extra == "sqlalchemy"
|
|
33
|
+
Requires-Dist: muffin-peewee-aio ; extra == "peewee"
|
|
33
34
|
Requires-Dist: pyyaml ; extra == "yaml"
|
|
34
35
|
Requires-Dist: sqlalchemy ; extra == "sqlalchemy"
|
|
35
36
|
Project-URL: Repository, https://github.com/klen/muffin-rest
|
|
@@ -2,7 +2,7 @@ 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=MARP_WsJslncahlgZLTImigl0RTxBtb0jmZbXfJ0c6Y,5637
|
|
5
|
-
muffin_rest/handler.py,sha256=
|
|
5
|
+
muffin_rest/handler.py,sha256=3efL8-AbxR0oHEwySfWSyfRuxCWyJOwDaYAhUzg6f-0,10772
|
|
6
6
|
muffin_rest/limits.py,sha256=pA5hnDQgrP-euDGjAoczlT_b7Dxzw5btQ-3okkHYKSA,1855
|
|
7
7
|
muffin_rest/marshmallow.py,sha256=jWsZeMj3KslbGGgzEMo8-e5eeuGhmqFolL0mIEquylc,789
|
|
8
8
|
muffin_rest/mongo/__init__.py,sha256=SiYSbX6ySJl43fw9aGREIs8ZsS8Qk_ieizoPOj4DjJc,4656
|
|
@@ -15,7 +15,7 @@ muffin_rest/openapi.py,sha256=0QU7qrfBjGl0vl378SJC5boZZI2ogddl45fS9WL4Axw,8751
|
|
|
15
15
|
muffin_rest/options.py,sha256=reHbd2o-F6bKEKc8bznzj0TMY2vzjK6Yt1qOny7kt_w,2691
|
|
16
16
|
muffin_rest/peewee/__init__.py,sha256=94DSj_ftT6fbPksHlBv40AH2HWaiZommUFOMN2jd9a4,129
|
|
17
17
|
muffin_rest/peewee/filters.py,sha256=oghjKwurNCyFUYT0r2TVu2Nd1SIalRsmbU4_RbaoXLs,2440
|
|
18
|
-
muffin_rest/peewee/handler.py,sha256=
|
|
18
|
+
muffin_rest/peewee/handler.py,sha256=Tk20ChTGkhzSF0K1-TFruPfXJyHfJE_fDKcQqGQeoAU,5297
|
|
19
19
|
muffin_rest/peewee/openapi.py,sha256=lDnLnoXi33p0YeFVwRgaVrndyrG2XL93RH-BzbxinOY,1105
|
|
20
20
|
muffin_rest/peewee/options.py,sha256=TimJtErC9e8B7BRiEkHiBZd71_bZbYr-FE2PIlQvfH0,1455
|
|
21
21
|
muffin_rest/peewee/schemas.py,sha256=w6jBziUp40mOOjkz_4RCXuY0x5ZDIe9Ob25k1FnZSfc,469
|
|
@@ -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=lU0tAaDu9sKm-30RM1_qOx-hOYEkNRaA72LdWDvg72g,491
|
|
35
35
|
muffin_rest/utils.py,sha256=c08E4HJ4SLYC-91GKPEbsyKTZ4sZbTN4qDqJbNg_HTE,2076
|
|
36
|
-
muffin_rest-
|
|
37
|
-
muffin_rest-
|
|
38
|
-
muffin_rest-
|
|
39
|
-
muffin_rest-
|
|
36
|
+
muffin_rest-9.1.1.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
|
|
37
|
+
muffin_rest-9.1.1.dist-info/METADATA,sha256=wD6-ATvsx8N9AJQ4OB2Yz7dWAyLarB37eZsR5pAjcrk,4134
|
|
38
|
+
muffin_rest-9.1.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
39
|
+
muffin_rest-9.1.1.dist-info/RECORD,,
|
|
File without changes
|