§
    :FcaÒ6  ã                   ó4  — 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
j         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$¦  «         dS )(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                  ó   — d S ©N© r   ó    ú8/usr/lib/python3/dist-packages/gevent/_hub_primitives.pyú<lambda>r      s   €  D€ 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dS )	r   c                 ó>  — t          | ¦  «        }|                     |j        |¦  «         	 |                     ¦   «         }||ur+t	          dt          ¦   «         ›d|›d|›d| ›d|›d�¦  «        ‚	 |                     ¦   «          dS # |                     ¦   «          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.   s­   € õ ˜‘”ˆØ�Š�f”m VÑ,Ô,Ð,ð	Ø—Z’Z‘\”\ˆFØ˜VÐ#Ð#Ý(Ð(å"™œ˜˜Ø˜˜Ø˜˜Ø˜˜Ø˜˜ðñô ð ð $ð �LŠL‰NŒNˆNˆNˆNøˆG�LŠL‰NŒNˆNˆNøøøs   ¬AB ÂBc                 óÔ   — g }|D ]6}|€Œ|j         €|                     ¦   «          Œ!|                     |¦  «         Œ7|r%| j                             | j        ||||¦  «         d S  ||Ž  d S 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   s�   € ØˆØð 	)ð 	)ˆGØˆØØÔÐ'Ø—’‘”��à—’ Ñ(Ô(Ð(Ð(Øð 	ØŒI×"Ò" 4Ô#:¸HÀhÐPTÐV_Ñ`Ô`Ð`Ð`Ð`àˆD�)ÐÐÐÐr   c                 óH   — |D ]}|                       ||d¦  «         Œ ||Ž  d S )NT)Ú_cancel_wait)r&   r2   r3   r4   r5   r'   s         r   r1   z)WaitOperationsGreenlet._cancel_waits_thenS   s?   € Øð 	7ð 	7ˆGØ×Ò˜g x°Ñ6Ô6Ð6Ð6ØˆˆiÐÐÐÐr   Fc                 ó”   — |€dS |j         �$| j                             | j        |||¦  «         dS |r|                     ¦   «          dS dS )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   s`   € ð ˆ?ð ˆFàÔÐ'ØŒI×"Ò" 4Ô#4°g¸uÀmÑTÔTÐTØˆFàð 	Ø�MŠM‰OŒOˆOˆOˆOð	ð 	r   c                 óª   — |j         }|j        }|r|                     ¦   «          |r*t          |dd ¦  «        }|�|                     |¦  «         d S d S d S )NÚ__self__)Úactiver,   r-   ÚgetattrÚthrow)r&   r'   r;   r<   r@   ÚcbÚglets          r   r9   z#WaitOperationsGreenlet._cancel_waitq   sq   € ð ”ˆØÔˆØð 	Ø�MŠM‰OŒOˆOØð 	"å˜2˜z¨4Ñ0Ô0ˆDØÐØ—
’
˜5Ñ!Ô!Ð!Ð!Ð!ð		"ð 	"ð  Ðr   N)F)Ú__name__Ú
__module__Ú__qualname__r*   r7   r1   r=   r9   r   r   r   r   r   ,   sd   € € € € € ðð ð ð.ð ð ðð ð ð
ð ð ð ð2"ð "ð "ð "ð "r   r   c                   ó<   — e Zd Zd„ Zd„ Zd„ Zd„ ZeZd„ Zd„ Z	d„ Z
dS )	Ú_WaitIteratorc                 óü   — || _         t          |¦  «        | _        | j        j        | _        || _        || _        d | _        d| _        |€t          |¦  «        nt          |t          |¦  «        ¦  «        | _        d S )NF)Ú_hubr   r	   r#   Ú_switchÚ_timeoutÚ_objectsÚ_timerÚ_begunÚlenÚminÚ_count)r&   ÚobjectsÚhubÚtimeoutÚcounts        r   Ú__init__z_WaitIterator.__init__…   sk   € ØˆŒ	Ý% cÑ*Ô*ˆŒØ”|Ô*ˆŒØˆŒØˆŒàˆŒØˆŒð
 ', m•c˜'‘l”l�l½¸UÅCÈÁLÄLÑ9QÔ9QˆŒˆˆr   c                 ó  — | j         rd S d| _         | j        D ]}|                     | j        ¦  «         Œ| j        �M| j        j                             | j        d¬¦  «        | _        | j         	                    | j        | ¦  «         d S d S )NTéÿÿÿÿ)Úpriority)
rP   rN   ÚrawlinkrL   rM   rK   r/   ÚtimerrO   r"   )r&   Úobjs     r   Ú_beginz_WaitIterator._begin”   s’   € ØŒ;ð 	ØˆFàˆŒð ”=ð 	&ð 	&ˆCØ�KŠK˜œÑ%Ô%Ð%Ð%àŒ=Ð$Øœ)œ.×.Ò.¨t¬}ÀrÐ.ÑJÔJˆDŒKØŒK×Ò˜dœl¨DÑ1Ô1Ð1Ð1Ð1ð %Ð$r   c                 ó   — | S r   r   ©r&   s    r   Ú__iter__z_WaitIterator.__iter__£   ó   € Øˆr   c                 óŽ  — |                       ¦   «          | j        dk    r"|                      ¦   «          t          ¦   «         ‚| xj        dz  c_        	 | j                             ¦   «         }| j                             ¦   «          || u r"|                      ¦   «          t          ¦   «         ‚|S #  |                      ¦   «          ‚ xY w)Nr   é   )r_   rS   Ú_cleanupÚStopIterationr	   r$   Úclear)r&   Úitems     r   Ú__next__z_WaitIterator.__next__¦   s­   € Ø�Š‰ŒˆàŒ;˜!ÒÐà�MŠM‰OŒOˆOÝ‘/”/Ð!àˆŒ�qÑˆŒð
	Ø”<×#Ò#Ñ%Ô%ˆDØŒL×ÒÑ Ô Ð Ø�tˆ|ˆ|à—’‘”�Ý#‘o”oÐ%ØˆKøð	Ø�MŠM‰OŒOˆOØøøøs   ÁAB- Â-Cc                 óø   — | j         � | j                              ¦   «          d | _         | j        }d| _        |D ]A}t          |dd ¦  «        }|�,	  || j        ¦  «         Œ'#  t          j        ¦   «          Y Œ>xY wŒBd S )Nr   Úunlink)rO   r-   rN   rA   rL   Ú	tracebackÚ	print_exc)r&   ÚobjsÚaobjrl   s       r   rf   z_WaitIterator._cleanup½   s    € ØŒ;Ð"ØŒK×ÒÑÔÐØˆDŒKàŒ}ˆØˆŒØð 	*ð 	*ˆDÝ˜T 8¨TÑ2Ô2ˆFØÐ!ð*Ø�F˜4œ<Ñ(Ô(Ð(Ð(øð*ÝÔ'Ñ)Ô)Ð)Ð)Ð)øøøð	 "ð	*ð 	*s   ÁAÁA6c                 ó   — | S r   r   ra   s    r   Ú	__enter__z_WaitIterator.__enter__Ì   rc   r   c                 ó.   — |                       ¦   «          d S 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ð Rð Rð2ð 2ð 2ðð ð ðð ð ð* €Dð*ð *ð *ðð ð ðð ð ð ð r   rI   c                 ót   — t          ¦   «         }| €|                     |¬¦  «        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.
    N©rV   )Úget_hubÚjoinrI   ©rT   rV   rW   rU   s       r   r   r   Ó   s>   € õB ‰)Œ)€CØ€Ø—’ �Ñ)Ô)Ð*Ð*Ý˜ # w°Ñ6Ô6Ð6r   c                 óŠ   — | €$t          ¦   «         }|                     |¬¦  «        S t          t          | ||¦  «        ¦  «        S )ax  
    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`
    Nrz   )r{   r|   Úlistr   r}   s       r   r   r   ú   sB   € ðD €Ý‰iŒiˆØ�xŠx ˆxÑ(Ô(Ð(ÝÕ  ¨'°5Ñ9Ô9Ñ:Ô:Ð:r   c                 ó
   — | a d S r   )Ú_timeout_error)Úes    r   Úset_default_timeout_errorrƒ   #  s   € à€N€N€Nr   c                 óR  — | j         �t          d| j         ›�¦  «        ‚|€t          ¦   «         }|€|                     | ¦  «         d S t	          j        ||t          us|€|nt          d¦  «        ¦  «        }|5  |                     | ¦  «         d d d ¦  «         d S # 1 swxY w Y   d S )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Œiˆà€Ø�Š�ÑÔÐØˆåÔ)Øà�uÐ$Ð$¨¨ð 
ˆå˜[Ñ)Ô)ñ	,ô ,€Gð 
ð ð Ø�Š�ÑÔÐðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð s   Á9BÂB Â#B c                 óv   — | �|€t          d¦  «        ‚t          || j        |�|nt          | j        ¦  «         d S )Nz6The socket has already been closed by another greenlet)r   rˆ   rV   r
   rU   )Úsocketr'   r‡   s      r   Úwait_on_socketr‹   =  sO   € Ø€~˜˜õ 'Ð'_Ñ`Ô`Ð`Ý�G˜Vœ^Ø#.Ð#:�K�KÅØ”Jñ ô  ð  ð  ð  r   c                 ó*   — t          | |||¦  «         dS )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 *io* by another greenlet,
    raise an exception in this blocking greenlet
    (``socket.error(EBADF, 'File descriptor was closed in another
    greenlet')`` by default).

    :param io: 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 �G˜W k°3Ñ7Ô7Ð7Ð7Ð7r   c                 óÔ   — t          ¦   «         }|j                             | d¦  «        }	 t          ||||¦  «        |                     ¦   «          S # |                     ¦   «          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  sY   € õ ‰)Œ)€CØ	Œ�Š�V˜QÑ	Ô	€BðÝ˜r 7¨K¸Ñ=Ô=à
