ó
ÐH/\c           @  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	 „  Z e ƒ  e ƒ  d
 <[ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d l m Z e e ƒ  d ƒ d S(   s7   Basic synchronization primitives: Event and AsyncResultiÿÿÿÿ(   t   print_function(   t   _NONE(   t   reraise(   t   dump_tracebackt   load_traceback(   t   Timeoutt   Eventt   AsyncResultc          C  s   t  d ƒ }  |  j j S(   Ns   gevent._abstract_linkable(   t
   __import__t   _abstract_linkablet   AbstractLinkable(   t   x(    (    s+   lib/python2.7/site-packages/gevent/event.pyt   _get_linkable   s    R
   c           B  sq   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d d
 „ Z d „  Z RS(   sd  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.

    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.

    .. 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.
    t   _flagc         C  s    t  t |  ƒ j ƒ  t |  _ d  S(   N(   t   superR   t   __init__t   FalseR   (   t   self(    (    s+   lib/python2.7/site-packages/gevent/event.pyR   0   s    c         C  s,   d |  j  j |  j r d p d |  j ƒ  f S(   Ns   <%s %s _links[%s]>t   sett   clear(   t	   __class__t   __name__R   t	   linkcount(   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   __str__4   s    c         C  s   |  j  S(   s5   Return true if and only if the internal flag is true.(   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   is_set8   s    c         C  s   |  j  S(   N(   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   isSet<   s    c         C  s   |  j  S(   N(   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   ready@   s    c         C  s   t  |  _ |  j ƒ  d S(   s"  
        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).
        N(   t   TrueR   t   _check_and_notify(   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyR   E   s    		c         C  s   t  |  _ d S(   s¾   
        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.
        N(   R   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyR   Q   s    c         C  s)   | s% |  j  } | s! t d ƒ ‚ | S| S(   Ns*   if we didn't wait we should already be set(   R   t   AssertionError(   R   t   waitedt   wait_successt   flag(    (    s+   lib/python2.7/site-packages/gevent/event.pyt   _wait_return_valueZ   s
    	c         C  s   |  j  | ƒ S(   sÝ  
        Block until the internal flag is true.

        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 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).

        :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.
        (   t   _wait(   R   t   timeout(    (    s+   lib/python2.7/site-packages/gevent/event.pyt   waitf   s    c         C  s   d  S(   N(    (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   _reset_internal_locks   s    (   R   N(   R   t
   __module__t   __doc__t	   __slots__R   R   R   R   R   R   R   R!   t   NoneR$   R%   (    (    (    s+   lib/python2.7/site-packages/gevent/event.pyR      s   									c           B  sø   e  Z d  Z d Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z	 d	 „  Z
 d
 „  Z e d „  ƒ Z d d „ Z d d „ Z d „  Z e d d „ Z d „  Z d „  Z d d „ Z d „  Z d d „ Z e Z d „  Z d „  Z d „  Z RS(   sß  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.

    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:

        >>> 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.
    t   _valuet	   _exc_infot   _imap_task_indexc         C  s)   t  t |  ƒ j ƒ  t |  _ d |  _ d  S(   N(    (   R   R   R   R   R*   R+   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyR   ¼   s    	c         C  s   |  j  r |  j  d St S(   Ni   (   R+   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt
   _exceptionÁ   s    c         C  s   |  j  t k	 r |  j  Sd S(   sn   
        Holds the value passed to :meth:`set` if :meth:`set` was called. Otherwise,
        ``None``
        N(   R*   R   R)   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   valueÅ   s    c         C  s5   |  j  r1 |  j  d |  j  d t |  j  d ƒ f Sd S(   s_   
        The three-tuple of exception information if :meth:`set_exception` was called.
        i    i   i   (    (   R+   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   exc_infoÍ   s    	(c         C  s¥   d |  j  j f } |  j d  k	 s1 |  j t k	 rE | d |  j 7} n  |  j d  k	 rw |  j t k	 rw | d |  j 7} n  |  j t k r“ | d 7} n  | d |  j ƒ  S(   Ns   <%s s	   value=%r s   exception=%r s   unset s    _links[%s]>(   R   R   R.   R)   R-   R   R   (   R   t   result(    (    s+   lib/python2.7/site-packages/gevent/event.pyR   Ö   s    c         C  s   |  j  p |  j t k	 S(   s;   Return true if and only if it holds a value or an exception(   R+   R*   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyR   à   s    c         C  s   |  j  t k	 S(   s8   Return true if and only if it is ready and holds a value(   R*   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt
   successfulä   s    c         C  s   |  j  r |  j  d Sd S(   s}   Holds the exception instance passed to :meth:`set_exception` if :meth:`set_exception` was called.
        Otherwise ``None``.i   N(   R+   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt	   exceptionè   s    	c         C  s   | |  _  |  j ƒ  d S(   sÎ   Store 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(   R*   R   (   R   R.   (    (    s+   lib/python2.7/site-packages/gevent/event.pyR   ï   s    	c         C  sY   | r- | d | d t  | d ƒ f |  _ n t | ƒ | t  d ƒ f |  _ |  j ƒ  d S(   sË  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.
        i    i   i   N(   R   R+   t   typeR)   R   (   R   R2   R/   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   set_exceptionø   s    
'c         C  s   t  |  j Œ  d  S(   N(   R   R/   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   _raise_exception	  s    c         C  s[   |  j  t k	 r |  j  S|  j r) |  j ƒ  S| s; t ƒ  ‚ n  |  j | d ƒ |  j d t ƒ S(   s¼  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.
        t   block(    (   R*   R   R+   R5   R   t
   _wait_coret   getR   (   R   R6   R#   (    (    s+   lib/python2.7/site-packages/gevent/event.pyR8     s    	
c         C  s   |  j  d t ƒ S(   s¸   
        Return the value or raise the exception without blocking.

        If this object is not yet :meth:`ready <ready>`, raise
        :class:`gevent.Timeout` immediately.
        R6   (   R8   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt
   get_nowait*  s    c         C  s   |  j  S(   N(   R.   (   R   R   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyR!   3  s    c         C  s   |  j  | ƒ S(   s-  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#   (    (    s+   lib/python2.7/site-packages/gevent/event.pyR$   9  s    c         C  sB   | j  ƒ  r |  j | j ƒ n |  j | j t | d d  ƒ ƒ d  S(   NR/   (   R1   R   R.   R4   R2   t   getattrR)   (   R   t   source(    (    s+   lib/python2.7/site-packages/gevent/event.pyt   __call__O  s    c         C  s   |  j  d | ƒ S(   NR#   (   R8   (   R   R#   (    (    s+   lib/python2.7/site-packages/gevent/event.pyR0   W  s    c         C  s
   |  j  ƒ  S(   N(   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   done\  s    c         C  s   t  S(   N(   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   cancela  s    c         C  s   t  S(   N(   R   (   R   (    (    s+   lib/python2.7/site-packages/gevent/event.pyt	   cancelledd  s    (   R*   R+   R,   N(   R   R&   R'   R(   R   t   propertyR-   R.   R/   R   R   R1   R2   R)   R   R4   R5   R   R8   R9   R!   R$   R<   R0   t
   set_resultR=   R>   R?   (    (    (    s+   lib/python2.7/site-packages/gevent/event.pyR   ˆ   s.   0			
										(   t   import_c_accels   gevent._eventN(   R'   t
   __future__R    t   gevent._utilR   t   gevent._compatR   t   gevent._tblibR   R   t   gevent.timeoutR   t   __all__R   t   localsR
   R   R   RB   t   globals(    (    (    s+   lib/python2.7/site-packages/gevent/event.pyt   <module>   s   		jâ