muffin-rest 8.1.0__py3-none-any.whl → 9.0.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 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
- if not (request.method == "GET" and resource is None):
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
- if meta.filters:
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
- if meta.sorting:
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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: muffin-rest
3
- Version: 8.1.0
3
+ Version: 9.0.0
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,6 +19,7 @@ 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
@@ -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=7DjPEtWmq7laWELKLJ6yZUwSdtxFIOps-699N_5_viQ,10277
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
@@ -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-8.1.0.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
37
- muffin_rest-8.1.0.dist-info/METADATA,sha256=nsCP8WeRU29Tdlfno68igQTZNIaZin39bWIfY2spMZI,4118
38
- muffin_rest-8.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
39
- muffin_rest-8.1.0.dist-info/RECORD,,
36
+ muffin_rest-9.0.0.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
37
+ muffin_rest-9.0.0.dist-info/METADATA,sha256=3chS--H-C60xpvb9nBi6hlBfRCjEUOQ8Jd8gJGq11uM,4169
38
+ muffin_rest-9.0.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
39
+ muffin_rest-9.0.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 1.9.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any