
    dI(                    x   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ d dlmZ d dlmZmZ ddlmZ er"d dlZd d	lmZ ej        d
k    rd dlmZ nd dlmZ  ej        d          Z G d d          Ze G d d                      Z G d dee          Z G d deej                  ZddgZ dS )    )annotationsN)ABCabstractmethod)	dataclass)local)TYPE_CHECKINGAny   )Timeout)TracebackType)      )Selffilelockc                  *    e Zd ZdZddZddZddZdS )AcquireReturnProxyzDA context aware object that will release the lock file when exiting.lockBaseFileLockreturnNonec                    || _         d S Nr   )selfr   s     Q/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/filelock/_api.py__init__zAcquireReturnProxy.__init__"   s    			    c                    | j         S r   r   r   s    r   	__enter__zAcquireReturnProxy.__enter__%   s
    yr   exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | Nonec                8    | j                                          d S r   )r   releaser   r!   r#   r%   s       r   __exit__zAcquireReturnProxy.__exit__(   s     		r   N)r   r   r   r   )r   r   r!   r"   r#   r$   r%   r&   r   r   )__name__
__module____qualname____doc__r   r    r*    r   r   r   r      sV        NN           r   r   c                  N    e Zd ZU dZded<   ded<   ded<   dZd	ed
<   dZded<   dS )FileLockContextzBA dataclass which holds the context for a ``BaseFileLock`` object.str	lock_filefloattimeoutintmodeNz
int | Nonelock_file_fdr   lock_counter)r,   r-   r.   r/   __annotations__r9   r:   r0   r   r   r2   r2   1   s_         LL NNN NNN III  $L#### Lr   r2   c                      e Zd ZdZdS )ThreadLocalFileContextz8A thread local version of the ``FileLockContext`` class.N)r,   r-   r.   r/   r0   r   r   r=   r=   H   s        BBBBr   r=   c                     e Zd ZdZ	 	 	 d1d2dZd3dZed4d            Zed5d            Zej	        d6d            Ze
d7d            Ze
d7d            Zed3d            Zed8d            Z	 	 d9dddd:d#Zd;d<d&Zd=d(Zd>d/Zd7d0ZdS )?r   z+Abstract base class for a file lock object.  Tr4   str | os.PathLike[str]r6   r5   r8   r7   thread_localboolr   r   c                z    || _         t          j        |          ||d} |rt          nt          di || _        dS )a  
        Create a new lock object.

        :param lock_file: path to the file
        :param timeout: default timeout when acquiring the lock, in seconds. 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.
        :param mode: file permissions for the lockfile.
        :param thread_local: Whether this object's internal context should be thread local or not.
        If this is set to ``False`` then the lock will be reentrant across threads.
        )r4   r6   r8   Nr0   )_is_thread_localosfspathr=   r2   _context)r   r4   r6   r8   rB   kwargss         r   r   zBaseFileLock.__init__O   sX    $ !-
 9--"
 "

 +fL*e*@*@Ve)p)pio)p)pr   c                    | j         S )z>:return: a flag indicating if this lock is thread local or not)rE   r   s    r   is_thread_localzBaseFileLock.is_thread_locall   s    $$r   r3   c                    | j         j        S )z:return: path to the lock file)rH   r4   r   s    r   r4   zBaseFileLock.lock_filep   s     }&&r   c                    | j         j        S )za
        :return: the default timeout value, in seconds

        .. versionadded:: 2.0.0
        )rH   r6   r   s    r   r6   zBaseFileLock.timeoutu   s     }$$r   valuefloat | strc                8    t          |          | j        _        dS )zd
        Change the default timeout value.

        :param value: the new value, in seconds
        N)r5   rH   r6   )r   rN   s     r   r6   zBaseFileLock.timeout~   s     !&er   c                    t           )zjIf the file lock could be acquired, self._context.lock_file_fd holds the file descriptor of the lock file.NotImplementedErrorr   s    r   _acquirezBaseFileLock._acquire   
     "!r   c                    t           )z>Releases the lock and sets self._context.lock_file_fd to None.rR   r   s    r   _releasezBaseFileLock._release   rU   r   c                    | j         j        duS )z

        :return: A boolean indicating if the lock file is holding the lock currently.

        .. versionchanged:: 2.0.0

            This was previously a method and is now a property.
        N)rH   r9   r   s    r   	is_lockedzBaseFileLock.is_locked   s     })55r   c                    | j         j        S )zP:return: The number of times this lock has been acquired (but not yet released).)rH   r:   r   s    r   r:   zBaseFileLock.lock_counter   s     }))r   N皙?)poll_intervallblockingfloat | Nonepoll_intervalr\   r]   r   c                  || j         j        }| d}t          j        |t          d           |}| j         xj        dz  c_        t          |           }| j        }t          j	                    }	 	 | j
        s0t                              d||           |                                  | j
        rt                              d||           n|d	u r+t                              d
