o
    0׾g:                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddgZd	d
 Ze e d< [G dd deZG dd deZddlmZ ee d dS )z7Basic synchronization primitives: Event and AsyncResult    )print_function)_NONE)reraise)dump_tracebackload_traceback)TimeoutEventAsyncResultc                  C   s   t d} | jjS )Nzgevent._abstract_linkable)
__import___abstract_linkableAbstractLinkable)x r   V/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/gevent/event.py_get_linkable   s   r   r   c                       sn   e Zd ZdZdZ fddZdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd ZdddZdd Z  ZS )r   a  
    A synchronization primitive that allows one greenlet to wake up
    one or more others. It has the same interface as
    :class:`threading.Event` but works across greenlets.

    .. important::
       This object is for communicating among greenlets within the
       same thread *only*! Do not try to use it to communicate across threads.

    An event object manages an internal flag that can be set to true
    with the :meth:`set` method and reset to false with the
    :meth:`clear` method. The :meth:`wait` method blocks until the
    flag is true; as soon as the flag is set to true, all greenlets
    that are currently blocked in a call to :meth:`wait` will be scheduled
    to awaken.

    Note that the flag may be cleared and set many times before
    any individual greenlet runs; all the greenlet can know for sure is that the
    flag was set *at least once* while it was waiting.
    If the greenlet cares whether the flag is still
    set, it must check with :meth:`ready` and possibly call back into
    :meth:`wait` again.

    .. note::

        The exact order and timing in which waiting greenlets are awakened is not determined.

        Once the event is set, other greenlets may run before any waiting greenlets
        are awakened.

        While the code here will awaken greenlets in the order in which they
        waited, each such greenlet that runs may in turn cause other greenlets
        to run.

        These details may change in the future.

    .. versionchanged:: 1.5a3

        Waiting greenlets are now awakened in
        the order in which they waited.

    .. versionchanged:: 1.5a3

        The low-level ``rawlink`` method (most users won't use this) now
        automatically unlinks waiters before calling them.

    .. versionchanged:: 20.5.1

        Callers to ``wait`` that find the event already set will now run
        after any other waiters that had to block. See :issue:`1520`.
    _flagc                    s   t t|   d| _d S NF)superr   __init__r   self	__class__r   r   r   Q   s   
