ó
–ù\c           @   sÑ  d  Z  d d l Z d d l Z d d l Z d d l Z y d d l Z Wn e k
 r_ d Z n Xy d d l Z Wn e k
 r‰ d Z n Xy d d l	 Z	 Wn e k
 r³ d Z	 n Xy e
 Wn e k
 rÕ e Z
 n Xd d d d d d g Z d	 Z d a d
 „  Z d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d Z e rœe Z n1 e	 r«e Z n" e Z e d k	 rÍe j d ƒ n  d S(   sD   
A platform independent file lock that supports the with-statement.
iÿÿÿÿNt   Timeoutt   BaseFileLockt   WindowsFileLockt   UnixFileLockt   SoftFileLockt   FileLocks   3.0.12c           C   s   t  p t j t ƒ a  t  S(   s0   Returns the logger instance used in this module.(   t   _loggert   loggingt	   getLoggert   __name__(    (    (    s'   lib/python2.7/site-packages/filelock.pyt   loggerL   s    c           B   s    e  Z d  Z d „  Z d „  Z RS(   sN   
    Raised when the lock could not be acquired in *timeout*
    seconds.
    c         C   s   | |  _  d S(   s	   
        N(   t	   lock_filet   None(   t   selfR   (    (    s'   lib/python2.7/site-packages/filelock.pyt   __init__[   s    	c         C   s   d j  |  j ƒ } | S(   Ns)   The file lock '{}' could not be acquired.(   t   formatR   (   R   t   temp(    (    s'   lib/python2.7/site-packages/filelock.pyt   __str__b   s    (   R	   t
   __module__t   __doc__R   R   (    (    (    s'   lib/python2.7/site-packages/filelock.pyR    U   s   	t   _Acquire_ReturnProxyc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t   lockR   (   R   R   (    (    s'   lib/python2.7/site-packages/filelock.pyR   u   s    	c         C   s   |  j  S(   N(   R   (   R   (    (    s'   lib/python2.7/site-packages/filelock.pyt	   __enter__y   s    c         C   s   |  j  j ƒ  d  S(   N(   R   t   releaseR   (   R   t   exc_typet	   exc_valuet	   traceback(    (    s'   lib/python2.7/site-packages/filelock.pyt   __exit__|   s    (   R	   R   R   R   R   (    (    (    s'   lib/python2.7/site-packages/filelock.pyR   s   s   		c           B   s¡   e  Z d  Z d d „ Z e d „  ƒ Z e d „  ƒ Z e j d „  ƒ Z d „  Z d „  Z	 e d „  ƒ Z
 d d	 d
 „ Z e d „ Z d „  Z d „  Z d „  Z RS(   s3   
    Implements the base class of a file lock.
    iÿÿÿÿc         C   s7   | |  _  d |  _ | |  _ t j ƒ  |  _ d |  _ d S(   s	   
        i    N(   t
   _lock_fileR   t   _lock_file_fdt   timeoutt	   threadingt   Lockt   _thread_lockt   _lock_counter(   R   R   R   (    (    s'   lib/python2.7/site-packages/filelock.pyR   †   s    				c         C   s   |  j  S(   s,   
        The path to the lock file.
        (   R   (   R   (    (    s'   lib/python2.7/site-packages/filelock.pyR   ž   s    c         C   s   |  j  S(   s~  
        You can set a default timeout for the filelock. It will be used as
        fallback value in the acquire method, if no timeout value (*None*) is
        given.

        If you want to disable the timeout, set it to a negative value.

        A timeout of 0 means, that there is exactly one attempt to acquire the
        file lock.

        .. versionadded:: 2.0.0
        (   t   _timeout(   R   (    (    s'   lib/python2.7/site-packages/filelock.pyR   ¥   s    c         C   s   t  | ƒ |  _ d S(   s	   
        N(   t   floatR#   R   (   R   t   value(    (    s'   lib/python2.7/site-packages/filelock.pyR   µ   s    c         C   s   t  ƒ  ‚ d S(   s˜   
        Platform dependent. If the file lock could be
        acquired, self._lock_file_fd holds the file descriptor
        of the lock file.
        N(   t   NotImplementedError(   R   (    (    s'   lib/python2.7/site-packages/filelock.pyt   _acquire¿   s    c         C   s   t  ƒ  ‚ d S(   sH   
        Releases the lock and sets self._lock_file_fd to None.
        N(   R&   (   R   (    (    s'   lib/python2.7/site-packages/filelock.pyt   _releaseÇ   s    c         C   s   |  j  d k	 S(   sž   
        True, if the object holds the file lock.

        .. versionchanged:: 2.0.0

            This was previously a method and is now a property.
        N(   R   R   (   R   (    (    s'   lib/python2.7/site-packages/filelock.pyt	   is_lockedÐ   s    	gš™™™™™©?c      	   C   s{  | d k r |  j } n  |  j  |  j d 7_ Wd QXt |  ƒ } |  j } t j ƒ  } yà xÙ t r6|  j 1 |  j sš t	 ƒ  j
 d | | ƒ |  j ƒ  n  Wd QX|  j rÃ t	 ƒ  j d | | ƒ Pq^ | d k rt j ƒ  | | k rt	 ƒ  j
 d | | ƒ t |  j ƒ ‚ q^ t	 ƒ  j
 d | | | ƒ t j | ƒ q^ WWn3 |  j  t d |  j d ƒ |  _ Wd QX‚  n Xt d |  ƒ S(	   sY  
        Acquires the file lock or fails with a :exc:`Timeout` error.

        .. code-block:: python

            # You can use this method in the context manager (recommended)
            with lock.acquire():
                pass

            # Or use an equivalent try-finally construct:
            lock.acquire()
            try:
                pass
            finally:
                lock.release()

        :arg float timeout:
            The maximum time waited for the file lock.
            If ``timeout < 0``, there is no timeout and this method will
            block until the lock could be acquired.
            If ``timeout`` is None, the default :attr:`~timeout` is used.

        :arg float poll_intervall:
            We check once in *poll_intervall* seconds if we can acquire the
            file lock.

        :raises Timeout:
            if the lock could not be acquired in *timeout* seconds.

        .. versionchanged:: 2.0.0

            This method returns now a *proxy* object instead of *self*,
            so that it can be used in a with statement without side effects.
        i   Ns#   Attempting to acquire lock %s on %ss   Lock %s acquired on %si    s"   Timeout on acquiring lock %s on %ss2   Lock %s not acquired on %s, waiting %s seconds ...R   (   R   R   R!   R"   t   idR   t   timet   TrueR)   R
   t   debugR'   t   infoR    t   sleept   maxR   (   R   R   t   poll_intervallt   lock_idt   lock_filenamet
   start_time(    (    s'   lib/python2.7/site-packages/filelock.pyt   acquireÛ   s8    $
		
		"	
c         C   s›   |  j  Œ |  j r‘ |  j d 8_ |  j d k s7 | r‘ t |  ƒ } |  j } t ƒ  j d | | ƒ |  j ƒ  d |  _ t ƒ  j d | | ƒ q‘ n  Wd QXd S(   sV  
        Releases the file lock.

        Please note, that the lock is only completly released, if the lock
        counter is 0.

        Also note, that the lock file itself is not automatically deleted.

        :arg bool force:
            If true, the lock counter is ignored and the lock is released in
            every case.
        i   i    s#   Attempting to release lock %s on %ss   Lock %s released on %sN(
   R!   R)   R"   R*   R   R
   R-   R(   R.   R   (   R   t   forceR2   R3   (    (    s'   lib/python2.7/site-packages/filelock.pyR   %  s    
		
	"c         C   s   |  j  ƒ  |  S(   N(   R5   (   R   (    (    s'   lib/python2.7/site-packages/filelock.pyR   B  s    
c         C   s   |  j  ƒ  d  S(   N(   R   R   (   R   R   R   R   (    (    s'   lib/python2.7/site-packages/filelock.pyR   F  s    
c         C   s   |  j  d t ƒ d  S(   NR6   (   R   R,   R   (   R   (    (    s'   lib/python2.7/site-packages/filelock.pyt   __del__J  s    N(   R	   R   R   R   t   propertyR   R   t   setterR'   R(   R)   R   R5   t   FalseR   R   R   R7   (    (    (    s'   lib/python2.7/site-packages/filelock.pyR      s   
			J		c           B   s    e  Z d  Z d „  Z d „  Z RS(   se   
    Uses the :func:`msvcrt.locking` function to hard lock the lock file on
    windows systems.
    c         C   s’   t  j t  j Bt  j B} y t  j |  j | ƒ } Wn t k
 rC nK Xy t j | t j	 d ƒ Wn$ t
 t f k
 r„ t  j | ƒ n
 X| |  _ d  S(   Ni   (   t   ost   O_RDWRt   O_CREATt   O_TRUNCt   openR   t   OSErrort   msvcrtt   lockingt   LK_NBLCKt   IOErrort   closeR   R   (   R   t	   open_modet   fd(    (    s'   lib/python2.7/site-packages/filelock.pyR'   X  s    	c         C   sa   |  j  } d  |  _  t j | t j d ƒ t j | ƒ y t j |  j ƒ Wn t	 k
 r\ n Xd  S(   Ni   (
   R   R   RA   RB   t   LK_UNLCKR;   RE   t   removeR   R@   (   R   RG   (    (    s'   lib/python2.7/site-packages/filelock.pyR(   h  s    		(   R	   R   R   R'   R(   (    (    (    s'   lib/python2.7/site-packages/filelock.pyR   R  s   	c           B   s    e  Z d  Z d „  Z d „  Z RS(   sR   
    Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems.
    c         C   s~   t  j t  j Bt  j B} t  j |  j | ƒ } y t j | t j t j	 Bƒ Wn$ t
 t f k
 rp t  j | ƒ n
 X| |  _ d  S(   N(   R;   R<   R=   R>   R?   R   t   fcntlt   flockt   LOCK_EXt   LOCK_NBRD   R@   RE   R   R   (   R   RF   RG   (    (    s'   lib/python2.7/site-packages/filelock.pyR'   ~  s    	c         C   s6   |  j  } d  |  _  t j | t j ƒ t j | ƒ d  S(   N(   R   R   RJ   RK   t   LOCK_UNR;   RE   (   R   RG   (    (    s'   lib/python2.7/site-packages/filelock.pyR(   Š  s
    		(   R	   R   R   R'   R(   (    (    (    s'   lib/python2.7/site-packages/filelock.pyR   y  s   	c           B   s    e  Z d  Z d „  Z d „  Z RS(   s8   
    Simply watches the existence of the lock file.
    c         C   s^   t  j t  j Bt  j Bt  j B} y t  j |  j | ƒ } Wn t t f k
 rP n
 X| |  _	 d  S(   N(   R;   t   O_WRONLYR=   t   O_EXCLR>   R?   R   RD   R@   R   R   (   R   RF   RG   (    (    s'   lib/python2.7/site-packages/filelock.pyR'     s    	c         C   sE   t  j |  j ƒ d  |  _ y t  j |  j ƒ Wn t k
 r@ n Xd  S(   N(   R;   RE   R   R   RI   R   R@   (   R   (    (    s'   lib/python2.7/site-packages/filelock.pyR(   §  s    	(   R	   R   R   R'   R(   (    (    (    s'   lib/python2.7/site-packages/filelock.pyR   ˜  s   	
s    only soft file lock is available(   R   R   R;   R   R+   t   warningst   ImportErrorR   RA   RJ   t   TimeoutErrort	   NameErrorR@   t   __all__t   __version__R   R
   R    t   objectR   R   R   R   R   R   t   warn(    (    (    s'   lib/python2.7/site-packages/filelock.pyt   <module>   sV   



			Ñ'!		