
    ce0                        d Z ddlZddlZddlZddlZ	 ddlZn# e$ r dZY nw xY w	 ddlZn# e$ r dZY nw xY w	 ddlZn# e$ r dZY nw xY w	 e	 n# e
$ r eZ	Y nw xY wg dZdZ ej        e          Z G d de	          Z G d de          Z G d	 d
e          Z G d de          Z G d de          ZdZereZdS ereZdS eZe ej        d           dS dS )zD
A platform independent file lock that supports the with-statement.
    N)TimeoutBaseFileLockWindowsFileLockUnixFileLockSoftFileLockFileLockz2.0.8c                       e Zd ZdZd Zd ZdS )r   zN
    Raised when the lock could not be acquired in *timeout*
    seconds.
    c                     || _         dS 	
        N)	lock_file)selfr   s     Dlib/python3.11/site-packages/anaconda_navigator/external/filelock.py__init__zTimeout.__init__T   s     #t    c                 :    d                     | j                  }|S )Nz)The file lock '{}' could not be acquired.)formatr   )r   temps     r   __str__zTimeout.__str__[   s    :t~&& 	r   N)__name__
__module____qualname____doc__r   r    r   r   r   r   O   s<               r   r   c                       e Zd 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ZddZd Zd Zd Zd
S )r   z3
    Implements the base class of a file lock.
    c                 n    || _         d| _        || _        t          j                    | _        d| _        dS )r   Nr   )
_lock_file_lock_file_fdtimeout	threadingLock_thread_lock_lock_counter)r   r   r    s      r   r   zBaseFileLock.__init__g   s?     $ "  &N,,
 tr   c                     | j         S )z,
        The path to the lock file.
        )r   r   s    r   r   zBaseFileLock.lock_file   s    
 r   c                     | 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
        )_timeoutr&   s    r   r    zBaseFileLock.timeout   s     }r   c                 .    t          |          | _        dS r   )floatr(   )r   values     r   r    zBaseFileLock.timeout   s     etr   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&   s    r   _acquirezBaseFileLock._acquire   s     "###r   c                     t                      )zH
        Releases the lock and sets self._lock_file_fd to None.
        r-   r&   s    r   _releasezBaseFileLock._release   s     "###r   c                     | 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&   s    r   	is_lockedzBaseFileLock.is_locked   s     !--r   N皙?c                    || j         }| j        5  | xj        dz  c_        ddd           n# 1 swxY w Y   	 t          j                    }	 t	          |           }| j        }| j        5  | j        s0t                              d||           | 	                                 ddd           n# 1 swxY w Y   | j        rt          
                    d||           n|dk    rJt          j                    |z
  |k    r0t                              d||           t          | j                  t                              d|||           t          j        |           nK# t          $ r> | j        5  t          d| j        dz
            | _        ddd           n# 1 swxY w Y    w xY w G d	 d
t                    } ||           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 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.
        N   Tz#Attempting to acquire lock %s on %szLock %s acquired on %sr   z!Timeout on aquiring lock %s on %sz2Lock %s not acquired on %s, waiting %s seconds ...c                        e Zd Zd Zd Zd ZdS ))BaseFileLock.acquire.<locals>.ReturnProxyc                     || _         d S Nlock)r   r<   s     r   r   z2BaseFileLock.acquire.<locals>.ReturnProxy.__init__
  s     	tr   c                     | j         S r:   r;   r&   s    r   	__enter__z3BaseFileLock.acquire.<locals>.ReturnProxy.__enter__  s
    y r   c                 8    | j                                          d S r:   )r<   releaser   exc_type	exc_value	tracebacks       r   __exit__z2BaseFileLock.acquire.<locals>.ReturnProxy.__exit__  s    	!!###tr   N)r   r   r   r   r>   rE   r   r   r   ReturnProxyr8   	  sA          ! ! !    r   rF   r;   )r    r#   r$   timeidr   r3   loggerdebugr/   infor   sleepBaseExceptionmaxobject)r   r    poll_intervall
start_timelock_idlock_filenamerF   s          r   acquirezBaseFileLock.acquire   s   H ?lG  	$ 	$!#	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$	J/T(( $& ( (> (%JGUbccc( ( ( ( ( ( ( ( ( ( ( ( ( ( (
 > 
