Skip to content

Commit 4e9a46f

Browse files
author
Michael Brewer
committed
refactor: final cleanup
1 parent 242ab2f commit 4e9a46f

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ def build(self, event: BaseProxyEvent, cors: Optional[CORSConfig] = None) -> Dic
230230

231231

232232
class BaseRouter(ABC):
233+
current_event: BaseProxyEvent
234+
lambda_context: LambdaContext
235+
233236
@abstractmethod
234237
def route(
235238
self,
@@ -405,9 +408,6 @@ def lambda_handler(event, context):
405408
```
406409
"""
407410

408-
current_event: BaseProxyEvent
409-
lambda_context: LambdaContext
410-
411411
def __init__(
412412
self,
413413
proxy_type: Enum = ProxyEventType.APIGatewayProxyEvent,
@@ -494,8 +494,8 @@ def resolve(self, event, context) -> Dict[str, Any]:
494494
"""
495495
if self._debug:
496496
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
499499
return self._resolve().build(self.current_event, self._cors)
500500

501501
def __call__(self, event, context) -> Any:
@@ -661,8 +661,6 @@ def include_router(self, router: "Router", prefix: Optional[str] = None) -> None
661661
prefix : str, optional
662662
An optional prefix to be added to the originally defined rule
663663
"""
664-
router._app = self
665-
666664
for route, func in router._routes.items():
667665
if prefix:
668666
rule = route[0]
@@ -675,19 +673,9 @@ def include_router(self, router: "Router", prefix: Optional[str] = None) -> None
675673
class Router(BaseRouter):
676674
"""Router helper class to allow splitting ApiGatewayResolver into multiple files"""
677675

678-
_app: ApiGatewayResolver
679-
680676
def __init__(self):
681677
self._routes: Dict[tuple, Callable] = {}
682678

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-
691679
def route(
692680
self,
693681
rule: str,
@@ -697,10 +685,8 @@ def route(
697685
cache_control: Optional[str] = None,
698686
):
699687
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
705691

706692
return register_route

0 commit comments

Comments
 (0)