||           t          |          d|cxk    rt          j	                    |z
  k     r.n n+t                              d||           t          |          d}t                              ||||           t          j        |           n6# t           $ r) t#          d| j         j        dz
            | j         _         w xY wt%          |           S )a_  
        Try to acquire the file lock.

        :param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and
         if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired
        :param poll_interval: interval of trying to acquire the lock file
        :param poll_intervall: deprecated, kept for backwards compatibility, use ``poll_interval`` instead
        :param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the
         first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired.
        :raises Timeout: if fails to acquire lock within the timeout period
        :return: a context object that will unlock the file when the context is exited

        .. 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()

        .. 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.

        Nz+use poll_interval instead of poll_intervall   )
stacklevelr
   Tz#Attempting to acquire lock %s on %szLock %s acquired on %sFz+Failed to immediately acquire lock %s on %sr   z"Timeout on acquiring lock %s on %sz2Lock %s not acquired on %s, waiting %s seconds ...r   )rH   r6   warningswarnDeprecationWarningr:   idr4   timeperf_counterrY   _LOGGERdebugrT   r   sleepBaseExceptionmaxr   )	r   r6   r_   r\   r]   msglock_idlock_filename
start_times	            r   acquirezBaseFileLock.acquire   s   P ?m+G%?CM#1a@@@@*M 	""a'""T((&((
	*~ $MM"GR_```MMOOO> MM":G]SSSu$$MM"OQXZghhh!-000BBBB$"3"5"5
"BBBBBBMM"FQ^___!-000Jc7M=III
=)))*   	 	 	),Q0JQ0N)O)ODM&	 "t,,,,s   0DF   3F3Fforcec                F   | j         r| j        xj        dz  c_        | j        j        dk    s|rrt          |           | j        }}t
                              d||           |                                  d| j        _        t
                              d||           dS dS dS )a*  
        Releases the file lock. Please note, that the lock is only completely released, if the lock counter is 0. Also
        note, that the lock file itself is not automatically deleted.

        :param 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)rY   rH   r:   rf   r4   ri   rj   rW   )r   rs   ro   rp   s       r   r(   zBaseFileLock.release   s     > 		PM&&!+&&})Q..%.)+D4>CWm\\\-.*6OOOOO		P 		P /.r   r   c                .    |                                   | S )zE
        Acquire the lock.

        :return: the lock object
        )rr   r   s    r   r    zBaseFileLock.__enter__   s     	r   r!   r"   r#   r$   r%   r&   c                .    |                                   dS )z
        Release the lock.

        :param exc_type: the exception type if raised
        :param exc_value: the exception value if raised
        :param traceback: the exception traceback if raised
        Nr(   r)   s       r   r*   zBaseFileLock.__exit__	  s     	r   c                2    |                      d           dS )z'Called when the lock object is deleted.T)rs   Nrw   r   s    r   __del__zBaseFileLock.__del__  s    4     r   )r?   r@   T)
r4   rA   r6   r5   r8   r7   rB   rC   r   r   )r   rC   )r   r3   )r   r5   )rN   rO   r   r   )r   r   )r   r7   )Nr[   )
r6   r^   r_   r5   r\   r^   r]   rC   r   r   )F)rs   rC   r   r   )r   r   r+   )r,   r-   r.   r/   r   rK   propertyr4   r6   setterr   rT   rW   rY   r:   rr   r(   r    r*   ry   r0   r   r   r   r   L   s       55
 !q q q q q:% % % % ' ' ' X' % % % X% ^- - - ^- " " " ^" " " " ^" 	6 	6 	6 X	6 * * * X* !%#J-
 (,J- J- J- J- J- J-XP P P P P$      ! ! ! ! ! !r   r   )!
__future__r   
contextlibloggingrF   rg   rc   abcr   r   dataclassesr   	threadingr   typingr   r	   _errorr   systypesr   version_infor   typing_extensions	getLoggerri   r   r2   r=   ContextDecoratorr   __all__r0   r   r   <module>r      s   " " " " " "      				   # # # # # # # # ! ! ! ! ! !       % % % % % % % %       +JJJ######
7""****** '
J
'
'       $        ,C C C C C_e C C CN! N! N! N! N!3
3 N! N! N!d r   