Skip to content

Commit e683d64

Browse files
author
Michael Brewer
committed
docs: add some missing doc strings
1 parent 8494cde commit e683d64

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def _compress(self):
110110
gzip = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS | 16)
111111
self.response.body = gzip.compress(self.response.body) + gzip.flush()
112112

113-
def _route(self, event: BaseProxyEvent, cors: CORSConfig = None):
113+
def _route(self, event: BaseProxyEvent, cors: Optional[CORSConfig]):
114+
"""Optionally handle any of the route's configure response handling"""
114115
if self.route is None:
115116
return
116117
if self.route.cors:
@@ -173,19 +174,25 @@ def resolve(self, event, context) -> Dict[str, Any]:
173174
self.lambda_context = context
174175
return self._resolve_response().build(self.current_event, self._cors)
175176

177+
def __call__(self, event, context) -> Any:
178+
return self.resolve(event, context)
179+
176180
@staticmethod
177181
def _compile_regex(rule: str):
182+
"""Precompile regex pattern"""
178183
rule_regex: str = re.sub(r"(<\w+>)", r"(?P\1.+)", rule)
179184
return re.compile("^{}$".format(rule_regex))
180185

181186
def _to_data_class(self, event: Dict) -> BaseProxyEvent:
187+
"""Convert the event dict to the corresponding data class"""
182188
if self._proxy_type == ProxyEventType.http_api_v1:
183189
return APIGatewayProxyEvent(event)
184190
if self._proxy_type == ProxyEventType.http_api_v2:
185191
return APIGatewayProxyEventV2(event)
186192
return ALBEvent(event)
187193

188194
def _resolve_response(self) -> ResponseBuilder:
195+
"""Resolve the response or return the not found response"""
189196
method = self.current_event.http_method.upper()
190197
path = self.current_event.path
191198
for route in self._routes:
@@ -195,9 +202,10 @@ def _resolve_response(self) -> ResponseBuilder:
195202
if match:
196203
return self._call_route(route, match.groupdict())
197204

198-
return self.not_found(method, path)
205+
return self._not_found(method, path)
199206

200-
def not_found(self, method: str, path: str) -> ResponseBuilder:
207+
def _not_found(self, method: str, path: str) -> ResponseBuilder:
208+
"""No matching route was found, includes support for the cors preflight response"""
201209
headers = {}
202210
if self._cors:
203211
headers.update(self._cors.to_dict())
@@ -214,10 +222,12 @@ def not_found(self, method: str, path: str) -> ResponseBuilder:
214222
)
215223

216224
def _call_route(self, route: Route, args: Dict[str, str]) -> ResponseBuilder:
225+
"""Actually call the matching route with any provided keyword arguments."""
217226
return ResponseBuilder(self._to_response(route.func(**args)), route)
218227

219228
@staticmethod
220229
def _to_response(result: Union[Tuple[int, str, Union[bytes, str]], Dict, Response]) -> Response:
230+
"""Convert the route result to a Response"""
221231
if isinstance(result, Response):
222232
return result
223233
elif isinstance(result, dict):
@@ -228,6 +238,3 @@ def _to_response(result: Union[Tuple[int, str, Union[bytes, str]], Dict, Respons
228238
)
229239
else: # Tuple[int, str, Union[bytes, str]]
230240
return Response(*result)
231-
232-
def __call__(self, event, context) -> Any:
233-
return self.resolve(event, context)

0 commit comments

Comments
 (0)