zEvent.__init__c                 C   s    d| j j| jr	dnd|  f S )Nz<%s %s _links[%s]>setclear)r   __name__r   	linkcountr   r   r   r   __str__U   s
   zEvent.__str__c                 C      | j S )z5Return true if and only if the internal flag is true.r   r   r   r   r   is_set\      zEvent.is_setc                 C   r   Nr   r   r   r   r   isSet`   r!   zEvent.isSetc                 C   r   r"   r   r   r   r   r   readyd   s   zEvent.readyc                 C   s   d| _ |   dS )a"  
        Set the internal flag to true.

        All greenlets waiting for it to become true are awakened in
        some order at some time in the future. Greenlets that call
        :meth:`wait` once the flag is true will not block at all
        (until :meth:`clear` is called).
        TN)r   _check_and_notifyr   r   r   r   r   i   s   	z	Event.setc                 C   s
   d| _ dS )z
        Reset the internal flag to false.

        Subsequently, threads calling :meth:`wait` will block until
        :meth:`set` is called to set the internal flag to true again.
        FNr   r   r   r   r   r   u   s   
zEvent.clearc                 C   s   |s| j }|sJ d|S |S )Nz*if we didn't wait we should already be setr   )r   waitedwait_successflagr   r   r   _wait_return_value~   s
   zEvent._wait_return_valueNc                 C   
   |  |S )a  
        Block until this object is :meth:`ready`.

        If the internal flag is true on entry, return immediately. Otherwise,
        block until another thread (greenlet) calls :meth:`set` to set the flag to true,
        or until the optional *timeout* expires.

        When the *timeout* argument is present and not ``None``, it should be a
        floating point number specifying a timeout for the operation in seconds
        (or fractions thereof).

        :return: This method returns true if and only if the internal flag has been set to
            true, either before the wait call or after the wait starts, so it will
            always return ``True`` except if a timeout is given and the operation
            times out.

        .. versionchanged:: 1.1
            The return value represents the flag during the elapsed wait, not
            just after it elapses. This solves a race condition if one greenlet
            sets and then clears the flag without switching, while other greenlets
            are waiting. When the waiters wake up, this will return True; previously,
            they would still wake up, but the return value would be False. This is most
            noticeable when the *timeout* is present.
        _waitr   timeoutr   r   r   wait   s   
z
Event.waitc                 C   s   d S r"   r   r   r   r   r   _reset_internal_locks   s   zEvent._reset_internal_locksr"   )r   
__module____qualname____doc__	__slots__r   r   r    r#   r$   r   r   r)   r/   r0   __classcell__r   r   r   r   r      s    4	
c                       s   e Zd ZdZdZ fddZedd Zedd Zed	d
 Z	dd Z
dd Zdd Zedd Zd-ddZd-ddZdd Zd.ddZdd Zdd  Zd-d!d"Zd#d$ Zd-d%d&ZeZd'd( Zd)d* Zd+d, Z  ZS )/r	   a	  
    A one-time event that stores a value or an exception.

    Like :class:`Event` it wakes up all the waiters when :meth:`set`
    or :meth:`set_exception` is called. Waiters may receive the passed
    value or exception by calling :meth:`get` instead of :meth:`wait`.
    An :class:`AsyncResult` instance cannot be reset.

    .. important::
       This object is for communicating among greenlets within the
       same thread *only*! Do not try to use it to communicate across threads.

    To pass a value call :meth:`set`. Calls to :meth:`get` (those that
    are currently blocking as well as those made in the future) will
    return the value::

        >>> from gevent.event import AsyncResult
        >>> result = AsyncResult()
        >>> result.set(100)
        >>> result.get()
        100

    To pass an exception call :meth:`set_exception`. This will cause
    :meth:`get` to raise that exception::

        >>> result = AsyncResult()
        >>> result.set_exception(RuntimeError('failure'))
        >>> result.get()
        Traceback (most recent call last):
         ...
        RuntimeError: failure

    :class:`AsyncResult` implements :meth:`__call__` and thus can be
    used as :meth:`link` target::

        >>> import gevent
        >>> result = AsyncResult()
        >>> gevent.spawn(lambda : 1/0).link(result)
        >>> try:
        ...     result.get()
        ... except ZeroDivisionError:
        ...     print('ZeroDivisionError')
        ZeroDivisionError

    .. note::

        The order and timing in which waiting greenlets are awakened is not determined.
        As an implementation note, in gevent 1.1 and 1.0, waiting greenlets are awakened in a
        undetermined order sometime *after* the current greenlet yields to the event loop. Other greenlets
        (those not waiting to be awakened) may run between the current greenlet yielding and
        the waiting greenlets being awakened. These details may change in the future.

    .. versionchanged:: 1.1

       The exact order in which waiting greenlets
       are awakened is not the same as in 1.0.

    .. versionchanged:: 1.1

       Callbacks :meth:`linked <rawlink>` to this object are required to
       be hashable, and duplicates are merged.

    .. versionchanged:: 1.5a3

       Waiting greenlets are now awakened in the order in which they
       waited.

    .. versionchanged:: 1.5a3

       The low-level ``rawlink`` method
       (most users won't use this) now automatically unlinks waiters
       before calling them.
    )_value	_exc_info_imap_task_indexc                    s   t t|   t| _d| _d S )Nr   )r   r	   r   r   r6   r7   r   r   r   r   r      s   
zAsyncResult.__init__c                 C   s   | j r| j d S tS )N   )r7   r   r   r   r   r   
_exception   s   zAsyncResult._exceptionc                 C   s   | j tur| j S dS )zn
        Holds the value passed to :meth:`set` if :meth:`set` was called. Otherwise,
        ``None``
        Nr6   r   r   r   r   r   value  s   zAsyncResult.valuec                 C   s*   | j r| j d | j d t| j d fS dS )z_
        The three-tuple of exception information if :meth:`set_exception` was called.
        r   r9      r   )r7   r   r   r   r   r   exc_info
  s    zAsyncResult.exc_infoc                 C   st   d| j jf }| jd us| jtur|d| j 7 }| jd ur)| jtur)|d| j 7 }| jtu r2|d7 }|d|    S )Nz<%s z	value=%r zexception=%r zunset z _links[%s]>)r   r   r<   r:   r   r   )r   resultr   r   r   r     s   
zAsyncResult.__str__c                 C   s   | j p| jtuS )z;Return true if and only if it holds a value or an exception)r7   r6   r   r   r   r   r   r$     s   zAsyncResult.readyc                 C   s
   | j tuS )z8Return true if and only if it is ready and holds a valuer;   r   r   r   r   
successful!  s   
zAsyncResult.successfulc                 C   s   | j r| j d S dS )z}Holds the exception instance passed to :meth:`set_exception` if :meth:`set_exception` was called.
        Otherwise ``None``.r9   N)r7   r   r   r   r   	exception%  s   
zAsyncResult.exceptionNc                 C   s   || _ |   dS )zStore the value and wake up any waiters.

        All greenlets blocking on :meth:`get` or :meth:`wait` are awakened.
        Subsequent calls to :meth:`wait` and :meth:`get` will not block at all.
        N)r6   r%   )r   r<   r   r   r   r   ,  s   zAsyncResult.setc                 C   sB   |r|d |d t |d f| _n
t||t df| _|   dS )a  Store the exception and wake up any waiters.

        All greenlets blocking on :meth:`get` or :meth:`wait` are awakened.
        Subsequent calls to :meth:`wait` and :meth:`get` will not block at all.

        :keyword tuple exc_info: If given, a standard three-tuple of type, value, :class:`traceback`
            as returned by :func:`sys.exc_info`. This will be used when the exception
            is re-raised to propagate the correct traceback.
        r   r9   r=   N)r   r7   typer%   )r   rA   r>   r   r   r   set_exception5  s   
zAsyncResult.set_exceptionc                 C   s   t | j  d S r"   )r   r>   r   r   r   r   _raise_exceptionF  s   zAsyncResult._raise_exceptionTc                 C   sJ   | j tur| j S | jr|  S |st | d | |d | jddS )a  Return the stored value or raise the exception.

        If this instance already holds a value or an exception, return  or raise it immediately.
        Otherwise, block until another greenlet calls :meth:`set` or :meth:`set_exception` or
        until the optional timeout occurs.

        When the *timeout* argument is present and not ``None``, it should be a
        floating point number specifying a timeout for the operation in seconds
        (or fractions thereof). If the *timeout* elapses, the *Timeout* exception will
        be raised.

        :keyword bool block: If set to ``False`` and this instance is not ready,
            immediately raise a :class:`Timeout` exception.
        Tr   Fblock)r6   r   r7   rD   r   _capture_hub
_wait_coreget)r   rF   r.   r   r   r   rI   I  s   

zAsyncResult.getc                 C   s   | j ddS )z
        Return the value or raise the exception without blocking.

        If this object is not yet :meth:`ready <ready>`, raise
        :class:`gevent.Timeout` immediately.
        FrE   rI   r   r   r   r   
get_nowaiti  s   zAsyncResult.get_nowaitc                 C   r   r"   )r<   )r   r&   r'   r   r   r   r)   r  s   zAsyncResult._wait_return_valuec                 C   r*   )a-  Block until the instance is ready.

        If this instance already holds a value, it is returned immediately. If this
        instance already holds an exception, ``None`` is returned immediately.

        Otherwise, block until another greenlet calls :meth:`set` or :meth:`set_exception`
        (at which point either the value or ``None`` will be returned, respectively),
        or until the optional timeout expires (at which point ``None`` will also be
        returned).

        When the *timeout* argument is present and not ``None``, it should be a
        floating point number specifying a timeout for the operation in seconds
        (or fractions thereof).

        .. note:: If a timeout is given and expires, ``None`` will be returned
            (no timeout exception will be raised).

        r+   r-   r   r   r   r/   x  s   
zAsyncResult.waitc                 C   s2   |  r| |j d S | |jt|dd  d S )Nr>   )r@   r   r<   rC   rA   getattr)r   sourcer   r   r   __call__  s   zAsyncResult.__call__c                 C   s   | j |dS )N)r.   rJ   r-   r   r   r   r?     s   zAsyncResult.resultc                 C   s   |   S r"   )r$   r   r   r   r   done  s   zAsyncResult.donec                 C      dS r   r   r   r   r   r   cancel     zAsyncResult.cancelc                 C   rP   r   r   r   r   r   r   	cancelled  rR   zAsyncResult.cancelledr"   )TN)r   r1   r2   r3   r4   r   propertyr:   r<   r>   r   r$   r@   rA   r   rC   rD   rI   rK   r)   r/   rN   r?   
set_resultrO   rQ   rS   r5   r   r   r   r   r	      s8    J






	
 	

)import_c_accelzgevent._eventN)r3   
__future__r   gevent._utilr   gevent._compatr   gevent._tblibr   r   gevent.timeoutr   __all__r   localsr   r   r	   rV   globalsr   r   r   r   <module>   s$     ~