applications.cpython-312.pyc•12.8 kB
�
�MMg�( � �D � 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# ejH dd�� Z% ed� Z& G d� d� Z'y)� )�annotationsN)� �
)� ParamSpec)�State�URLPath)�
Middleware�_MiddlewareFactory)�BaseHTTPMiddleware)�ServerErrorMiddleware)�ExceptionMiddleware)�Request)�Response)� BaseRoute�Router)�ASGIApp�ExceptionHandler�Lifespan�Receive�Scope�Send)� WebSocket�AppType� Starlette)�bound�Pc �L � e Zd ZdZ d dd�Zdd�Zedd�� Zdd�Zdd�Z dd�Z
ddd �Zddd
�Z dd�Z
dd�Z d d
�Z d! d"d�Z d d#d�Zd$d�Z d! d%d�Zdd&d�Zd'd�Zy)(r aC
Creates an application instance.
**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.
Nc �� � |�|�|�J d� �|| _ t � | _ t ||||�� | _ |�i n
t |� | _ |�g n
t |� | _ d | _ y )Nz>Use either 'lifespan' or 'on_startup'/'on_shutdown', not both.)�
on_startup�on_shutdown�lifespan)
�debugr �stater �router�dict�exception_handlers�list�user_middleware�middleware_stack)�selfr"