/KK 8'=QQQ\\dikkJ&>&H&HLL!Dg}]]]!$/222LLLgWdft   J~...'/   	 	 	" D D%(D,>,B%C%C"D D D D D D D D D D D D D D D		
	 
	 
	 
	 
	& 
	 
	 
	 {%%%%s`   .221E" +8B/#E" /B33E" 6B37B*E" "F*3FF*F!	!F*$F!	%F*Fc                 ^   | j         5  | j        r| xj        dz  c_        | j        dk    s|rit          |           }| j        }t
                              d||           |                                  d| _        t
                              d||           ddd           n# 1 swxY w 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.
        r6   r   z#Attempting to release lock %s on %szLock %s released on %sN)	r#   r3   r$   rH   r   rI   rJ   r1   rK   )r   forcerR   rS   s       r   r@   zBaseFileLock.release  s     	R 	R~ 
R""a'""%**e* hhG$(OMLL!FQ^___MMOOO)*D&KK 8'=QQQ	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R ts   BB""B&)B&c                 .    |                                   | S r:   )rT   r&   s    r   r>   zBaseFileLock.__enter__4  s    r   c                 .    |                                   d S r:   r@   rA   s       r   rE   zBaseFileLock.__exit__8  s    tr   c                 2    |                      d           d S )NT)rV   rY   r&   s    r   __del__zBaseFileLock.__del__<  s    4   tr   )r   )Nr4   )F)r   r   r   r   r   propertyr   r    setterr/   r1   r3   rT   r@   r>   rE   r[   r   r   r   r   r   c   s           0   X   X ^  ^$ $ $$ $ $ . . X.Y& Y& Y& Y&v   :        r   r   c                       e Zd ZdZd Zd ZdS )r   ze
    Uses the :func:`msvcrt.locking` function to hard lock the lock file on
    windows systems.
    c                 P   t           j        t           j        z  t           j        z  }	 t          j        | j        |          }	 t          j        |t          j        d           || _	        n;# t          t          f$ r t          j        |           Y nw xY w# t          $ r Y nw xY wd S Nr6   )osO_RDWRO_CREATO_TRUNCopenr   msvcrtlockingLK_NBLCKr   IOErrorOSErrorcloser   	open_modefds      r   r/   zWindowsFileLock._acquireJ  s    I
*RZ7	
	()44B(r6?A666 &("" W%     	 	 	D	 ts#   B  A+ +%BB
B#"B#c                     | j         }d | _         t          j        |t          j        d           t	          j        |           	 t	          j        | j                   n# t          $ r Y nw xY wd S r`   )	r   rf   rg   LK_UNLCKra   rk   remover   rj   r   rn   s     r   r1   zWindowsFileLock._releaseZ  sv    !r6?A...
	Ido&&&&  	 	 	D	ts   A 
A+*A+Nr   r   r   r   r/   r1   r   r   r   r   r   E  s<                r   r   c                       e Zd ZdZd Zd ZdS )r   zR
    Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems.
    c                 F   t           j        t           j        z  t           j        z  }t          j        | j        |          }	 t          j        |t          j        t          j	        z             || _
        n+# t          t          f$ r t          j        |           Y nw xY wd S r:   )ra   rb   rc   rd   re   r   fcntlflockLOCK_EXLOCK_NBr   ri   rj   rk   rl   s      r   r/   zUnixFileLock._acquireq  s    I
*RZ7	WT_i00	$KEMEM9::: "$D ! 	 	 	HRLLLLL	 ts   ,A6 6%BBc                     | j         }d | _         t          j        |t          j                   t	          j        |           d S r:   )r   rv   rw   LOCK_UNra   rk   rr   s     r   r1   zUnixFileLock._release}  s8    !B&&&
tr   Nrs   r   r   r   r   r   m  s<         
 
 
    r   r   c                       e Zd ZdZd Zd ZdS )r   z8
    Simply watches the existence of the lock file.
    c                     t           j        t           j        z  t           j        z  t           j        z  }	 t          j        | j        |          }|| _        n# t          t          f$ r Y nw xY wd S r:   )
ra   O_WRONLYrc   O_EXCLrd   re   r   r   ri   rj   rl   s      r   r/   zSoftFileLock._acquire  sq    K"*,ry82:E		$)44B "$D ! 	 	 	D	 ts   A A+*A+c                     t          j        | j                   d | _        	 t          j        | j                   n# t
          $ r Y nw xY wd S r:   )ra   rk   r   rq   r   rj   r&   s    r   r1   zSoftFileLock._release  s\    
#$$$!	Ido&&&& 	 	 	D	ts   < 
A	A	Nrs   r   r   r   r   r     s<           	 	 	 	 	r   r   z only soft file lock is available)r   loggingra   r!   rG   warningsImportErrorrf   rv   TimeoutError	NameErrorrj   __all____version__	getLoggerr   rI   r   rO   r   r   r   r   r   warnr   r   r   <module>r      s[  :   				     
OOOO   HHHMMMM   FFFLLLL   EEE
LL   LLL
 e
d
d		8	$	$
    l   ([ [ [ [ [6 [ [ [D! ! ! ! !l ! ! !P    <   8    <   @ 	 :HHH
 :HHHH899999 s9    ##, 66? A	A	A AA