�
K�g�) � �F � d dl mZ d dlZd dlZd dlZej dk rd dlmZ nd dlmZ d dlm Z m
Z
d dlmZm
Z
d dlmZ d dlmZ d d lmZ d d
lmZ d dlmZ d dlmZmZ d d
lmZmZmZmZm Z m!Z! d dl"m#Z# ej$ dd�� � Z% ed� � Z& G d� d� � Z'dS )� )�annotationsN)� �
)� ParamSpec)�State�URLPath)�
Middleware�_MiddlewareFactory)�BaseHTTPMiddleware)�ServerErrorMiddleware)�ExceptionMiddleware)�Request)�Response)� BaseRoute�Router)�ASGIApp�ExceptionHandler�Lifespan�Receive�Scope�Send)� WebSocket�AppType� Starlette)�bound�Pc �� � e Zd ZdZ dLdMd�ZdNd�ZedOd�� � ZdPd�ZdQd&�Z dRd)�Z
dSdTd-�ZdSdUd/�ZdVd6�Z
dWd;�ZdXd=�Z dYdZdD�Z dSd[dF�Zd\dG�Z dYd]dH�ZdSd^dI�Zd_dK�ZdS )`r z!Creates an Starlette application.FN�selfr �debug�bool�routes�!typing.Sequence[BaseRoute] | None�
middleware�"typing.Sequence[Middleware] | None�exception_handlers�3typing.Mapping[typing.Any, ExceptionHandler] | None�
on_startup�7typing.Sequence[typing.Callable[[], typing.Any]] | None�on_shutdown�lifespan�Lifespan[AppType] | None�return�Nonec �� � |�|�|�
J d� � �|| _ t � � | _ t ||||�� � | _ |�i nt |� � | _ |�g nt |� � | _ d| _ dS )a� Initializes the application.
Parameters:
debug: Boolean indicating if debug tracebacks should be returned on errors.
routes: A list of routes to serve incoming HTTP and WebSocket requests.
middleware: A list of middleware to run for every request. A starlette
application will always automatically include two middleware classes.
`ServerErrorMiddleware` is added as the very outermost middleware, to handle
any uncaught errors occurring anywhere in the entire stack.
`ExceptionMiddleware` is added as the very innermost middleware, to deal
with handled exception cases occurring in the routing or endpoints.
exception_handlers: A mapping of either integer status codes,
or exception class types onto callables which handle the exceptions.
Exception handler callables should be of the form
`handler(request, exc) -> response` and may be either standard functions, or
async functions.
on_startup: A list of callables to run on application startup.
Startup handler callables do not take any arguments, and may be either
standard functions, or async functions.
on_shutdown: A list of callables to run on application shutdown.
Shutdown handler callables do not take any arguments, and may be either
standard functions, or async functions.
lifespan: A lifespan context function, which can be used to perform
startup and shutdown tasks. This is a newer style that replaces the
`on_startup` and `on_shutdown` handlers. Use one or the other, not both.
Nz>Use either 'lifespan' or 'on_startup'/'on_shutdown', not both.)r'