Your IP : 216.73.216.209


Current Path : /lib/python3/dist-packages/lockfile/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/lockfile/__pycache__/__init__.cpython-310.pyc

o

�r^~$�@srdZddlmZddlZddlZddlZddlZddlZeed�s%ej	e_
eejd�s1ejjej_
gd�ZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zdd�Zdd�Zdd �Zd!d"�Zd)d#d$�Zeed%�r�d&d'l m!Z"e"j#Z$e$Z(dSd&d(l m%Z&e&j'Z$e$Z(dS)*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
>>> lock.is_locked()
True
>>> lock.release()

>>> lock = LockFile('somefile')
>>> lock.is_locked()
False
>>> with lock:
...    lock.is_locked()
True
>>> 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...
>>> 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@�eZdZdZdS)rzw
    Base class for other exceptions.

    >>> try:
    ...   raise Error
    ... except Exception:
    ...   pass
    N��__name__�
__module__�__qualname__�__doc__�rr�3/usr/lib/python3/dist-packages/lockfile/__init__.pyrJ�rc@r)rz�
    Base class for error arising from attempts to acquire the lock.

    >>> try:
    ...   raise LockError
    ... except Error:
    ...   pass
    NrrrrrrVrrc@r)rz�Raised when lock creation fails within a user-defined period of time.

    >>> try:
    ...   raise LockTimeout
    ... except LockError:
    ...   pass
    Nrrrrrrb�rc@r)rz�Some other thread/process is locking the file.

    >>> try:
    ...   raise AlreadyLocked
    ... except LockError:
    ...   pass
    Nrrrrrrmrrc@r)r	z�Lock file creation failed for some other reason.

    >>> try:
    ...   raise LockFailed
    ... except LockError:
    ...   pass
    Nrrrrrr	xrr	c@r)r
z�
    Base class for errors arising from attempts to release the lock.

    >>> try:
    ...   raise UnlockError
    ... except Error:
    ...   pass
    Nrrrrrr
�rr
c@r)rz�Raised when an attempt is made to unlock an unlocked file.

    >>> try:
    ...   raise NotLocked
    ... except UnlockError:
    ...   pass
    Nrrrrrr�rrc@r)rz�Raised when an attempt is made to unlock a file someone else locked.

    >>> try:
    ...   raise NotMyLock
    ... except UnlockError:
    ...   pass
    Nrrrrrr�rrc@s>eZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�_SharedBasecCs
||_dS�N)�path)�selfrrrr�__init__�s
z_SharedBase.__init__NcC�td��)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 subclass��NotImplemented)r�timeoutrrr�acquire�sz_SharedBase.acquirecCr!)zX
        Release the lock.

        If the file is not locked, raise NotLocked.
        r"r#�rrrr�release�sz_SharedBase.releasecCs|��|S)�*
        Context manager support.
        )r&r'rrr�	__enter__�sz_SharedBase.__enter__cGs|��dS)r)N)r()r�_excrrr�__exit__�sz_SharedBase.__exit__cCsd|jj|jfS)Nz<%s: %r>)�	__class__rrr'rrr�__repr__�sz_SharedBase.__repr__r)	rrrr r&r(r*r,r.rrrrr�s
rcsBeZdZdZd�fdd�	Zdd�Zdd	�Zd
d�Zdd
�Z�Z	S)rz.Base class for platform-specific lock classes.TNc	s�tt|��|�tj�|�d|_t��|_	t�
�|_|r1t�
�}t|dt|��}d|d@|_nd|_tj�|j�}tj�|d|j	|j|jt|j�f�|_||_dS)zi
        >>> lock = LockBase('somefile')
        >>> lock = LockBase('somefile', threaded=False)
        z.lock�identz-%xl���z	%s%s.%s%sN)�superrr �osr�abspath�	lock_file�socket�gethostname�hostname�getpid�pid�	threadingr�getattr�hash�tname�dirname�join�unique_namer%)rr�threadedr%�tr/r>�r-rrr �s$

	��
zLockBase.__init__cCr!)z9
        Tell whether or not the file is locked.
        r"r#r'rrr�	is_locked��zLockBase.is_lockedcCr!)zA
        Return True if this object is locking the file.
        r"r#r'rrr�i_am_locking�rEzLockBase.i_am_lockingcCr!)zN
        Remove a lock.  Useful if a locking thread failed to unlock.
        r"r#r'rrr�
break_lockrEzLockBase.break_lockcCsd|jj|j|jfS)Nz<%s: %r -- %r>)r-rr@rr'rrrr.s�zLockBase.__repr__)TN)
rrrrr rDrFrGr.�
__classcell__rrrCrr�s!rcOsTtjd|tdd�t|dt�s|dd�}t|�dkr#|s#d|d<||i|��S)Nz1Import from %s module instead of lockfile package�)�
stacklevelr�TrA)�warnings�warn�DeprecationWarning�
isinstance�str�len)�cls�mod�args�kwdsrrr�
_fl_helpers
�rVcO�&ddlm}t|jdg|�Ri|��S)z�Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import LinkLockFile from the
    lockfile.linklockfile module.
    rK��linklockfilezlockfile.linklockfile)r0rYrV�LinkLockFile)rTrUrYrrrr
�
��r
cOrW)z�Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import MkdirLockFile from the
    lockfile.mkdirlockfile module.
    rK��
mkdirlockfilezlockfile.mkdirlockfile)r0r]rV�
MkdirLockFile)rTrUr]rrrr%r[rcOrW)z�Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import SQLiteLockFile from the
    lockfile.mkdirlockfile module.
    rK)�sqlitelockfilezlockfile.sqlitelockfile)r0r_rV�SQLiteLockFile)rTrUr_rrrr0r[rcs��fdd�}|S)aDecorator 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(...):
             ...
    cst������fdd��}|S)Ncs8t��d�}|��z�|i|��W|��S|��w)N)r%)�FileLockr&r()rT�kwargs�lock)�funcrr%rr�wrapperHs
z&locked.<locals>.decor.<locals>.wrapper)�	functools�wraps)rdre�rr%)rdr�decorGszlocked.<locals>.decorr)rr%rirrhrr;s
r�linkrKrXr\r))r�
__future__rrfr2r5r:rL�hasattr�
currentThreadr�Thread�getNamer�__all__�	Exceptionrrrrr	r
rr�objectrrrVr
rrrr0rY�_llfrZ�LockFiler]�_mlfr^rarrrr�<module>sD3
-:

