
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
U
    ùýUV›$  ã                   @   s„  d Z 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eedƒsJej	e_
eejdƒsbejjej_dddd	d
ddddddddg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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d„ Zd d„ Zd!d„ Zd"d„ Zd(d#d„Zeed$ƒ�rjd%d&l m!Z" e"j#Z$nd%d'l m%Z& e&j'Z$e$Z(dS ))a  
lockfile.py - Platform-independent advisory file locks.

Requires Python 2.5 unless you apply 2.4.diff
Locking is done on a per-thread basis instead of a per-process basis.

Usage:

>>> lock = LockFile('somefile')
>>> try:
...     lock.acquire()
... except AlreadyLocked:
...     print 'somefile', 'is locked already.'
... except LockFailed:
...     print 'somefile', 'can\'t be locked.'
... else:
...     print 'got lock'
got lock
>>> print lock.is_locked()
True
>>> lock.release()

>>> lock = LockFile('somefile')
>>> print lock.is_locked()
False
>>> with lock:
...    print lock.is_locked()
True
>>> print lock.is_locked()
False

>>> lock = LockFile('somefile')
>>> # It is okay to lock twice from the same thread...
>>> with lock:
...     lock.acquire()
...
>>> # Though no counter is kept, so you can't unlock multiple times...
>>> print lock.is_locked()
False

Exceptions:

    Error - base class for other exceptions
        LockError - base class for all locking exceptions
            AlreadyLocked - Another thread or process already holds the lock
            LockFailed - Lock failed for some other reason
        UnlockError - base class for all unlocking exceptions
            AlreadyUnlocked - File was not locked.
            NotMyLock - File was locked but not by the current thread/process
é    )Úabsolute_importNÚcurrent_threadÚget_nameÚErrorÚ	LockErrorÚLockTimeoutÚAlreadyLockedÚ
LockFailedÚUnlockErrorÚ	NotLockedÚ	NotMyLockÚLinkFileLockÚMkdirFileLockÚSQLiteFileLockÚLockBaseÚlockedc                   @   s   e Zd ZdZdS )r   zw
    Base class for other exceptions.

    >>> try:
    ...   raise Error
    ... except Exception:
    ...   pass
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úB/opt/alt/python38/lib/python3.8/site-packages/lockfile/__init__.pyr   J   s   c                   @   s   e Zd ZdZdS )r   z–
    Base class for error arising from attempts to acquire the lock.

    >>> try:
    ...   raise LockError
    ... except Error:
    ...   pass
    Nr   r   r   r   r   r   V   s   c                   @   s   e Zd ZdZdS )r   z�Raised when lock creation fails within a user-defined period of time.

    >>> try:
    ...   raise LockTimeout
    ... except LockError:
    ...   pass
    Nr   r   r   r   r   r   b   s   c                   @   s   e Zd ZdZdS )r   zˆSome other thread/process is locking the file.

    >>> try:
    ...   raise AlreadyLocked
    ... except LockError:
    ...   pass
    Nr   r   r   r   r   r   m   s   c                   @   s   e Zd ZdZdS )r	   z‡Lock file creation failed for some other reason.

    >>> try:
    ...   raise LockFailed
    ... except LockError:
    ...   pass
    Nr   r   r   r   r   r	   x   s   c                   @   s   e Zd ZdZdS )r
   z™
    Base class for errors arising from attempts to release the lock.

    >>> try:
    ...   raise UnlockError
    ... except Error:
    ...   pass
    Nr   r   r   r   r   r
   ƒ   s   c                   @   s   e Zd ZdZdS )r   z’Raised when an attempt is made to unlock an unlocked file.

    >>> try:
    ...   raise NotLocked
    ... except UnlockError:
    ...   pass
    Nr   r   r   r   r   r   �   s   c                   @   s   e Zd ZdZdS )r   zœRaised when an attempt is made to unlock a file someone else locked.

    >>> try:
    ...   raise NotMyLock
    ... except UnlockError:
    ...   pass
    Nr   r   r   r   r   r   š   s   c                   @   s>   e Zd Zdd„ Zddd„Zdd„ Zdd	„ Zd
d„ Zdd„ ZdS )Ú_SharedBasec                 C   s
   || _ d S )N)Úpath)Úselfr   r   r   r   Ú__init__¦   s    z_SharedBase.__init__Nc                 C   s   t dƒ‚dS )a�  
        Acquire the lock.

        * If timeout is omitted (or None), wait forever trying to lock the
          file.

        * If timeout > 0, try to acquire the lock for that many seconds.  If
          the lock period expires and the file is still locked, raise
          LockTimeout.

        * If timeout <= 0, raise AlreadyLocked immediately if the file is
          already locked.
        úimplement in subclassN©ÚNotImplemented)r   Útimeoutr   r   r   Úacquire©   s    z_SharedBase.acquirec                 C   s   t dƒ‚dS )zX
        Release the lock.

        If the file is not locked, raise NotLocked.
        r   Nr   ©r   r   r   r   Úrelease¹   s    z_SharedBase.releasec                 C   s   |   ¡  | S )ú*
        Context manager support.
        )r!   r"   r   r   r   Ú	__enter__Á   s    z_SharedBase.__enter__c                 G   s   |   ¡  dS )r$   N)r#   )r   Z_excr   r   r   Ú__exit__È   s    z_SharedBase.__exit__c                 C   s   d| j j| jf S )Nz<%s: %r>)Ú	__class__r   r   r"   r   r   r   Ú__repr__Î   s    z_SharedBase.__repr__)N)	r   r   r   r   r!   r#   r%   r&   r(   r   r   r   r   r   ¥   s   
