ó
úR_c           @` s   d  d l  m Z m Z 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(   i    (   t   print_functiont   absolute_importt   divisiont	   Semaphoret   BoundedSemaphorec          C` s   t  d  }  |  j j S(   Ns   gevent._abstract_linkable(   t
   __import__t   _abstract_linkablet   AbstractLinkable(   t   x(    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   _get_linkable	   s    R   c           B` s   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z	 d d	  Z e d d
  Z e Z d   Z d   Z RS(   s#  
    Semaphore(value=1) -> Semaphore

    A semaphore manages a counter representing the number of release()
    calls minus the number of acquire() calls, plus an initial value.
    The acquire() method blocks if necessary until it can return
    without making the counter negative.

    If not given, ``value`` defaults to 1.

    The semaphore is a context manager and can be used in ``with`` statements.

    This Semaphore's ``__exit__`` method does not call the trace function
    on CPython, but does under PyPy.

    .. seealso:: :class:`BoundedSemaphore` for a safer version that prevents
       some classes of bugs.

    .. versionchanged:: 1.4.0

        The order in which waiters are awakened is not specified. It was not
        specified previously, but usually went in FIFO order.
    i   c         C` sD   | d k  r t  d   n  t t |   j   | |  _ t |  _ d  S(   Ni    s$   semaphore initial value must be >= 0(   t
   ValueErrort   superR   t   __init__t   countert   Falset   _notify_all(   t   selft   value(    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyR   )   s
    	c         C` s&   |  j  j |  j |  j   f } d | S(   Ns   <%s counter=%s _links[%s]>(   t	   __class__t   __name__R   t	   linkcount(   R   t   params(    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   __str__0   s    c         C` s   |  j  d k S(   sn   Return a boolean indicating whether the semaphore can be acquired.
        Most useful with binary semaphores.i    (   R   (   R   (    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   locked4   s    c         C` s    |  j  d 7_  |  j   |  j  S(   sI   
        Release the semaphore, notifying any waiters if needed.
        i   (   R   t   _check_and_notify(   R   (    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   release9   s    
c         C` s   |  j  d k S(   Ni    (   R   (   R   (    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   readyA   s    c         C` s   |  j    d  S(   N(   R   (   R   (    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   _start_notifyD   s    c         C` s   | r
 | St  S(   N(   t   True(   R   t   waitedt   wait_success(    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   _wait_return_valueG   s    c         C` s*   |  j  d k r |  j  S|  j |  |  j  S(   s  
        wait(timeout=None) -> int

        Wait until it is possible to acquire this semaphore, or until the optional
        *timeout* elapses.

        .. caution:: If this semaphore was initialized with a size of 0,
           this method will block forever if no timeout is given.

        :keyword float timeout: If given, specifies the maximum amount of seconds
           this method will block.
        :return: A number indicating how many times the semaphore can be acquired
            before blocking.
        i    (   R   t   _wait(   R   t   timeout(    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   waitO   s    c         C` sm   |  j  d k r" |  j  d 8_  t S| s, t S|  j |  } | sE t S|  j  d 8_  |  j  d k si t  t S(   s   
        acquire(blocking=True, timeout=None) -> bool

        Acquire the semaphore.

        .. caution:: If this semaphore was initialized with a size of 0,
           this method will block forever (unless a timeout is given or blocking is
           set to false).

        :keyword bool blocking: If True (the default), this function will block
           until the semaphore is acquired.
        :keyword float timeout: If given, specifies the maximum amount of seconds
           this method will block.
        :return: A boolean indicating whether the semaphore was acquired.
           If ``blocking`` is True and ``timeout`` is None (the default), then
           (so long as this semaphore was initialized with a size greater than 0)
           this will always return True. If a timeout was given, and it expired before
           the semaphore was acquired, False will be returned. (Note that this can still
           raise a ``Timeout`` exception, if some other caller had already started a timer.)
        i    i   (   R   R   R   R    t   AssertionError(   R   t   blockingR!   t   success(    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   acquired   s    c         C` s   |  j    d  S(   N(   R&   (   R   (    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt	   __enter__   s    c         C` s   |  j    d  S(   N(   R   (   R   t   tt   vt   tb(    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   __exit__   s    N(   R   t
   __module__t   __doc__R   R   R   R   R   R   R   t   NoneR"   R   R&   t   _py3k_acquireR'   R+   (    (    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyR      s   						'	c           B` s&   e  Z d  Z e Z d   Z d   Z RS(   s  
    BoundedSemaphore(value=1) -> BoundedSemaphore

    A bounded semaphore checks to make sure its current value doesn't
    exceed its initial value. If it does, :class:`ValueError` is
    raised. In most situations semaphores are used to guard resources
    with limited capacity. If the semaphore is released too many times
    it's a sign of a bug.

    If not given, *value* defaults to 1.
    c         O` s#   t  j |  | |  |  j |  _ d  S(   N(   R   R   R   t   _initial_value(   R   t   argst   kwargs(    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyR   ¤   s    c         C` s5   |  j  |  j k r$ |  j d   n  t j |   d  S(   Ns!   Semaphore released too many times(   R   R0   t   _OVER_RELEASE_ERRORR   R   (   R   (    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyR   ¨   s    (   R   R,   R-   R
   R3   R   R   (    (    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyR      s   	(   t   import_c_accels   gevent.__semaphoreN(   t
   __future__R    R   R   t   __all__R	   t   localsR   R   R   t   gevent._utilR4   t   globals(    (    (    sJ   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/_semaphore.pyt   <module>   s   		'