o
    ¨Ýj’  ã                   @   s¦   d dl Z d dl mZ d dlmZ zd dlZdZW n ey'   d dlmZ Y nw G dd„ de jƒZ	edur>G dd„ deƒZ
nG d	d„ dƒZ
e	ejejee
e jd
œZdS )é    N)Úqueue)ÚEvent)ÚSimpleWebSocketWSGIc                       s.   e Zd ZdZg i f‡ fdd„	Zdd„ Z‡  ZS )ÚThreadz€
    This wrapper class provides gevent Greenlet interface that is compatible
    with the standard library's Thread class.
    c                    s   t ƒ j|g|¢R i |¤Ž d S ©N)ÚsuperÚ__init__)ÚselfÚtargetÚargsÚkwargs©Ú	__class__© úX/var/www/html/chatgpt/venv/lib/python3.10/site-packages/engineio/async_drivers/gevent.pyr      s   zThread.__init__c                 C   s   |   ¡ S r   )Úrun©r	   r   r   r   Ú_run   s   zThread._run)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__classcell__r   r   r   r   r      s    r   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚWebSocketWSGIz±
        This wrapper class provides a gevent WebSocket interface that is
        compatible with eventlet's implementation, using the simple-websocket
        package.
        c                    s2   dd l }dd l}tƒ j||t|jj|jjd� d S )Nr   )Zthread_classZevent_classZselector_class)	Úgevent.eventZgevent.selectorsr   r   r   Úeventr   Ú	selectorsÚDefaultSelector)r	   ÚhandlerÚserverÚgeventr   r   r   r       s   

ýúWebSocketWSGI.__init__)r   r   r   r   r   r   r   r   r   r   r      s    r   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )r   z±
        This wrapper class provides a gevent WebSocket interface that is
        compatible with eventlet's implementation, using the gevent-websocket
        package.
        c                 C   s
   || _ d S r   )Úapp)r	   r   r   r   r   r   r   1   ó   
r!   c                 C   sR   d|vrt dƒ‚|d | _|| _| jj| _| jj| _| jj| _| jj| _|  | ¡S )Nzwsgi.websocketz‚The gevent-websocket server is not configured appropriately. See the Deployment section of the documentation for more information.)ÚRuntimeErrorÚ_sockÚenvironÚversionÚpathÚoriginÚprotocolr"   )r	   r&   Zstart_responser   r   r   Ú__call__4   s   





zWebSocketWSGI.__call__c                 C   ó
   | j  ¡ S r   )r%   Úcloser   r   r   r   r-   B   r#   zWebSocketWSGI.closec                 C   s   | j  |¡S r   )r%   Úsend)r	   Úmessager   r   r   r.   E   s   zWebSocketWSGI.sendc                 C   r,   r   )r%   Zreceiver   r   r   r   ÚwaitH   r#   zWebSocketWSGI.waitN)	r   r   r   r   r   r+   r-   r.   r0   r   r   r   r   r   +   s    )Úthreadr   Zqueue_emptyr   Z	websocketÚsleep)r    r   r   r   Zgeventwebsocketr   ÚImportErrorZ&engineio.async_drivers._websocket_wsgiZGreenletr   r   ZJoinableQueueÚEmptyr2   Z_asyncr   r   r   r   Ú<module>   s(    þ"
ú