a
    Ni1                     @   s`  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yF   dZY n0 zddlZW n eyj   dZY n0 zddlZW n ey   dZY n0 ze	 W n e
y   eZ	Y n0 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r8eZn$erDeZneZedur\e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ta t S )z0Returns the logger instance used in this module.)_loggerloggingZ	getLogger__name__ r   r   X/home/james-whalen/.local/share/Steam/steamapps/common/Proton - Experimental/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 	
        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   Z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   s   | 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   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
        )_timeoutr   r   r   r   r'      s    zBaseFileLock.timeoutc                 C   s   t || _dS r   )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NotImplementedErrorr   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.
        Nr/   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   sb  |du r| j }| j |  jd7  _W d   n1 s80    Y  t| }| j}t }z| j. | jst d|| | 	  W d   n1 s0    Y  | jrt 
d|| qqZ|dkrt | |krt d|| t| jqZt d||| t| qZW nH   | j" td| jd | _W d   n1 sF0    Y   Y n0 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   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%   timer3   r   debugr1   infor   sleepmaxr   )r   r'   Zpoll_intervalllock_idlock_filenameZ
start_timer   r   r   acquire   s8    $,&2zBaseFileLock.acquireFc                 C   s   | j n | jrf|  jd8  _| jdks*|rft| }| j}t d|| |   d| _t d|| W d   n1 sz0    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.
        r5   r   z#Attempting to release lock %s on %szLock %s released on %sN)	r*   r3   r+   r6   r%   r   r8   r2   r9   )r   forcer<   r=   r   r   r   r   %  s    .zBaseFileLock.releasec                 C   s   |    | S r   )r>   r   r   r   r   r   B  s    zBaseFileLock.__enter__c                 C   s   |    d S 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$   )Nr4   )F)r
   r   r   r   r   propertyr   r'   setterr1   r2   r3   r>   r   r   r#   rA   r   r   r   r   r      s"   



		


J
r   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   sx   t jt jB t jB }zt | j|}W n ty6   Y n>0 zt|tj	d W n  t
tfyl   t | Y n0 || _d S Nr5   )osO_RDWRO_CREATO_TRUNCopenr%   OSErrormsvcrtlockingZLK_NBLCKIOErrorcloser&   r   Z	open_modefdr   r   r   r1   X  s    zWindowsFileLock._acquirec                 C   sN   | j }d | _ t|tjd t| zt| j W n tyH   Y n0 d S rD   )	r&   rK   rL   ZLK_UNLCKrE   rN   remover%   rJ   r   rP   r   r   r   r2   h  s    
zWindowsFileLock._releaseNr
   r   r   r   r1   r2   r   r   r   r   r   R  s   r   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   sd   t jt jB t jB }t | j|}zt|tjtj	B  W n  t
tfyX   t | Y n0 || _d S r   )rE   rF   rG   rH   rI   r%   fcntlflockLOCK_EXLOCK_NBrM   rJ   rN   r&   rO   r   r   r   r1   ~  s    zUnixFileLock._acquirec                 C   s(   | j }d | _ t|tj t| d S r   )r&   rT   rU   LOCK_UNrE   rN   rR   r   r   r   r2     s
    
zUnixFileLock._releaseNrS   r   r   r   r   r   y  s   r   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   sL   t jt jB t jB t jB }zt | j|}W n ttfy@   Y n0 || _	d S r   )
rE   O_WRONLYrG   O_EXCLrH   rI   r%   rM   rJ   r&   rO   r   r   r   r1     s    zSoftFileLock._acquirec                 C   s:   t | j d | _zt | j W n ty4   Y n0 d S r   )rE   rN   r&   rQ   r%   rJ   r   r   r   r   r2     s    zSoftFileLock._releaseNrS   r   r   r   r   r     s   
r   z only soft file lock is available)r   r	   rE   r(   r7   warningsImportErrorrK   rT   TimeoutError	NameErrorrJ   __all____version__r   r   r   objectr   r   r   r   r   r   warnr   r   r   r   <module>   sN   



		 R'!
