
    <|h6                        d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 dd	l	mZ dd
lmZ ddlmZ ddlmZ  ed      j(                   e       d<   d  e       d<   ej,                   e       d<   ej.                   e       d<   e
j0                   e       d<   g dZ G d de      Z G d de      Zd%dZd&dZea d Z!d Z"d'dZ#dedfdZ$defdZ%deefd Z&deefd!Z'd" Z( e(        dd#lm)Z)  e) e*       d$       y)(z{
A collection of primitives used by the hub, and suitable for
compilation with Cython because of their frequency of use.


    )absolute_import)division)print_functionN)InvalidSwitchError)ConcurrentObjectUseError)_greenlet_primitives)_waiter)_NONE)get_hub_noargs)Timeoutgreenlet
getcurrentc                       y N r       U/var/www/html/test/engine/venv/lib/python3.12/site-packages/gevent/_hub_primitives.py<lambda>r      s    r   greenlet_initWaiterMultipleWaiterSwitchOutGreenletWithLoop)WaitOperationsGreenletiwait_on_objectswait_on_objects	wait_read
wait_writewait_readwritec                   ,    e Zd Zd Zd Zd ZddZd Zy)r   c                    t        |       }|j                  |j                  |       	 |j                         }||ur#t	        dt               d|d|d| d|d      	 |j                          y# |j                          w xY w)z
        Wait until the *watcher* (which must not be started) is ready.

        The current greenlet will be unscheduled during this time.
        zInvalid switch into z: got z (expected z; waiting on z with )N)r   startswitchgetr   r   stop)selfwatcherwaiterresults       r   waitzWaitOperationsGreenlet.wait.   st     fmmV,	ZZ\FV#("  $ LLNGLLNs   7A2 2Bc                     g }|D ]3  }||j                   |j                          #|j                  |       5 |r*| j                  j	                  | j
                  ||||       y  ||  y r   )callbackcloseappendlooprun_callback_cancel_waits_then)r&   watchersexc_kindthen	then_argsdeferredr'   s          r   cancel_waits_close_and_thenz2WaitOperationsGreenlet.cancel_waits_close_and_thenE   sn     	)G'(	) II""4#:#:HhPTV_`)r   c                 B    |D ]  }| j                  ||d         ||  y )NT)_cancel_wait)r&   r2   r3   r4   r5   r'   s         r   r1   z)WaitOperationsGreenlet._cancel_waits_thenS   s+     	7Ggx6	7ir   c                     |y|j                   )| j                  j                  | j                  |||       y|r|j	                          yy)a  
        Cancel an in-progress call to :meth:`wait` by throwing the given *error*
        in the waiting greenlet.

        .. versionchanged:: 1.3a1
           Added the *close_watcher* parameter. If true, the watcher
           will be closed after the exception is thrown. The watcher should then
           be discarded. Closing the watcher is important to release native resources.
        .. versionchanged:: 1.3a2
           Allow the *watcher* to be ``None``. No action is taken in that case.

        N)r,   r/   r0   r9   r-   )r&   r'   errorclose_watchers       r   cancel_waitz"WaitOperationsGreenlet.cancel_waitX   sL     ? 'II""4#4#4gumTMMO r   c                     |j                   }|j                  }|r|j                          |r"t        |dd       }||j	                  |       y y y )N__self__)activer,   r-   getattrthrow)r&   r'   r;   r<   r@   cbglets          r   r9   z#WaitOperationsGreenlet._cancel_waitq   sQ     MMO2z40D

5!   r   N)F)__name__
__module____qualname__r*   r7   r1   r=   r9   r   r   r   r   r   ,   s    .
2"r   r   c                   :    e Zd Zd Zd Zd Zd ZeZd Zd Z	d Z
y)	_WaitIteratorc                     || _         t        |      | _        | j                  j                  | _        || _        || _        d | _        d| _        |t        |      | _        y t        |t        |            | _        y )NF)_hubr   r	   r#   _switch_timeout_objects_timer_begunlenmin_count)r&   objectshubtimeoutcounts        r   __init__z_WaitIterator.__init__   sd    	%c*||**
 ',mc'lUCL9Qr   c                 V   | j                   ry d| _         | j                  D ]  }|j                  | j                          | j                  ]| j
                  j                  j                  | j                  d      | _        | j                  j                  | j                  |        y y )NT)priority)
rP   rN   rawlinkrL   rM   rK   r/   timerrO   r"   )r&   objs     r   _beginz_WaitIterator._begin   s    ;; == 	&CKK%	& ==$))....t}}r.JDKKKdllD1 %r   c                     | S r   r   r&   s    r   __iter__z_WaitIterator.__iter__       r   c                 t   | j                          | j                  dk(  r| j                          t               | xj                  dz  c_        	 | j                  j                         }| j                  j                          || u r| j                          t               |S #  | j                           xY w)Nr      )r_   rS   _cleanupStopIterationr	   r$   clear)r&   items     r   __next__z_WaitIterator.__next__   s    ;;!MMO/!q
	<<##%DLL t|#o%K	MMOs   AB$ $B7c                    | j                   !| j                   j                          d | _         | j                  }d| _        |D ]%  }t        |dd       }|	  || j                         ' y #  t        j                          Y AxY w)Nr   unlink)rO   r-   rN   rA   rL   	traceback	print_exc)r&   objsaobjrl   s       r   rf   z_WaitIterator._cleanup   sz    ;;"KKDK}} 	*DT8T2F!*4<<(		*
*'')s   A,,Bc                     | S r   r   ra   s    r   	__enter__z_WaitIterator.__enter__   rc   r   c                 $    | j                          y r   )rf   )r&   typvaluetbs       r   __exit__z_WaitIterator.__exit__   s    r   N)rE   rF   rG   rX   r_   rb   rj   nextrf   rr   rw   r   r   r   rI   rI      s-    R2* D*r   rI   c                 \    t               }| |j                  |      gS t        | |||      S )a  
    Iteratively yield *objects* as they are ready, until all (or *count*) are ready
    or *timeout* expired.

    If you will only be consuming a portion of the *objects*, you should
    do so inside a ``with`` block on this object to avoid leaking resources::

        with gevent.iwait((a, b, c)) as it:
            for i in it:
                if i is a:
                    break

    :param objects: A sequence (supporting :func:`len`) containing objects
        implementing the wait protocol (rawlink() and unlink()).
    :keyword int count: If not `None`, then a number specifying the maximum number
        of objects to wait for. If ``None`` (the default), all objects
        are waited for.
    :keyword float timeout: If given, specifies a maximum number of seconds
        to wait. If the timeout expires before the desired waited-for objects
        are available, then this method returns immediately.

    .. seealso:: :func:`wait`

    .. versionchanged:: 1.1a1
       Add the *count* parameter.
    .. versionchanged:: 1.1a2
       No longer raise :exc:`LoopExit` if our caller switches greenlets
       in between items yielded by this function.
    .. versionchanged:: 1.4
       Add support to use the returned object as a context manager.
    rV   )get_hubjoinrI   rT   rV   rW   rU   s       r   r   r      s6    B )C)**#w66r   c                 j    | t               }|j                  |      S t        t        | ||            S )af  
    Wait for *objects* to become ready or for event loop to finish.

    If *objects* is provided, it must be a list containing objects
    implementing the wait protocol (rawlink() and unlink() methods):

    - :class:`gevent.Greenlet` instance
    - :class:`gevent.event.Event` instance
    - :class:`gevent.lock.Semaphore` instance
    - :class:`gevent.subprocess.Popen` instance

    If *objects* is ``None`` (the default), ``wait()`` blocks until
    the current event loop has nothing to do (or until *timeout* passes):

    - all greenlets have finished
    - all servers were stopped
    - all event loop watchers were stopped.

    If *count* is ``None`` (the default), wait for all *objects*
    to become ready.

    If *count* is a number, wait for (up to) *count* objects to become
    ready. (For example, if count is ``1`` then the function exits
    when any object in the list is ready).

    If *timeout* is provided, it specifies the maximum number of
    seconds ``wait()`` will block.

    Returns the list of ready objects, in the order in which they were
    ready.

    .. seealso:: :func:`iwait`
    rz   )r{   r|   listr   r}   s       r   r   r      s7    D ixxx(( '59::r   c                     | a y r   )_timeout_error)es    r   set_default_timeout_errorr   #  s    Nr   c                 2   | j                   t        d| j                         |
t               }||j                  |        y t	        j
                  ||t        us||n
t        d            }|5  |j                  |        d d d        y # 1 sw Y   y xY w)Nz1This socket is already used by another greenlet: z	timed out)r,   r   r{   r*   r   _start_new_or_dummyr
   r   r'   rV   timeout_excrU   s       r   _primitive_waitr   '  s    #&*1*:*:(> ? 	? {i))u$ 
