U
    ²@Ûf¶  ã                   @   s8   d dl Z d dlmZ G dd„ deƒZG dd„ deƒZdS )é    N)Úget_static_filec                   @   s*   e Zd ZdZd
dd„Zdd„ Zdd	„ ZdS )Ú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)
    Nú	engine.ioc                 C   sR   || _ || _|| _| j d¡s*d| j | _| j d¡sD|  jd7  _|pJi | _d S )Nú/)Úengineio_appÚwsgi_appÚengineio_pathÚ
startswithÚendswithÚstatic_files)Úselfr   r   r   r   © r   úM/var/www/html/chatgpt/venv/lib/python3.8/site-packages/engineio/middleware.pyÚ__init__"   s    zWSGIApp.__init__c              
   C   sÞ   d|kr(G dd„ dt ƒ}||d ƒ|d< |d }|d k	rR| | j¡rR| j ||¡S | jrdt|| jƒnd }|r¾tj 	|d ¡r¾|dd|d	 fgƒ t
|d d
ƒ�}| ¡ gW  5 Q R £ S Q R X n| jd k	rÔ|  ||¡S |  |¡S )Nzgunicorn.socketc                   @   s   e Zd Zdd„ Zdd„ ZdS )zWSGIApp.__call__.<locals>.Inputc                 S   s
   || _ d S ©N©Úsocket)r   r   r   r   r   r   6   s    z(WSGIApp.__call__.<locals>.Input.__init__c                 S   s   | j S r   r   )r   r   r   r   Ú
get_socket9   s    z*WSGIApp.__call__.<locals>.Input.get_socketN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   ÚInput5   s   r   zeventlet.inputZ	PATH_INFOÚfilenamez200 OKúContent-TypeÚcontent_typeÚrb)Úobjectr	   r   r   Úhandle_requestr   r   ÚosÚpathÚexistsÚopenÚreadr   Ú	not_found)r   ÚenvironÚstart_responser   r   Zstatic_fileÚfr   r   r   Ú__call__-   s(    ÿÿþ
zWSGIApp.__call__c                 C   s   |ddgƒ dgS )Nz404 Not Found)r   z
text/plains	   Not Foundr   )r   r%   r   r   r   r#   M   s    zWSGIApp.not_found)NNr   )r   r   r   Ú__doc__r   r'   r#   r   r   r   r   r      s     ÿ
 r   c                       s"   e Zd ZdZd‡ fdd„	Z‡  ZS )Ú
MiddlewarezAThis class has been renamed to ``WSGIApp`` and is now deprecated.Nr   c                    s   t ƒ j|||d� d S )N)r   )Úsuperr   )r   r   r   r   ©Ú	__class__r   r   r   T   s    zMiddleware.__init__)Nr   )r   r   r   r(   r   Ú__classcell__r   r   r+   r   r)   R   s     ÿr)   )r   Zengineio.static_filesr   r   r   r)   r   r   r   r   Ú<module>   s   M