ó
%_[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 e j e ƒ 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 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   2.0.8c           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   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyt   __init__Q   s    	c         C   s   d j  |  j ƒ } | S(   Ns)   The file lock '{}' could not be acquired.(   t   formatR   (   R   t   temp(    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyt   __str__X   s    (   t   __name__t
   __module__t   __doc__R	   R   (    (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR    K   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   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR	   e   s    				c         C   s   |  j  S(   s,   
        The path to the lock file.
        (   R   (   R   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/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   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR   „   s    c         C   s   t  | ƒ |  _ d S(   s	   
        N(   t   floatR   R   (   R   t   value(    (    sB   lib/python2.7/site-packages/navigator_updater/external/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   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/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   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/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   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyt	   is_locked¯   s    	gš™™™™™©?c      	   C   s…  | d k r |  j } n  |  j  |  j d 7_ Wd QXyõ t j ƒ  } xâ t r*t |  ƒ } |  j } |  j . |  j s— t	 j
 d | | ƒ |  j ƒ  n  Wd QX|  j r½ t	 j d | | ƒ PqI | d k rt j ƒ  | | k rt	 j
 d | | ƒ t |  j ƒ ‚ qI t	 j
 d | | | ƒ t j | ƒ qI WWn3 |  j  t d |  j d ƒ |  _ Wd QX‚  n Xd t f d	 „  ƒ  Y} | 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 you use an equal 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 aquiring lock %s on %ss2   Lock %s not acquired on %s, waiting %s seconds ...t   ReturnProxyc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         S   s   | |  _  d  S(   N(   t   lockR   (   R   R   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR	     s    	c         S   s   |  j  S(   N(   R   (   R   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyt	   __enter__  s    c         S   s   |  j  j ƒ  d  S(   N(   R   t   releaseR   (   R   t   exc_typet	   exc_valuet	   traceback(    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyt   __exit__  s    (   R   R   R	   R    R%   (    (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR     s   		R   (   R   R   R   R   t   timet   Truet   idR   R   t   loggert   debugR   t   infoR    t   sleept   maxt   object(   R   R   t   poll_intervallt
   start_timet   lock_idt   lock_filenameR   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyt   acquireº   sD    $
		
		"
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   forceR1   R2   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR!     s    
		
	c         C   s   |  j  ƒ  |  S(   N(   R3   (   R   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR    A  s    
c         C   s   |  j  ƒ  d  S(   N(   R!   R   (   R   R"   R#   R$   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR%   E  s    
c         C   s   |  j  d t ƒ d  S(   NR4   (   R!   R'   R   (   R   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyt   __del__I  s    N(   R   R   R   R	   t   propertyR   R   t   setterR   R   R   R   R3   t   FalseR!   R    R%   R5   (    (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR   `   s   
			e"		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(    (    sB   lib/python2.7/site-packages/navigator_updater/external/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   R?   R@   t   LK_UNLCKR9   RC   t   removeR   R>   (   R   RE   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR   h  s    		(   R   R   R   R   R   (    (    (    sB   lib/python2.7/site-packages/navigator_updater/external/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(   R9   R:   R;   R<   R=   R   t   fcntlt   flockt   LOCK_EXt   LOCK_NBRB   R>   RC   R   R   (   R   RD   RE   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR   €  s    	c         C   s6   |  j  } d  |  _  t j | t j ƒ t j | ƒ d  S(   N(   R   R   RH   RI   t   LOCK_UNR9   RC   (   R   RE   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR   Œ  s
    		(   R   R   R   R   R   (    (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR   {  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(   R9   t   O_WRONLYR;   t   O_EXCLR<   R=   R   RB   R>   R   R   (   R   RD   RE   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR     s    	c         C   sE   t  j |  j ƒ d  |  _ y t  j |  j ƒ Wn t k
 r@ n Xd  S(   N(   R9   RC   R   R   RG   R   R>   (   R   (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR   §  s    	(   R   R   R   R   R   (    (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyR   ˜  s   	
s    only soft file lock is available(   R   t   loggingR9   R   R&   t   warningst   ImportErrorR   R?   RH   t   TimeoutErrort	   NameErrorR>   t   __all__t   __version__t	   getLoggerR   R)   R    R.   R   R   R   R   R   t   warn(    (    (    sB   lib/python2.7/site-packages/navigator_updater/external/filelock.pyt   <module>   sJ   



ò)!		