�Š‰
Œ
ˆ
ˆ
øˆ�Š‰
Œ
ˆ
ˆ
øøøó   «A ÁA'c                 óÔ   — t          ¦   «         }|j                             | d¦  «        }	 t          ||||¦  «        |                     ¦   «          S # |                     ¦   «          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  sY   € õ  ‰)Œ)€CØ	Œ�Š�V˜QÑ	Ô	€BðÝ˜r 7¨K¸Ñ=Ô=à
�Š‰
Œ
ˆ
ˆ
øˆ�Š‰
Œ
ˆ
ˆ
øøør’   c                 óÔ   — t          ¦   «         }|j                             | d¦  «        }	 t          ||||¦  «        |                     ¦   «          S # |                     ¦   «          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   Œ  sY   € õ" ‰)Œ)€CØ	Œ�Š�V˜QÑ	Ô	€BðÝ˜r 7¨K¸Ñ=Ô=à
�Š‰
Œ
ˆ
ˆ
øˆ�Š‰
Œ
ˆ
ˆ
øøør’   c                  ó"   — t          ¦   «          d S r   )r   r   r   r   Ú_initrš   ¥  s   € Ý�O„O€O€O€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Ð 0Ð 0Ð 0Ð 0Ð 0Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6à 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø "Ð "Ð "Ð "Ð "Ð "ð $˜ JÑ/Ô/Ô:€€�„ˆÑ Ø(˜L€€�„ˆÑ Ø”^€€�„ˆÑ Ø$Ô3€€�„Ð	Ñ Ø(<Ô(V€€�„Ð	$Ñ %ðð ð €ðT"ð T"ð T"ð T"ð T"Ð6ñ T"ô T"ð T"ðnMð Mð Mð Mð M�Fñ Mô Mð Mð`$7ð $7ð $7ð $7ðN%;ð %;ð %;ð %;ðN €ðð ð ðð ð ð, ð  ð  ð  ð &*°uÀ$ð 8ð 8ð 8ð 8ð6 #°ð ð ð ð ð&  $°¸eð ð ð ð ð0 $(°UÀ%ð ð ð ð ð2ð ð ð €�„€à 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø €ˆwˆw‰yŒyÐ3Ñ 4Ô 4Ð 4Ð 4Ð 4r   