a
    Nf*
                     @  sT   d Z ddlmZ ddlZejrBddlmZ ddlmZ ddlm	Z	 G dd dZ
dS )	aY  
Application Dispatcher
======================

This middleware creates a single WSGI application that dispatches to
multiple other WSGI applications mounted at different URL paths.

A common example is writing a Single Page Application, where you have a
backend API and a frontend written in JavaScript that does the routing
in the browser rather than requesting different pages from the server.
The frontend is a single HTML and JS file that should be served for any
path besides "/api".

This example dispatches to an API app under "/api", an admin app
under "/admin", and an app that serves frontend files for all other
requests::

    app = DispatcherMiddleware(serve_frontend, {
        '/api': api_app,
        '/admin': admin_app,
    })

In production, you might instead handle this at the HTTP server level,
serving files or proxying to application servers based on location. The
API and admin apps would each be deployed with a separate WSGI server,
and the static files would be served directly by the HTTP server.

.. autoclass:: DispatcherMiddleware

:copyright: 2007 Pallets
:license: BSD-3-Clause
    )annotationsN)StartResponse)WSGIApplication)WSGIEnvironmentc                   @  s6   e Zd ZdZdddddddZd	d
ddddZdS )DispatcherMiddlewareaJ  Combine multiple applications as a single WSGI application.
    Requests are dispatched to an application based on the path it is
    mounted under.

    :param app: The WSGI application to dispatch to if the request
        doesn't match a mounted path.
    :param mounts: Maps path prefixes to applications for dispatching.
    Nr   z!dict[str, WSGIApplication] | NoneNone)appmountsreturnc                 C  s   || _ |pi | _d S )N)r   r	   )selfr   r	    r   W/var/www/ai-form-bot/venv/lib/python3.9/site-packages/werkzeug/middleware/dispatcher.py__init__6   s    zDispatcherMiddleware.__init__r   r   zt.Iterable[bytes])environstart_responser
   c                 C  s   | dd}d}d|v rN|| jv r.| j| }q^|dd\}}d| | }q| j || j}| dd}|| |d< ||d< |||S )NZ	PATH_INFO /   ZSCRIPT_NAME)getr	   rsplitr   )r   r   r   scriptZ	path_infor   Z	last_itemZoriginal_script_namer   r   r   __call__>   s    

zDispatcherMiddleware.__call__)N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   ,   s    r   )r   
__future__r   typingtTYPE_CHECKINGZ_typeshed.wsgir   r   r   r   r   r   r   r   <module>   s   !