def normalize_handler( route: Route, services: Services) -> Callable[[Request], Awaitable[Response]]: method = route.handler sig = Signature.from_callable(method) params = sig.parameters params_len = len(params) if any( str(param).startswith("*") or param.kind.value == _ParameterKind.KEYWORD_ONLY for param in params.values()): raise UnsupportedSignatureError(method) if inspect.iscoroutinefunction(method): normalized = get_async_wrapper(services, route, method, params, params_len) else: normalized = get_sync_wrapper(services, route, method, params, params_len) if normalized is not method: copy_special_attributes(method, normalized) _copy_name_and_docstring(method, normalized) return normalized
def get_middlewares_chain(middlewares, handler): fn = handler for middleware in reversed(middlewares): if not middleware: continue wrapper_fn = middleware_partial(middleware, fn) copy_special_attributes(fn, wrapper_fn) fn = wrapper_fn return fn
def normalize_handler(route, services): method = route.handler sig = Signature.from_callable(method) params = sig.parameters params_len = len(params) if inspect.iscoroutinefunction(method): normalized = get_async_wrapper(services, route, method, params, params_len) else: normalized = get_sync_wrapper(services, route, method, params, params_len) if normalized is not method: copy_special_attributes(method, normalized) _copy_name_and_docstring(method, normalized) return normalized
def normalize_handler(route, services): method = route.handler sig = Signature.from_callable(method) params = sig.parameters params_len = len(params) if any(str(param).startswith('*') for param in params.values()): raise UnsupportedSignatureError(method) if inspect.iscoroutinefunction(method): normalized = get_async_wrapper(services, route, method, params, params_len) else: normalized = get_sync_wrapper(services, route, method, params, params_len) if normalized is not method: copy_special_attributes(method, normalized) _copy_name_and_docstring(method, normalized) return normalized
def normalize_handler( route: Route, services: Services ) -> Callable[[Request], Awaitable[Response]]: method = route.handler sig = Signature.from_callable(method) params = _get_method_annotations_base(method) params_len = len(params) if any( str(param).startswith("*") or param.kind.value == _ParameterKind.KEYWORD_ONLY for param in params.values() ): raise UnsupportedSignatureError(method) return_type = sig.return_annotation # normalize input if inspect.iscoroutinefunction(method): normalized = get_async_wrapper(services, route, method, params, params_len) else: normalized = get_sync_wrapper(services, route, method, params, params_len) # normalize output if return_type is _empty or return_type is not Response: if return_type is not _empty: # this scenario enables a more accurate automatic generation of # OpenAPI Documentation, for responses setattr(route.handler, "return_type", return_type) normalized = get_async_wrapper_for_output(normalized) if normalized is not method: setattr(normalized, "root_fn", method) copy_special_attributes(method, normalized) return normalized