[)	,G 
   s   2BBc                 v    | |t        d      t        || j                  ||nt        | j                         y )Nz6The socket has already been closed by another greenlet)r   r   rV   r
   rU   )socketr'   r   s      r   wait_on_socketr   =  s:    ~ ''_``GV^^#.#:KJJ r   c                      t        | |||       y)a  
    wait(watcher, timeout=None, [timeout_exc=None]) -> None

    Block the current greenlet until *watcher* is ready.

    If *timeout* is non-negative, then *timeout_exc* is raised after
    *timeout* second has passed.

    If :func:`cancel_wait` is called on *watcher* by another greenlet,
    raise an exception in this blocking greenlet
    (``socket.error(EBADF, 'File descriptor was closed in another
    greenlet')`` by default).

    :param watcher: An event loop watcher, most commonly an IO watcher obtained from
        :meth:`gevent.core.loop.io`
    :keyword timeout_exc: The exception to raise if the timeout expires.
        By default, a :class:`socket.timeout` exception is raised.
        If you pass a value for this keyword, it is interpreted as for
        :class:`gevent.timeout.Timeout`.

    :raises ~gevent.hub.ConcurrentObjectUseError: If the *watcher* is
        already started.
    N)r   r   s       r   wait_on_watcherr   F  s    0 GWk37r   c                     t               }|j                  j                  | d      }	 t        ||||      |j	                          S # |j	                          w xY w)a  
    wait_read(fileno, timeout=None, [timeout_exc=None]) -> None

    Block the current greenlet until *fileno* is ready to read.

    For the meaning of the other parameters and possible exceptions,
    see :func:`wait`.

    .. seealso:: :func:`cancel_wait`
    re   r{   r/   ior   r-   )filenorV   r   rU   r   s        r   r   r   a  sE     )C	VQ	Br7K=


   A Ac                     t               }|j                  j                  | d      }	 t        ||||      |j	                          S # |j	                          w xY w)a  
    wait_write(fileno, timeout=None, [timeout_exc=None]) -> None

    Block the current greenlet until *fileno* is ready to write.

    For the meaning of the other parameters and possible exceptions,
    see :func:`wait`.

    .. deprecated:: 1.1
       The keyword argument *event* is ignored. Applications should not pass this parameter.
       In the future, doing so will become an error.

    .. seealso:: :func:`cancel_wait`
       r   r   rV   r   eventrU   r   s         r   r   r   t  sE      )C	VQ	Br7K=


r   c                     t               }|j                  j                  | d      }	 t        ||||      |j	                          S # |j	                          w xY w)a  
    wait_readwrite(fileno, timeout=None, [timeout_exc=None]) -> None

    Block the current greenlet until *fileno* is ready to read or
    write.

    For the meaning of the other parameters and possible exceptions,
    see :func:`wait`.

    .. deprecated:: 1.1
       The keyword argument *event* is ignored. Applications should not pass this parameter.
       In the future, doing so will become an error.

    .. seealso:: :func:`cancel_wait`
       r   r   s         r   r   r     sE    " )C	VQ	Br7K=


r   c                      t                y r   )r   r   r   r   _initr     s    Or   )import_c_accelzgevent.__hub_primitives)NN)NNNr   )+__doc__
__future__r   r   r   rm   gevent.exceptionsr   r   geventr   r	   gevent._utilr
   gevent._hub_localr   r{   gevent.timeoutr   
__import__r   localsr   r   r   __all__r   objectrI   r   r   	Exceptionr   r   r   r   r   r   r   r   r   r   globalsr   r   r   <module>r      s"   '  %  0 6 '   7 " $J/:: ( ^^ $33	 (<(V(V	$ %T"6 T"nMF M`$7N%;N ,  &*u$ 86 # &  $e 0 $(U% 2  ' wy3 4r   