@@ -24,18 +24,17 @@ class RenderDecoratorException(Exception):
2424 pass
2525
2626
27- class Render :
28- def __init__ (self , template_name : t .Optional [str ] = NOT_SET ) -> None :
29- if template_name is not NOT_SET :
30- assert isinstance (
31- template_name , str
32- ), "Render Operation must invoked eg. @Render()"
33- self .template_name = None if template_name is NOT_SET else template_name
34- self .class_base_function_regex = re .compile (
35- "<\\ w+ (\\ w+)\\ .(\\ w+) at \\ w+>" , re .IGNORECASE
36- )
37-
38- def __call__ (self , func : t .Union [t .Callable , t .Any ]) -> t .Union [t .Callable , t .Any ]:
27+ def render (template_name : t .Optional [str ] = NOT_SET ) -> t .Callable :
28+ if template_name is not NOT_SET :
29+ assert isinstance (
30+ template_name , str
31+ ), "Render Operation must invoked eg. @Render()"
32+ template_name = None if template_name is NOT_SET else template_name
33+ class_base_function_regex = re .compile (
34+ "<\\ w+ (\\ w+)\\ .(\\ w+) at \\ w+>" , re .IGNORECASE
35+ )
36+
37+ def _decorator (func : t .Union [t .Callable , t .Any ]) -> t .Union [t .Callable , t .Any ]:
3938 if not callable (func ) or isinstance (func , RouteOperationBase ):
4039 warnings .warn_explicit (
4140 UserWarning (
@@ -52,23 +51,25 @@ def __call__(self, func: t.Union[t.Callable, t.Any]) -> t.Union[t.Callable, t.An
5251 endpoint_name = get_name (func )
5352 is_class_base_function = use_mvc = False
5453
55- if self . class_base_function_regex .match (repr (func )):
54+ if class_base_function_regex .match (repr (func )):
5655 is_class_base_function = True
5756
58- if not self . template_name and is_class_base_function :
57+ if not template_name and is_class_base_function :
5958 use_mvc = True
6059
61- if not self . template_name and not is_class_base_function :
60+ if not template_name and not is_class_base_function :
6261 raise RenderDecoratorException (
6362 f"template_name is required for function endpoints. { func } "
6463 )
6564
6665 response = HTMLResponseModel (
67- template_name = self . template_name or endpoint_name , use_mvc = use_mvc
66+ template_name = template_name or endpoint_name , use_mvc = use_mvc
6867 )
6968 target_decorator = set_meta (RESPONSE_OVERRIDE_KEY , {200 : response })
7069 return target_decorator (func )
7170
71+ return _decorator
72+
7273
7374def _validate_template_function (f : t .Any ) -> None :
7475 if asyncio .iscoroutinefunction (f ):
0 commit comments