-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Follow spec * Update type hint for exc_info parameter in StartResponse class * Add REMOTE_PORT to test_build_environ() and test_build_environ_with_env() functions
- Loading branch information
1 parent
7f4297c
commit 3b17409
Showing
6 changed files
with
443 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
""" | ||
https://asgi.readthedocs.io/en/latest/specs/index.html | ||
""" | ||
import sys | ||
from typing import ( | ||
Any, | ||
Awaitable, | ||
Callable, | ||
Dict, | ||
Iterable, | ||
Literal, | ||
Optional, | ||
Tuple, | ||
TypedDict, | ||
Union, | ||
) | ||
|
||
if sys.version_info >= (3, 11): | ||
from typing import NotRequired | ||
else: | ||
from typing_extensions import NotRequired | ||
|
||
|
||
class ASGIVersions(TypedDict): | ||
spec_version: str | ||
version: Literal["3.0"] | ||
|
||
|
||
class HTTPScope(TypedDict): | ||
type: Literal["http"] | ||
asgi: ASGIVersions | ||
http_version: str | ||
method: str | ||
scheme: str | ||
path: str | ||
raw_path: NotRequired[bytes] | ||
query_string: bytes | ||
root_path: str | ||
headers: Iterable[Tuple[bytes, bytes]] | ||
client: NotRequired[Tuple[str, int]] | ||
server: NotRequired[Tuple[str, Optional[int]]] | ||
state: NotRequired[Dict[str, Any]] | ||
extensions: NotRequired[Dict[str, Dict[object, object]]] | ||
|
||
|
||
class WebSocketScope(TypedDict): | ||
type: Literal["websocket"] | ||
asgi: ASGIVersions | ||
http_version: str | ||
scheme: str | ||
path: str | ||
raw_path: bytes | ||
query_string: bytes | ||
root_path: str | ||
headers: Iterable[Tuple[bytes, bytes]] | ||
client: NotRequired[Tuple[str, int]] | ||
server: NotRequired[Tuple[str, Optional[int]]] | ||
subprotocols: Iterable[str] | ||
state: NotRequired[Dict[str, Any]] | ||
extensions: NotRequired[Dict[str, Dict[object, object]]] | ||
|
||
|
||
class LifespanScope(TypedDict): | ||
type: Literal["lifespan"] | ||
asgi: ASGIVersions | ||
state: NotRequired[Dict[str, Any]] | ||
|
||
|
||
WWWScope = Union[HTTPScope, WebSocketScope] | ||
Scope = Union[HTTPScope, WebSocketScope, LifespanScope] | ||
|
||
|
||
class HTTPRequestEvent(TypedDict): | ||
type: Literal["http.request"] | ||
body: bytes | ||
more_body: NotRequired[bool] | ||
|
||
|
||
class HTTPResponseStartEvent(TypedDict): | ||
type: Literal["http.response.start"] | ||
status: int | ||
headers: NotRequired[Iterable[Tuple[bytes, bytes]]] | ||
trailers: NotRequired[bool] | ||
|
||
|
||
class HTTPResponseBodyEvent(TypedDict): | ||
type: Literal["http.response.body"] | ||
body: NotRequired[bytes] | ||
more_body: NotRequired[bool] | ||
|
||
|
||
class HTTPDisconnectEvent(TypedDict): | ||
type: Literal["http.disconnect"] | ||
|
||
|
||
class WebSocketConnectEvent(TypedDict): | ||
type: Literal["websocket.connect"] | ||
|
||
|
||
class WebSocketAcceptEvent(TypedDict): | ||
type: Literal["websocket.accept"] | ||
subprotocol: NotRequired[str] | ||
headers: NotRequired[Iterable[Tuple[bytes, bytes]]] | ||
|
||
|
||
class WebSocketReceiveEvent(TypedDict): | ||
type: Literal["websocket.receive"] | ||
bytes: NotRequired[bytes] | ||
text: NotRequired[str] | ||
|
||
|
||
class WebSocketSendEvent(TypedDict): | ||
type: Literal["websocket.send"] | ||
bytes: NotRequired[bytes] | ||
text: NotRequired[str] | ||
|
||
|
||
class WebSocketDisconnectEvent(TypedDict): | ||
type: Literal["websocket.disconnect"] | ||
code: int | ||
|
||
|
||
class WebSocketCloseEvent(TypedDict): | ||
type: Literal["websocket.close"] | ||
code: NotRequired[int] | ||
reason: NotRequired[str] | ||
|
||
|
||
class LifespanStartupEvent(TypedDict): | ||
type: Literal["lifespan.startup"] | ||
|
||
|
||
class LifespanShutdownEvent(TypedDict): | ||
type: Literal["lifespan.shutdown"] | ||
|
||
|
||
class LifespanStartupCompleteEvent(TypedDict): | ||
type: Literal["lifespan.startup.complete"] | ||
|
||
|
||
class LifespanStartupFailedEvent(TypedDict): | ||
type: Literal["lifespan.startup.failed"] | ||
message: str | ||
|
||
|
||
class LifespanShutdownCompleteEvent(TypedDict): | ||
type: Literal["lifespan.shutdown.complete"] | ||
|
||
|
||
class LifespanShutdownFailedEvent(TypedDict): | ||
type: Literal["lifespan.shutdown.failed"] | ||
message: str | ||
|
||
|
||
ReceiveEvent = Union[ | ||
HTTPRequestEvent, | ||
HTTPDisconnectEvent, | ||
WebSocketConnectEvent, | ||
WebSocketReceiveEvent, | ||
WebSocketDisconnectEvent, | ||
LifespanStartupEvent, | ||
LifespanShutdownEvent, | ||
] | ||
|
||
SendEvent = Union[ | ||
HTTPResponseStartEvent, | ||
HTTPResponseBodyEvent, | ||
HTTPDisconnectEvent, | ||
WebSocketAcceptEvent, | ||
WebSocketSendEvent, | ||
WebSocketCloseEvent, | ||
LifespanStartupCompleteEvent, | ||
LifespanStartupFailedEvent, | ||
LifespanShutdownCompleteEvent, | ||
LifespanShutdownFailedEvent, | ||
] | ||
|
||
Receive = Callable[[], Awaitable[ReceiveEvent]] | ||
|
||
Send = Callable[[SendEvent], Awaitable[None]] | ||
|
||
ASGIApp = Callable[[Scope, Receive, Send], Awaitable[None]] |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.