Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mangum/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from .response import Response
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move Response and Scope to a single file. The reason for doing so isn't for the imports, rather it is easier to maintain a single file with related classes like this.

Copy link
Copy Markdown
Contributor Author

@four43 four43 Mar 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I was able to clean up adapter so much, they might fit nicely in adapter... but now circular references.

from .scope import Scope
from .adapter import Mangum # noqa: F401

__all__ = ["Mangum", "Response", "Scope"]
11 changes: 5 additions & 6 deletions mangum/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from contextlib import ExitStack
from typing import Any, ContextManager, Dict, TYPE_CHECKING

from mangum.exceptions import ConfigurationError
from mangum.handlers import AbstractHandler
from mangum.protocols.http import HTTPCycle
from mangum.protocols.lifespan import LifespanCycle
from mangum.types import ASGIApp
from .exceptions import ConfigurationError
from .handlers import AbstractHandler
from .protocols import HTTPCycle, LifespanCycle
from .types import ASGIApp

if TYPE_CHECKING: # pragma: no cover
from awslambdaric.lambda_context import LambdaContext
Expand Down Expand Up @@ -65,7 +64,7 @@ def __call__(self, event: dict, context: "LambdaContext") -> dict:
handler = AbstractHandler.from_trigger(
event, context, **self.handler_kwargs
)
http_cycle = HTTPCycle(handler.scope.as_dict())
http_cycle = HTTPCycle(handler.scope)
response = http_cycle(self.app, handler.body)

return handler.transform_response(response)
3 changes: 1 addition & 2 deletions mangum/handlers/abstract_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from abc import ABCMeta, abstractmethod
from typing import Dict, Any, TYPE_CHECKING, Tuple, List

from mangum.response import Response
from mangum.scope import Scope
from .. import Response, Scope

if TYPE_CHECKING: # pragma: no cover
from awslambdaric.lambda_context import LambdaContext
Expand Down
3 changes: 1 addition & 2 deletions mangum/handlers/aws_alb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from typing import Dict, Any

from .abstract_handler import AbstractHandler
from ..response import Response
from ..scope import Scope
from .. import Response, Scope


class AwsAlb(AbstractHandler):
Expand Down
3 changes: 1 addition & 2 deletions mangum/handlers/aws_api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from typing import Dict, Any, TYPE_CHECKING

from .abstract_handler import AbstractHandler
from ..response import Response
from ..scope import Scope
from .. import Response, Scope

if TYPE_CHECKING: # pragma: no cover
from awslambdaric.lambda_context import LambdaContext
Expand Down
3 changes: 1 addition & 2 deletions mangum/handlers/aws_cf_lambda_at_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from typing import Dict, Any, List

from .abstract_handler import AbstractHandler
from ..response import Response
from ..scope import Scope
from .. import Response, Scope


class AwsCfLambdaAtEdge(AbstractHandler):
Expand Down
3 changes: 1 addition & 2 deletions mangum/handlers/aws_http_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from typing import Dict, Any

from .abstract_handler import AbstractHandler
from ..response import Response
from ..scope import Scope
from .. import Response, Scope


class AwsHttpGateway(AbstractHandler):
Expand Down
8 changes: 8 additions & 0 deletions mangum/protocols/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .http import HTTPCycle
from .lifespan import LifespanCycleState, LifespanCycle

__all__ = [
"HTTPCycle",
"LifespanCycleState",
"LifespanCycle",
]
10 changes: 5 additions & 5 deletions mangum/protocols/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from io import BytesIO
from dataclasses import dataclass

from mangum.response import Response
from mangum.types import ASGIApp, Message, ScopeDict
from mangum.exceptions import UnexpectedMessage
from .. import Response, Scope
from ..types import ASGIApp, Message
from ..exceptions import UnexpectedMessage


class HTTPCycleState(enum.Enum):
Expand Down Expand Up @@ -44,7 +44,7 @@ class HTTPCycle:
* **response** - A dictionary containing the response data to return in AWS Lambda.
"""

scope: ScopeDict
scope: Scope
state: HTTPCycleState = HTTPCycleState.REQUEST
response: Optional[Response] = None

Expand Down Expand Up @@ -77,7 +77,7 @@ async def run(self, app: ASGIApp) -> None:
Calls the application with the `http` connection scope.
"""
try:
await app(self.scope, self.receive, self.send)
await app(self.scope.as_dict(), self.receive, self.send)
except BaseException as exc:
self.logger.error("Exception in 'http' protocol.", exc_info=exc)
if self.state is HTTPCycleState.REQUEST:
Expand Down
4 changes: 2 additions & 2 deletions mangum/protocols/lifespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import enum
from dataclasses import dataclass

from mangum.types import ASGIApp, Message
from mangum.exceptions import LifespanUnsupported, LifespanFailure, UnexpectedMessage
from ..types import ASGIApp, Message
from ..exceptions import LifespanUnsupported, LifespanFailure, UnexpectedMessage


class LifespanCycleState(enum.Enum):
Expand Down
2 changes: 1 addition & 1 deletion mangum/scope.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass, field
from typing import List, Tuple, Optional, Dict, Any, Union, TYPE_CHECKING

from mangum.types import ScopeDict
from .types import ScopeDict

if TYPE_CHECKING: # pragma: no cover
from awslambdaric.lambda_context import LambdaContext
Expand Down