Browse Source

begin to implement input_query in async

Bastien Sevajol 5 years ago
parent
commit
9a00759b4b
1 changed files with 33 additions and 5 deletions
  1. 33 5
      hapic/hapic.py

+ 33 - 5
hapic/hapic.py View File

19
 from hapic.decorator import InputPathControllerWrapper
19
 from hapic.decorator import InputPathControllerWrapper
20
 from hapic.decorator import AsyncInputPathControllerWrapper
20
 from hapic.decorator import AsyncInputPathControllerWrapper
21
 from hapic.decorator import InputQueryControllerWrapper
21
 from hapic.decorator import InputQueryControllerWrapper
22
+from hapic.decorator import AsyncInputQueryControllerWrapper
22
 from hapic.decorator import InputFilesControllerWrapper
23
 from hapic.decorator import InputFilesControllerWrapper
23
 from hapic.decorator import OutputBodyControllerWrapper
24
 from hapic.decorator import OutputBodyControllerWrapper
24
 from hapic.decorator import OutputHeadersControllerWrapper
25
 from hapic.decorator import OutputHeadersControllerWrapper
238
         context = context or self._context_getter
239
         context = context or self._context_getter
239
 
240
 
240
         decoration = self._get_input_path_controller_wrapper(
241
         decoration = self._get_input_path_controller_wrapper(
241
-            processor,
242
-            context,
243
-            error_http_code,
244
-            default_http_code,
242
+            context=context,
243
+            processor=processor,
244
+            error_http_code=error_http_code,
245
+            default_http_code=default_http_code,
245
         )
246
         )
246
 
247
 
247
         def decorator(func):
248
         def decorator(func):
262
         processor.schema = schema
263
         processor.schema = schema
263
         context = context or self._context_getter
264
         context = context or self._context_getter
264
 
265
 
265
-        decoration = InputQueryControllerWrapper(
266
+        decoration = self._get_input_query_controller_wrapper(
266
             context=context,
267
             context=context,
267
             processor=processor,
268
             processor=processor,
268
             error_http_code=error_http_code,
269
             error_http_code=error_http_code,
511
             error_http_code=error_http_code,
512
             error_http_code=error_http_code,
512
             default_http_code=default_http_code,
513
             default_http_code=default_http_code,
513
         )
514
         )
515
+
516
+    def _get_input_query_controller_wrapper(
517
+        self,
518
+        processor: ProcessorInterface,
519
+        context: ContextInterface,
520
+        error_http_code: HTTPStatus = HTTPStatus.BAD_REQUEST,
521
+        default_http_code: HTTPStatus = HTTPStatus.OK,
522
+        as_list: typing.List[str]=None,
523
+    ) -> typing.Union[
524
+        InputQueryControllerWrapper,
525
+        AsyncInputQueryControllerWrapper,
526
+    ]:
527
+        if not self._async:
528
+            return InputQueryControllerWrapper(
529
+                context=context,
530
+                processor=processor,
531
+                error_http_code=error_http_code,
532
+                default_http_code=default_http_code,
533
+                as_list=as_list,
534
+            )
535
+        return AsyncInputQueryControllerWrapper(
536
+            context=context,
537
+            processor=processor,
538
+            error_http_code=error_http_code,
539
+            default_http_code=default_http_code,
540
+            as_list=as_list,
541
+        )