Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

typing.py 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import sys
  2. from typing import Awaitable, Callable, Dict, Iterable, Optional, Tuple, Type, Union
  3. if sys.version_info >= (3, 8):
  4. from typing import Literal, Protocol, TypedDict
  5. else:
  6. from typing_extensions import Literal, Protocol, TypedDict
  7. __all__ = (
  8. "ASGIVersions",
  9. "HTTPScope",
  10. "WebSocketScope",
  11. "LifespanScope",
  12. "WWWScope",
  13. "Scope",
  14. "HTTPRequestEvent",
  15. "HTTPResponseStartEvent",
  16. "HTTPResponseBodyEvent",
  17. "HTTPResponseTrailersEvent",
  18. "HTTPServerPushEvent",
  19. "HTTPDisconnectEvent",
  20. "WebSocketConnectEvent",
  21. "WebSocketAcceptEvent",
  22. "WebSocketReceiveEvent",
  23. "WebSocketSendEvent",
  24. "WebSocketResponseStartEvent",
  25. "WebSocketResponseBodyEvent",
  26. "WebSocketDisconnectEvent",
  27. "WebSocketCloseEvent",
  28. "LifespanStartupEvent",
  29. "LifespanShutdownEvent",
  30. "LifespanStartupCompleteEvent",
  31. "LifespanStartupFailedEvent",
  32. "LifespanShutdownCompleteEvent",
  33. "LifespanShutdownFailedEvent",
  34. "ASGIReceiveEvent",
  35. "ASGISendEvent",
  36. "ASGIReceiveCallable",
  37. "ASGISendCallable",
  38. "ASGI2Protocol",
  39. "ASGI2Application",
  40. "ASGI3Application",
  41. "ASGIApplication",
  42. )
  43. class ASGIVersions(TypedDict):
  44. spec_version: str
  45. version: Union[Literal["2.0"], Literal["3.0"]]
  46. class HTTPScope(TypedDict):
  47. type: Literal["http"]
  48. asgi: ASGIVersions
  49. http_version: str
  50. method: str
  51. scheme: str
  52. path: str
  53. raw_path: bytes
  54. query_string: bytes
  55. root_path: str
  56. headers: Iterable[Tuple[bytes, bytes]]
  57. client: Optional[Tuple[str, int]]
  58. server: Optional[Tuple[str, Optional[int]]]
  59. extensions: Optional[Dict[str, Dict[object, object]]]
  60. class WebSocketScope(TypedDict):
  61. type: Literal["websocket"]
  62. asgi: ASGIVersions
  63. http_version: str
  64. scheme: str
  65. path: str
  66. raw_path: bytes
  67. query_string: bytes
  68. root_path: str
  69. headers: Iterable[Tuple[bytes, bytes]]
  70. client: Optional[Tuple[str, int]]
  71. server: Optional[Tuple[str, Optional[int]]]
  72. subprotocols: Iterable[str]
  73. extensions: Optional[Dict[str, Dict[object, object]]]
  74. class LifespanScope(TypedDict):
  75. type: Literal["lifespan"]
  76. asgi: ASGIVersions
  77. WWWScope = Union[HTTPScope, WebSocketScope]
  78. Scope = Union[HTTPScope, WebSocketScope, LifespanScope]
  79. class HTTPRequestEvent(TypedDict):
  80. type: Literal["http.request"]
  81. body: bytes
  82. more_body: bool
  83. class HTTPResponseStartEvent(TypedDict):
  84. type: Literal["http.response.start"]
  85. status: int
  86. headers: Iterable[Tuple[bytes, bytes]]
  87. trailers: bool
  88. class HTTPResponseBodyEvent(TypedDict):
  89. type: Literal["http.response.body"]
  90. body: bytes
  91. more_body: bool
  92. class HTTPResponseTrailersEvent(TypedDict):
  93. type: Literal["http.response.trailers"]
  94. headers: Iterable[Tuple[bytes, bytes]]
  95. more_trailers: bool
  96. class HTTPServerPushEvent(TypedDict):
  97. type: Literal["http.response.push"]
  98. path: str
  99. headers: Iterable[Tuple[bytes, bytes]]
  100. class HTTPDisconnectEvent(TypedDict):
  101. type: Literal["http.disconnect"]
  102. class WebSocketConnectEvent(TypedDict):
  103. type: Literal["websocket.connect"]
  104. class WebSocketAcceptEvent(TypedDict):
  105. type: Literal["websocket.accept"]
  106. subprotocol: Optional[str]
  107. headers: Iterable[Tuple[bytes, bytes]]
  108. class WebSocketReceiveEvent(TypedDict):
  109. type: Literal["websocket.receive"]
  110. bytes: Optional[bytes]
  111. text: Optional[str]
  112. class WebSocketSendEvent(TypedDict):
  113. type: Literal["websocket.send"]
  114. bytes: Optional[bytes]
  115. text: Optional[str]
  116. class WebSocketResponseStartEvent(TypedDict):
  117. type: Literal["websocket.http.response.start"]
  118. status: int
  119. headers: Iterable[Tuple[bytes, bytes]]
  120. class WebSocketResponseBodyEvent(TypedDict):
  121. type: Literal["websocket.http.response.body"]
  122. body: bytes
  123. more_body: bool
  124. class WebSocketDisconnectEvent(TypedDict):
  125. type: Literal["websocket.disconnect"]
  126. code: int
  127. class WebSocketCloseEvent(TypedDict):
  128. type: Literal["websocket.close"]
  129. code: int
  130. reason: Optional[str]
  131. class LifespanStartupEvent(TypedDict):
  132. type: Literal["lifespan.startup"]
  133. class LifespanShutdownEvent(TypedDict):
  134. type: Literal["lifespan.shutdown"]
  135. class LifespanStartupCompleteEvent(TypedDict):
  136. type: Literal["lifespan.startup.complete"]
  137. class LifespanStartupFailedEvent(TypedDict):
  138. type: Literal["lifespan.startup.failed"]
  139. message: str
  140. class LifespanShutdownCompleteEvent(TypedDict):
  141. type: Literal["lifespan.shutdown.complete"]
  142. class LifespanShutdownFailedEvent(TypedDict):
  143. type: Literal["lifespan.shutdown.failed"]
  144. message: str
  145. ASGIReceiveEvent = Union[
  146. HTTPRequestEvent,
  147. HTTPDisconnectEvent,
  148. WebSocketConnectEvent,
  149. WebSocketReceiveEvent,
  150. WebSocketDisconnectEvent,
  151. LifespanStartupEvent,
  152. LifespanShutdownEvent,
  153. ]
  154. ASGISendEvent = Union[
  155. HTTPResponseStartEvent,
  156. HTTPResponseBodyEvent,
  157. HTTPResponseTrailersEvent,
  158. HTTPServerPushEvent,
  159. HTTPDisconnectEvent,
  160. WebSocketAcceptEvent,
  161. WebSocketSendEvent,
  162. WebSocketResponseStartEvent,
  163. WebSocketResponseBodyEvent,
  164. WebSocketCloseEvent,
  165. LifespanStartupCompleteEvent,
  166. LifespanStartupFailedEvent,
  167. LifespanShutdownCompleteEvent,
  168. LifespanShutdownFailedEvent,
  169. ]
  170. ASGIReceiveCallable = Callable[[], Awaitable[ASGIReceiveEvent]]
  171. ASGISendCallable = Callable[[ASGISendEvent], Awaitable[None]]
  172. class ASGI2Protocol(Protocol):
  173. def __init__(self, scope: Scope) -> None:
  174. ...
  175. async def __call__(
  176. self, receive: ASGIReceiveCallable, send: ASGISendCallable
  177. ) -> None:
  178. ...
  179. ASGI2Application = Type[ASGI2Protocol]
  180. ASGI3Application = Callable[
  181. [
  182. Scope,
  183. ASGIReceiveCallable,
  184. ASGISendCallable,
  185. ],
  186. Awaitable[None],
  187. ]
  188. ASGIApplication = Union[ASGI2Application, ASGI3Application]