o
    l¨Êh­3  ã                   @   sb  d Z ddlZddlZddlZddlZzddlZW n ey#   dZY nw zddlZW n ey5   dZY nw zddlZW n eyG   dZY nw ze	 W n e
yW   eZ	Y nw g d¢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rœeZdS er¢eZdS eZedur¯e d¡ dS 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 t¡a t S )z0Returns the logger instance used in this module.)Ú_loggerÚloggingÚ	getLoggerÚ__name__© r   r   ú:/var/www/html/env/lib/python3.10/site-packages/filelock.pyÚloggerL   s   r   c                   @   ó    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 ©ú	
        N)Ú	lock_file)Úselfr   r   r   r   Ú__init__[   s   zTimeout.__init__c                 C   s   d  | 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    r   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   ó   | j S r   r   ©r   r   r   r   Ú	__enter__y   s   z_Acquire_ReturnProxy.__enter__c                 C   s   | j  ¡  d S r   )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 ¡ | _d| _dS )r   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   r   )z,
        The path to the lock file.
        )r)   r    r   r   r   r   ž   s   zBaseFileLock.lock_filec                 C   r   )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
        )Ú_timeoutr    r   r   r   r+   ¥   s   zBaseFileLock.timeoutc                 C   s   t |ƒ| _dS r   )Úfloatr0   )r   Úvaluer   r   r   r+   µ   s   
c                 C   ó   t ƒ ‚)z˜
        Platform dependent. If the file lock could be
        acquired, self._lock_file_fd holds the file descriptor
        of the lock file.
        ©ÚNotImplementedErrorr    r   r   r   Ú_acquire¿   s   zBaseFileLock._acquirec                 C   r3   )zH
        Releases the lock and sets self._lock_file_fd to None.
        r4   r    r   r   r   Ú_releaseÇ   s   zBaseFileLock._releasec                 C   s
   | j du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   sV  |du r| j }| j� |  jd7  _W d  ƒ n1 sw   Y  t| ƒ}| j}t ¡ }zY	 | j� | jsAtƒ  d||¡ |  	¡  W d  ƒ n1 sKw   Y  | jr\tƒ  
d||¡ n(|dkrut ¡ | |krutƒ  d||¡ t| jƒ‚tƒ  d|||¡ t |¡ q.W n    | j� td| jd ƒ| _W d  ƒ ‚ 1 s w   Y  ‚ 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.
        Né   Tz#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)   Útimer8   r   Údebugr6   Úinfor   ÚsleepÚmaxr   )r   r+   Úpoll_intervallÚlock_idÚlock_filenameÚ
start_timer   r   r   ÚacquireÛ   sJ   $ÿ€ý
þ
ï

ÿý
zBaseFileLock.acquireFc                 C   sª   | j �H | jr;|  jd8  _| jdks|rCt| ƒ}| j}tƒ  d||¡ |  ¡  d| _tƒ  d||¡ W d  ƒ dS W d  ƒ dS W d  ƒ dS 1 sNw   Y  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.   r8   r/   r;   r)   r   r=   r7   r>   )r   ÚforcerB   rC   r   r   r   r"   %  s(   
ôô
þ÷
ûòzBaseFileLock.releasec                 C   s   |   ¡  | S r   )rE   r    r   r   r   r!   B  ó   zBaseFileLock.__enter__c                 C   s   |   ¡  d S r   ©r"   r#   r   r   r   r'   F  rG   zBaseFileLock.__exit__c                 C   s   | j dd� d S )NT)rF   rH   r    r   r   r   Ú__del__J  s   zBaseFileLock.__del__)r(   )Nr9   )F)r   r   r   r   r   Úpropertyr   r+   Úsetterr6   r7   r8   rE   r"   r!   r'   rI   r   r   r   r   r   �   s$    



		



Jr   c                   @   r   )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 }z	t  | j|¡}W n
 ty   Y d S w z
t |tj	d¡ W n t
tfy8   t  |¡ Y d S w || _d S ©Nr:   )ÚosÚO_RDWRÚO_CREATÚO_TRUNCÚopenr)   ÚOSErrorÚmsvcrtÚlockingÚLK_NBLCKÚIOErrorÚcloser*   ©r   Ú	open_modeÚfdr   r   r   r6   X  s   ÷üzWindowsFileLock._acquirec                 C   sN   | j }d | _ t |tjd¡ t |¡ z	t | j¡ W d S  ty&   Y d S w rL   )	r*   rS   rT   ÚLK_UNLCKrM   rW   Úremover)   rR   ©r   rZ   r   r   r   r7   h  s   
þþzWindowsFileLock._releaseN©r   r   r   r   r6   r7   r   r   r   r   r   R  s    r   c                   @   r   )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|¡}zt |tjtj	B ¡ W n t
tfy-   t  |¡ Y d S w || _d S r   )rM   rN   rO   rP   rQ   r)   ÚfcntlÚflockÚLOCK_EXÚLOCK_NBrV   rR   rW   r*   rX   r   r   r   r6   ~  s   üzUnixFileLock._acquirec                 C   s(   | j }d | _ t |tj¡ t |¡ d S r   )r*   r_   r`   ÚLOCK_UNrM   rW   r]   r   r   r   r7   Š  s
   
zUnixFileLock._releaseNr^   r   r   r   r   r   y  s    r   c                   @   r   )r   z8
    Simply watches the existence of the lock file.
    c              	   C   sN   t jt jB t jB t jB }z	t  | j|¡}W n ttfy!   Y d S w || _	d S r   )
rM   ÚO_WRONLYrO   ÚO_EXCLrP   rQ   r)   rV   rR   r*   rX   r   r   r   r6   �  s   üzSoftFileLock._acquirec                 C   s:   t  | j¡ d | _z	t  | j¡ W d S  ty   Y d S w r   )rM   rW   r*   r\   r)   rR   r    r   r   r   r7   §  s   þþzSoftFileLock._releaseNr^   r   r   r   r   r   ˜  s    
r   z only soft file lock is available)r   r	   rM   r,   r<   ÚwarningsÚImportErrorrS   r_   ÚTimeoutErrorÚ	NameErrorrR   Ú__all__Ú__version__r   r   r   Úobjectr   r   r   r   r   r   Úwarnr   r   r   r   Ú<module>   sZ   ÿÿÿÿ		 R'!ÿ