U
    @f}                     @   s   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ ddddgZ	e
dZe Zd	Zed
d eD ZG dd deZdd ZdddZdd Zd dlmZ dddejdfddZdd Zdd ZG dd deZdS )    N)patcher)	greenletsuse_hubget_hubget_default_hub
trampoline	threading)ZepollsZkqueuepollZselectsc                 c   s   | ]}t d | V  qdS )eventlet.hubs.N)	importlibimport_module).0name r   P/var/www/html/chatgpt/venv/lib/python3.8/site-packages/eventlet/hubs/__init__.py	<genexpr>   s     r   c                   @   s   e Zd ZdS )HubErrorN__name__
__module____qualname__r   r   r   r   r      s   r   c                  C   s,   t D ]} |  r|   S qtdt dS )a  Select the default hub implementation based on what multiplexing
    libraries are installed.  The order that the hubs are tried is:

    * epoll
    * kqueue
    * poll
    * select

    .. include:: ../../doc/source/common.txt
    .. note :: |internal|
    z"no built-in hubs are available: {}N)builtin_hub_modulesis_availabler   formatmodr   r   r   r      s    
c                 C   s   | dkrt jdd} | dkr$t } ttdr2t`d}t| tr| 	 dkrTt
dd| ksdd| krz| 	 d\}}}nd|  }t|} t| d	r|  std
| ndj| d}tj|tdd | }t| st| |pd}|t_dS )a  Use the module *mod*, containing a class called Hub, as the
    event hub. Usually not required; the default hub is usually fine.

    `mod` can be an actual hub class, a module, a string, or None.

    If `mod` is a class, use it directly.
    If `mod` is a module, use `module.Hub` class
    If `mod` is a string and contains either '.' or ':'
    then `use_hub` uses 'package.subpackage.module:Class' convention,
    otherwise imports `eventlet.hubs.mod`.
    If `mod` is None, `use_hub` uses the default hub.

    Only call use_hub during application initialization,
    because it resets the hub's state and any existing
    timers or listeners will never be resumed.

    These two threadlocal attributes are not part of Eventlet public API:
    - `threadlocal.Hub` (capital H) is hub constructor, used when no hub is currently active
    - `threadlocal.hub` (lowercase h) is active hub instance
    NZEVENTLET_HUBhub zNeed to specify a hub.:r
   r   z3selected hub is not available on this system mod={}zPlease provide `is_available()` function in your custom Eventlet hub {mod}.
It must return bool: whether hub supports current platform. See eventlet/hubs/{{epoll,kqueue}} for example.
r      )
stacklevelHub)osenvirongetr   hasattr_threadlocalr   
isinstancestrstripRuntimeError	partitionr   r   r   	Exceptionr   warningswarnDeprecationWarninginspectisclassgetattrr"   )r   	classname
modulename_msgZhubclassr   r   r   r   ,   s2    




c                  C   sX   z
t j} W nH tk
rR   z
t j W n tk
r>   t  Y nX t   } t _Y nX | S )zKGet the current event hub singleton object.

    .. note :: |internal|
    )r'   r   AttributeErrorr"   r   )r   r   r   r   r   b   s    

)timeoutc              	      s   d}t  }t  |j kr$td|r4|r4tdz|  }W n tk
rX   | }Y nX |dk	r| fdd}	|||	|}z\|r||j	| j
 j|}
n|r||j| j
 j|}
z|
 W W S ||
 X W 5 |dk	r|  X dS )a<  Suspend the current coroutine until the given socket object or file
    descriptor is ready to *read*, ready to *write*, or the specified
    *timeout* elapses, depending on arguments specified.

    To wait for *fd* to be ready to read, pass *read* ``=True``; ready to
    write, pass *write* ``=True``. To specify a timeout, pass the *timeout*
    argument in seconds.

    If the specified *timeout* elapses before the socket is ready to read or
    write, *timeout_exc* will be raised instead of ``trampoline()``
    returning normally.

    .. note :: |internal|
    Nz0do not call blocking functions from the mainloopz1not allowed to trampoline for reading and writingc                    s     |  d S )N)throw)exccurrentr   r   _timeout   s    ztrampoline.<locals>._timeout)r   greenletZ
getcurrentr+   filenor8   Zschedule_call_globalcanceladdREADswitchr:   WRITEremove)fdreadwriter9   Ztimeout_excZmark_as_closedtr   r@   r>   Zlistenerr   r<   r   r   v   s0    

c                 C   s   t  }||  dS )z
    A particular file descriptor has been explicitly closed. Register for any
    waiting listeners to be notified on the next run loop.
    N)r   notify_closerG   r   r   r   r   rK      s    rK   c                 C   s   t  }||  dS )a  
    Some file descriptors may be closed 'silently' - that is, by the garbage
    collector, by an external library, etc. When the OS returns a file descriptor
    from an open call (or something similar), this may be the only indication we
    have that the FD has been closed and then recycled.
    We let the hub know that the old file descriptor is dead; any stuck listeners
    will be disabled and notified in turn.
    N)r   Zmark_as_reopenedrL   r   r   r   notify_opened   s    	rM   c                   @   s   e Zd ZdS )IOClosedNr   r   r   r   r   rN      s   rN   )N)r   r1   r#   r.   Zeventletr   Zeventlet.supportr   r?   __all__originalr   localr'   Zbuiltin_hub_namestupler   r-   r   r   r   r   r9   Timeoutr   rK   rM   IOErrorrN   r   r   r   r   <module>   s,   

6
/	