<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
Pf$                 @   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   /usr/lib/python3.6/__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
    N)r   r   r   r   r   r   r   r   r   V   s   c               @   s   e Zd ZdZdS )r   zRaised when lock creation fails within a user-defined period of time.

    >>> try:
    ...   raise LockTimeout
    ... except LockError:
    ...   pass
    N)r   r   r   r   r   r   r   r   r   b   s   c               @   s   e Zd ZdZdS )r   zSome other thread/process is locking the file.

    >>> try:
    ...   raise AlreadyLocked
    ... except LockError:
    ...   pass
    N)r   r   r   r   r   r   r   r   r   m   s   c               @   s   e Zd ZdZdS )r	   zLock file creation failed for some other reason.

    >>> try:
    ...   raise LockFailed
    ... except LockError:
    ...   pass
    N)r   r   r   r   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
    N)r   r   r   r   r   r   r   r   r
      s   c               @   s   e Zd ZdZdS )r   zRaised when an attempt is made to unlock an unlocked file.

    >>> try:
    ...   raise NotLocked
    ... except UnlockError:
    ...   pass
    N)r   r   r   r   r   r   r   r   r      s   c               @   s   e Zd ZdZdS )r   zRaised when an attempt is made to unlock a file someone else locked.

    >>> try:
    ...   raise NotMyLock
    ... except UnlockError:
    ...   pass
    N)r   r   r   r   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.
        z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.
        zimplement in subclassN)r   )r   r   r   r   release   s    z_SharedBase.releasec             C   s   | j   | S )z*
        Context manager support.
        )r   )r   r   r   r   	__enter__   s    z_SharedBase.__enter__c             G   s   | j   dS )z*
        Context manager support.
        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| j| tjj|d | _tj | _	tj
 | _|rbtj }t|dt|}d|d@  | _nd| _tjj| j}tj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socketZgethostnameZhostnamegetpidpid	threadingr   getattrhashZtnamedirnamejoinunique_namer   )r   r   threadedr   tr$   r/   )r"   r   r   r      s     

	zLockBase.__init__c             C   s   t ddS )z9
        Tell whether or not the file is locked.
        zimplement in subclassN)r   )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.
        zimplement in subclassN)r   )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.
        zimplement in subclassN)r   )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   r1   r   )r   r   r   r   r#     s    zLockBase.__repr__)TN)
r   r   r   r   r   r4   r5   r6   r#   __classcell__r   r   )r"   r   r      s   !c             O   sR   t jd| tdd t|d ts.|dd  }t|dkrH| rHd|d< | ||S )Nz1Import from %s module instead of lockfile package   )
stacklevelr      Tr2   )warningswarnDeprecationWarning
isinstancestrlen)clsmodargskwdsr   r   r   
_fl_helper  s    

rE   c              O   s    ddl m} t|jdf| |S )zFactory function provided for backwards compatibility.

    Do not use in new code.  Instead, import LinkLockFile from the
    lockfile.linklockfile module.
    r:   )linklockfilezlockfile.linklockfile)r%   rF   rE   LinkLockFile)rC   rD   rF   r   r   r   r     s    
c              O   s    ddl m} t|jdf| |S )zFactory function provided for backwards compatibility.

    Do not use in new code.  Instead, import MkdirLockFile from the
    lockfile.mkdirlockfile module.
    r:   )mkdirlockfilezlockfile.mkdirlockfile)r%   rH   rE   MkdirLockFile)rC   rD   rH   r   r   r   r   %  s    
c              O   s    ddl m} t|jdf| |S )zFactory function provided for backwards compatibility.

    Do not use in new code.  Instead, import SQLiteLockFile from the
    lockfile.mkdirlockfile module.
    r:   )sqlitelockfilezlockfile.sqlitelockfile)r%   rJ   rE   ZSQLiteLockFile)rC   rD   rJ   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 j  fdd}|S )Nc           
      s.   t d}|j  z
 | |S |j  X d S )N)r   )FileLockr   r   )rC   kwargslock)funcr   r   r   r   wrapperH  s
    
z&locked.<locals>.decor.<locals>.wrapper)	functoolswraps)rN   rO   )r   r   )rN   r   decorG  s    zlocked.<locals>.decorr   )r   r   rR   r   )r   r   r   r   ;  s    
linkr:   )rF   )rH   )N))r   Z
__future__r   rP   r'   r)   r,   r;   hasattrZcurrentThreadr   ZThreadZgetNamer   __all__	Exceptionr   r   r   r   r	   r
   r   r   objectr   r   rE   r   r   r   r   r%   rF   Z_llfrG   ZLockFilerH   Z_mlfrI   rK   r   r   r   r   <module>4   sF   
-:
