3
W>p_3              &   @   sp  d Z ddlZddlZddlZddlZyddlZW n ek
rH   dZY nX yddlZW n ek
rn   dZY nX yddlZW n ek
r   dZY nX ye	 W n e
k
r   eZ	Y nX ddddddgZd	Zdad
d ZG dd de	ZG dd deZG dd deZG dd deZG dd deZG dd deZdZerHeZn$erTeZneZedk	rlejd dS )zD
A platform independent file lock that supports the with-statement.
    NTimeoutBaseFileLockWindowsFileLockUnixFileLockSoftFileLockFileLockz3.0.12c               C   s   t ptjta t S )z0Returns the logger instance used in this module.)_loggerlogging	getLogger__name__ r   r   }/home/aldo/Documentos/tesis/tesis/device auto/pruebas pulsar/pruebaclonado/envClonado/lib/python3.6/site-packages/filelock.pyloggerL   s    r   c               @   s    e Zd ZdZdd Zdd ZdS )r   zN
    Raised when the lock could not be acquired in *timeout*
    seconds.
    c             C   s
   || _ dS )z	
        N)	lock_file)selfr   r   r   r   __init__[   s    zTimeout.__init__c             C   s   dj | j}|S )Nz)The file lock '{}' could not be acquired.)formatr   )r   tempr   r   r   __str__b   s    zTimeout.__str__N)r   
__module____qualname____doc__r   r   r   r   r   r   r   U   s   c               @   s$   e Zd Zdd Zdd Zdd ZdS )_Acquire_ReturnProxyc             C   s
   || _ d S )N)lock)r   r   r   r   r   r   u   s    z_Acquire_ReturnProxy.__init__c             C   s   | j S )N)r   )r   r   r   r   	__enter__y   s    z_Acquire_ReturnProxy.__enter__c             C   s   | j j  d S )N)r   release)r   exc_type	exc_value	tracebackr   r   r   __exit__|   s    
z_Acquire_ReturnProxy.__exit__N)r   r   r   r   r   r   r   r   r   r   r   s   s   r   c               @   s   e Zd ZdZdddZedd Zedd Zej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 Zdd ZdS )!r   z3
    Implements the base class of a file lock.
       c             C   s&   || _ d| _|| _tj | _d| _dS )z	
        Nr   )
_lock_file_lock_file_fdtimeout	threadingLock_thread_lock_lock_counter)r   r   r#   r   r   r   r      s    
zBaseFileLock.__init__c             C   s   | j S )z,
        The path to the lock file.
        )r!   )r   r   r   r   r      s    zBaseFileLock.lock_filec             C   s   | j S )a~  
        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
        )_timeout)r   r   r   r   r#      s    zBaseFileLock.timeoutc             C   s   t || _dS )z	
        N)floatr(   )r   valuer   r   r   r#      s    
c             C   s
   t  dS )z
        Platform dependent. If the file lock could be
        acquired, self._lock_file_fd holds the file descriptor
        of the lock file.
        N)NotImplementedError)r   r   r   r   _acquire   s    zBaseFileLock._acquirec             C   s
   t  dS )zH
        Releases the lock and sets self._lock_file_fd to None.
        N)r+   )r   r   r   r   _release   s    zBaseFileLock._releasec             C   s
   | j dk	S )z
        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   r   r   	is_locked   s    	zBaseFileLock.is_lockedN皙?c             C   s&  |dkr| j }| j |  jd7  _W dQ R X t| }| j}tj }yx| j$ | jsnt jd|| | j	  W dQ R X | jrt j
d|| P qH|dkrtj | |krt jd|| t| jqHt jd||| tj| qHW W n2   | j td| jd | _W dQ R X  Y nX t| dS )	aY  
        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.
        Nr    z#Attempting to acquire lock %s on %szLock %s acquired on %sr   z"Timeout on acquiring lock %s on %sz2Lock %s not acquired on %s, waiting %s seconds ...)r   )r#   r&   r'   idr!   timer.   r   debugr,   infor   sleepmaxr   )r   r#   Zpoll_intervalllock_idlock_filename
start_timer   r   r   acquire   s8    $
zBaseFileLock.acquireFc             C   st   | j d | jrf|  jd8  _| jdks*|rft| }| j}t jd|| | j  d| _t jd|| W dQ R X dS )aV  
        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.
        r    r   z#Attempting to release lock %s on %szLock %s released on %sN)	r&   r.   r'   r0   r!   r   r2   r-   r3   )r   forcer6   r7   r   r   r   r   %  s    zBaseFileLock.releasec             C   s   | j   | S )N)r9   )r   r   r   r   r   B  s    zBaseFileLock.__enter__c             C   s   | j   d S )N)r   )r   r   r   r   r   r   r   r   F  s    zBaseFileLock.__exit__c             C   s   | j dd d S )NT)r:   )r   )r   r   r   r   __del__J  s    zBaseFileLock.__del__)r<   )Nr/   )F)r   r   r   r   r   propertyr   r#   setterr,   r-   r.   r9   r   r   r   r;   r   r   r   r   r      s   

	
J
c               @   s    e Zd ZdZdd Zdd ZdS )r   ze
    Uses the :func:`msvcrt.locking` function to hard lock the lock file on
    windows systems.
    c             C   s|   t jt jB t jB }yt j| j|}W n tk
r8   Y n@X ytj|tj	d W n" t
tfk
rp   t j| Y nX || _d S )Nr    )osO_RDWRO_CREATO_TRUNCopenr!   OSErrormsvcrtlockingZLK_NBLCKIOErrorcloser"   )r   	open_modefdr   r   r   r,   X  s    zWindowsFileLock._acquirec             C   sP   | j }d | _ tj|tjd tj| ytj| j W n tk
rJ   Y nX d S )Nr    )	r"   rE   rF   ZLK_UNLCKr?   rH   remover!   rD   )r   rJ   r   r   r   r-   h  s    
zWindowsFileLock._releaseN)r   r   r   r   r,   r-   r   r   r   r   r   R  s   c               @   s    e Zd ZdZdd Zdd ZdS )r   zR
    Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems.
    c             C   sf   t jt jB t jB }t j| j|}ytj|tjtj	B  W n" t
tfk
rZ   t j| Y nX || _d S )N)r?   r@   rA   rB   rC   r!   fcntlflockZLOCK_EXZLOCK_NBrG   rD   rH   r"   )r   rI   rJ   r   r   r   r,   ~  s    zUnixFileLock._acquirec             C   s(   | j }d | _ tj|tj tj| d S )N)r"   rL   rM   ZLOCK_UNr?   rH   )r   rJ   r   r   r   r-     s
    
zUnixFileLock._releaseN)r   r   r   r   r,   r-   r   r   r   r   r   y  s   c               @   s    e Zd ZdZdd Zdd ZdS )r   z8
    Simply watches the existence of the lock file.
    c             C   sN   t jt jB t jB t jB }yt j| j|}W n ttfk
rB   Y nX || _	d S )N)
r?   O_WRONLYrA   O_EXCLrB   rC   r!   rG   rD   r"   )r   rI   rJ   r   r   r   r,     s    zSoftFileLock._acquirec             C   s<   t j| j d | _yt j| j W n tk
r6   Y nX d S )N)r?   rH   r"   rK   r!   rD   )r   r   r   r   r-     s    zSoftFileLock._releaseN)r   r   r   r   r,   r-   r   r   r   r   r     s   
z only soft file lock is available)r   r	   r?   r$   r1   warningsImportErrorrE   rL   TimeoutError	NameErrorrD   __all____version__r   r   r   objectr   r   r   r   r   r   warnr   r   r   r   <module>   sX   



	 R'!
