@@ -230,6 +230,9 @@ def build(self, event: BaseProxyEvent, cors: Optional[CORSConfig] = None) -> Dic
230
230
231
231
232
232
class BaseRouter (ABC ):
233
+ current_event : BaseProxyEvent
234
+ lambda_context : LambdaContext
235
+
233
236
@abstractmethod
234
237
def route (
235
238
self ,
@@ -405,9 +408,6 @@ def lambda_handler(event, context):
405
408
```
406
409
"""
407
410
408
- current_event : BaseProxyEvent
409
- lambda_context : LambdaContext
410
-
411
411
def __init__ (
412
412
self ,
413
413
proxy_type : Enum = ProxyEventType .APIGatewayProxyEvent ,
@@ -494,8 +494,8 @@ def resolve(self, event, context) -> Dict[str, Any]:
494
494
"""
495
495
if self ._debug :
496
496
print (self ._json_dump (event ))
497
- self .current_event = self ._to_proxy_event (event )
498
- self .lambda_context = context
497
+ BaseRouter .current_event = self ._to_proxy_event (event )
498
+ BaseRouter .lambda_context = context
499
499
return self ._resolve ().build (self .current_event , self ._cors )
500
500
501
501
def __call__ (self , event , context ) -> Any :
@@ -661,8 +661,6 @@ def include_router(self, router: "Router", prefix: Optional[str] = None) -> None
661
661
prefix : str, optional
662
662
An optional prefix to be added to the originally defined rule
663
663
"""
664
- router ._app = self
665
-
666
664
for route , func in router ._routes .items ():
667
665
if prefix :
668
666
rule = route [0 ]
@@ -675,19 +673,9 @@ def include_router(self, router: "Router", prefix: Optional[str] = None) -> None
675
673
class Router (BaseRouter ):
676
674
"""Router helper class to allow splitting ApiGatewayResolver into multiple files"""
677
675
678
- _app : ApiGatewayResolver
679
-
680
676
def __init__ (self ):
681
677
self ._routes : Dict [tuple , Callable ] = {}
682
678
683
- @property
684
- def current_event (self ) -> BaseProxyEvent :
685
- return self ._app .current_event
686
-
687
- @property
688
- def lambda_context (self ) -> LambdaContext :
689
- return self ._app .lambda_context
690
-
691
679
def route (
692
680
self ,
693
681
rule : str ,
@@ -697,10 +685,8 @@ def route(
697
685
cache_control : Optional [str ] = None ,
698
686
):
699
687
def register_route (func : Callable ):
700
- if isinstance (method , list ):
701
- for item in method :
702
- self ._routes [(rule , item , cors , compress , cache_control )] = func
703
- else :
704
- self ._routes [(rule , method , cors , compress , cache_control )] = func
688
+ methods = method if isinstance (method , list ) else [method ]
689
+ for item in methods :
690
+ self ._routes [(rule , item , cors , compress , cache_control )] = func
705
691
706
692
return register_route
0 commit comments