Skip to content

Commit 8001dfa

Browse files
committed
fix: resolver circular dependencies
1 parent 72375cc commit 8001dfa

File tree

7 files changed

+50
-6
lines changed

7 files changed

+50
-6
lines changed

aws_lambda_powertools/event_handler/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
ApiGatewayResolver,
99
APIGatewayRestResolver,
1010
CORSConfig,
11-
Response,
1211
)
1312
from aws_lambda_powertools.event_handler.appsync import AppSyncResolver
1413
from aws_lambda_powertools.event_handler.lambda_function_url import (
1514
LambdaFunctionUrlResolver,
1615
)
16+
from aws_lambda_powertools.event_handler.response import Response
1717
from aws_lambda_powertools.event_handler.vpc_lattice import VPCLatticeResolver
1818

1919
__all__ = [

aws_lambda_powertools/event_handler/api_gateway.py

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from aws_lambda_powertools.event_handler.openapi.dependant import get_dependant
3333
from aws_lambda_powertools.event_handler.openapi.models import Contact, License, OpenAPI, Server, Tag
3434
from aws_lambda_powertools.event_handler.openapi.utils import get_flat_params
35+
from aws_lambda_powertools.event_handler.response import Response
3536
from aws_lambda_powertools.event_handler.route import Route
3637
from aws_lambda_powertools.shared.cookies import Cookie
3738
from aws_lambda_powertools.shared.functions import powertools_dev_is_set

aws_lambda_powertools/event_handler/middlewares/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import ABC, abstractmethod
22
from typing import Generic
33

4-
from aws_lambda_powertools.event_handler.api_gateway import Response
4+
from aws_lambda_powertools.event_handler import Response
55
from aws_lambda_powertools.event_handler.types import EventHandlerInstance
66
from aws_lambda_powertools.shared.types import Protocol
77

aws_lambda_powertools/event_handler/middlewares/schema_validation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from typing import Dict, Optional
33

4-
from aws_lambda_powertools.event_handler.api_gateway import Response
4+
from aws_lambda_powertools.event_handler import Response
55
from aws_lambda_powertools.event_handler.exceptions import BadRequestError, InternalServerError
66
from aws_lambda_powertools.event_handler.middlewares import BaseMiddlewareHandler, NextMiddleware
77
from aws_lambda_powertools.event_handler.types import EventHandlerInstance
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from typing import Dict, List, Optional, Union
2+
3+
from aws_lambda_powertools.shared.cookies import Cookie
4+
5+
6+
class Response:
7+
"""Response data class that provides greater control over what is returned from the proxy event"""
8+
9+
def __init__(
10+
self,
11+
status_code: int,
12+
content_type: Optional[str] = None,
13+
body: Union[str, bytes, None] = None,
14+
headers: Optional[Dict[str, Union[str, List[str]]]] = None,
15+
cookies: Optional[List[Cookie]] = None,
16+
compress: Optional[bool] = None,
17+
):
18+
"""
19+
20+
Parameters
21+
----------
22+
status_code: int
23+
Http status code, example 200
24+
content_type: str
25+
Optionally set the Content-Type header, example "application/json". Note this will be merged into any
26+
provided http headers
27+
body: Union[str, bytes, None]
28+
Optionally set the response body. Note: bytes body will be automatically base64 encoded
29+
headers: dict[str, Union[str, List[str]]]
30+
Optionally set specific http headers. Setting "Content-Type" here would override the `content_type` value.
31+
cookies: list[Cookie]
32+
Optionally set cookies.
33+
"""
34+
self.status_code = status_code
35+
self.body = body
36+
self.base64_encoded = False
37+
self.headers: Dict[str, Union[str, List[str]]] = headers if headers else {}
38+
self.cookies = cookies or []
39+
self.compress = compress
40+
if content_type:
41+
self.headers.setdefault("Content-Type", content_type)

aws_lambda_powertools/event_handler/route.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import logging
12
import warnings
23
from re import Pattern
34
from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Tuple, Union, cast
45

56
from pydantic.fields import ModelField
67
from pydantic.schema import TypeModelOrEnum, field_schema
78

8-
from aws_lambda_powertools.event_handler import Response
9-
from aws_lambda_powertools.event_handler.api_gateway import logger
109
from aws_lambda_powertools.event_handler.openapi.params import Dependant, Param
1110
from aws_lambda_powertools.event_handler.openapi.utils import get_flat_params
11+
from aws_lambda_powertools.event_handler.response import Response
12+
13+
logger = logging.getLogger(__name__)
1214

1315

1416
class MiddlewareFrame:

examples/event_handler_rest/src/binary_responses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from pathlib import Path
33

44
from aws_lambda_powertools import Logger, Tracer
5+
from aws_lambda_powertools.event_handler import Response
56
from aws_lambda_powertools.event_handler.api_gateway import (
67
APIGatewayRestResolver,
7-
Response,
88
)
99
from aws_lambda_powertools.logging import correlation_paths
1010
from aws_lambda_powertools.utilities.typing import LambdaContext

0 commit comments

Comments
 (0)