r   c                       sB   e Zd ZdZd‡ fdd„	Zdd„ Zdd	„ Zd
d„ Zdd„ Z‡  Z	S )r   z.Base class for platform-specific lock classes.TNc              	      s¨   t t| ƒ |¡ tj |¡d | _t ¡ | _	t 
¡ | _|rbt ¡ }t|dt|ƒƒ}d|d@  | _nd| _tj | j¡}tj |d| j	| j| jt| jƒf ¡| _|| _dS )zi
        >>> lock = LockBase('somefile')
        >>> lock = LockBase('somefile', threaded=False)
        z.lockÚidentz-%xl   ÿÿ Ú z	%s%s.%s%sN)Úsuperr   r   Úosr   ÚabspathZ	lock_fileÚsocketÚgethostnameÚhostnameÚgetpidÚpidÚ	threadingr   ÚgetattrÚhashÚtnameÚdirnameÚjoinÚunique_namer    )r   r   Úthreadedr    Útr)   r7   ©r'   r   r   r   Ô   s$    

	ýÿzLockBase.__init__c                 C   s   t dƒ‚dS )z9
        Tell whether or not the file is locked.
        r   Nr   r"   r   r   r   Ú	is_lockedõ   s    zLockBase.is_lockedc                 C   s   t dƒ‚dS )zA
        Return True if this object is locking the file.
        r   Nr   r"   r   r   r   Úi_am_lockingû   s    zLockBase.i_am_lockingc                 C   s   t dƒ‚dS )zN
        Remove a lock.  Useful if a locking thread failed to unlock.
        r   Nr   r"   r   r   r   Ú
break_lock  s    zLockBase.break_lockc                 C   s   d| j j| j| jf S )Nz<%s: %r -- %r>)r'   r   r9   r   r"   r   r   r   r(     s    ÿzLockBase.__repr__)TN)
r   r   r   r   r   r=   r>   r?   r(   Ú__classcell__r   r   r<   r   r   Ò   s   !c                 O   sP   t jd| tdd� t|d tƒs.|dd … }t|ƒdkrF|sFd|d< | ||ŽS )Nz1Import from %s module instead of lockfile packageé   )Ú
stacklevelr   é   Tr:   )ÚwarningsÚwarnÚDeprecationWarningÚ
isinstanceÚstrÚlen)ÚclsÚmodÚargsÚkwdsr   r   r   Ú
_fl_helper  s    
 ÿrN   c                  O   s    ddl m} t|jdf| ž|ŽS )z¡Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import LinkLockFile from the
    lockfile.linklockfile module.
    rC   ©Úlinklockfilezlockfile.linklockfile)r*   rP   rN   ÚLinkLockFile)rL   rM   rP   r   r   r   r     s    
ÿÿc                  O   s    ddl m} t|jdf| ž|ŽS )z£Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import MkdirLockFile from the
    lockfile.mkdirlockfile module.
    rC   ©Úmkdirlockfilezlockfile.mkdirlockfile)r*   rS   rN   ÚMkdirLockFile)rL   rM   rS   r   r   r   r   %  s    
ÿÿc                  O   s    ddl m} t|jdf| ž|ŽS )z¤Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import SQLiteLockFile from the
    lockfile.mkdirlockfile module.
    rC   )Úsqlitelockfilezlockfile.sqlitelockfile)r*   rU   rN   ZSQLiteLockFile)rL   rM   rU   r   r   r   r   0  s    
ÿÿc                    s   ‡ ‡fdd„}|S )a  Decorator which enables locks for decorated function.

    Arguments:
     - path: path for lockfile.
     - timeout (optional): Timeout for acquiring lock.

     Usage:
         @locked('/var/run/myname', timeout=0)
         def myname(...):
             ...
    c                    s   t  ˆ ¡‡ ‡‡fdd„ƒ}|S )Nc                     s2   t ˆˆd�}| ¡  zˆ | |ŽW ¢S | ¡  X d S )N)r    )ÚFileLockr!   r#   )rL   ÚkwargsÚlock)Úfuncr   r    r   r   ÚwrapperH  s
    z&locked.<locals>.decor.<locals>.wrapper)Ú	functoolsÚwraps)rY   rZ   ©r   r    )rY   r   ÚdecorG  s    zlocked.<locals>.decorr   )r   r    r^   r   r]   r   r   ;  s    
ÚlinkrC   rO   rR   )N))r   Ú
__future__r   r[   r,   r.   r3   rD   ÚhasattrÚcurrentThreadr   ÚThreadÚgetNamer   Ú__all__Ú	Exceptionr   r   r   r   r	   r
   r   r   Úobjectr   r   rN   r   r   r   r   r*   rP   Z_llfrQ   ZLockFilerS   Z_mlfrT   rV   r   r   r   r   Ú<module>   sT   3
      ý-:
