
    wg                     B    d dl Z d dlmZ  G d d      Z G d de      Zy)    N)get_static_filec                   (    e Zd ZdZ	 	 ddZd Zd Zy)WSGIAppa  WSGI application middleware for Engine.IO.

    This middleware dispatches traffic to an Engine.IO application. It can
    also serve a list of static files to the client, or forward unrelated
    HTTP traffic to another WSGI application.

    :param engineio_app: The Engine.IO server. Must be an instance of the
                         ``engineio.Server`` class.
    :param wsgi_app: The WSGI app that receives all other traffic.
    :param static_files: A dictionary with static file mapping rules. See the
                         documentation for details on this argument.
    :param engineio_path: The endpoint where the Engine.IO application should
                          be installed. The default value is appropriate for
                          most cases.

    Example usage::

        import engineio
        import eventlet

        eio = engineio.Server()
        app = engineio.WSGIApp(eio, static_files={
            '/': {'content_type': 'text/html', 'filename': 'index.html'},
            '/index.html': {'content_type': 'text/html',
                            'filename': 'index.html'},
        })
        eventlet.wsgi.server(eventlet.listen(('', 8000)), app)
    Nc                    || _         || _        || _        | j                  j                  d      sd| j                  z   | _        | j                  j	                  d      s| xj                  dz  c_        |xs i | _        y )N/)engineio_appwsgi_appengineio_path
startswithendswithstatic_files)selfr   r	   r   r
   s        X/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/engineio/middleware.py__init__zWSGIApp.__init__"   sr    ( *!!,,S1!$t'9'9!9D!!**3/#%(.B    c                 .   d|v r G d d      } ||d         |d<   |d   }|7|j                  | j                        r| j                  j                  ||      S | j                  rt        || j                        nd }|r[t        j                  j                  |d         r9 |dd|d	   fg       t        |d   d
      5 }|j                         gcd d d        S | j                  | j                  ||      S | j                  |      S # 1 sw Y   xY w)Nzgunicorn.socketc                       e Zd Zd Zd Zy)WSGIApp.__call__.<locals>.Inputc                     || _         y Nsocket)r   r   s     r   r   z(WSGIApp.__call__.<locals>.Input.__init__6   s	    "(DKr   c                     | j                   S r   r   )r   s    r   
get_socketz*WSGIApp.__call__.<locals>.Input.get_socket9   s    ;;&r   N)__name__
__module____qualname__r   r    r   r   Inputr   5   s    )'r   r   zeventlet.input	PATH_INFOfilenamez200 OKContent-Typecontent_typerb)r   r
   r   handle_requestr   r   ospathexistsopenreadr	   	not_found)r   environstart_responser   r'   static_filefs          r   __call__zWSGIApp.__call__-   s    '' ' ).g6G.H(IG$%{#0B0B C$$33G^LL $$ *$0A0AB*. rww~~k*.EF$k.&ABCE +j148 &AFFH:& &*}}Wn==~~n--	& &s   DDc                      |ddg       dgS )Nz404 Not Found)r"   z
text/plains	   Not Foundr   )r   r-   s     r   r+   zWSGIApp.not_foundM   s    )G(HI~r   )NN	engine.io)r   r   r   __doc__r   r0   r+   r   r   r   r   r      s!    8 BF*	/.@r   r   c                   (     e Zd ZdZ	 	 d fd	Z xZS )
MiddlewarezAThis class has been renamed to ``WSGIApp`` and is now deprecated.c                 *    t         |   |||       y )N)r
   )superr   )r   r   r	   r
   	__class__s       r   r   zMiddleware.__init__T   s    x}Mr   )Nr2   )r   r   r   r3   r   __classcell__)r8   s   @r   r5   r5   R   s    K.2*N Nr   r5   )r&   engineio.static_filesr   r   r5   r   r   r   <module>r;      s&    	 1J JZN Nr   