????

Your IP : 3.14.141.163


Current Path : /opt/imunify360/venv/lib/python3.11/site-packages/lockfile/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib/python3.11/site-packages/lockfile/__pycache__/__init__.cpython-311.pyc

�

J�Qg�$��N�dZddlmZddlZddlZddlZddlZddlZeed��sej	e_
eejd��sejjej_
gd�ZGd�de��ZGd	�d
e��ZGd�de��ZGd
�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��Zd�Zd�Zd�Zd�Zd$d�Zeed ��rd!d"l m!Z"e"j#Z$n
d!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
>>> 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��eZdZdZdS)rzw
    Base class for other exceptions.

    >>> try:
    ...   raise Error
    ... except Exception:
    ...   pass
    N��__name__�
__module__�__qualname__�__doc__���H/opt/imunify360/venv/lib64/python3.11/site-packages/lockfile/__init__.pyrrJ���������	�Drrc��eZdZdZdS)rz�
    Base class for error arising from attempts to acquire the lock.

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

    >>> try:
    ...   raise LockTimeout
    ... except LockError:
    ...   pass
    Nrrrrrrb���������	�Drrc��eZdZdZdS)r	z�Some other thread/process is locking the file.

    >>> try:
    ...   raise AlreadyLocked
    ... except LockError:
    ...   pass
    Nrrrrr	r	mrrr	c��eZdZdZdS)r
z�Lock file creation failed for some other reason.

    >>> try:
    ...   raise LockFailed
    ... except LockError:
    ...   pass
    Nrrrrr
r
xrrr
c��eZdZdZdS)rz�
    Base class for errors arising from attempts to release the lock.

    >>> try:
    ...   raise UnlockError
    ... except Error:
    ...   pass
    Nrrrrrr�rrrc��eZdZdZdS)rz�Raised when an attempt is made to unlock an unlocked file.

    >>> try:
    ...   raise NotLocked
    ... except UnlockError:
    ...   pass
    Nrrrrrr�rrrc��eZdZdZdS)r
z�Raised when an attempt is made to unlock a file someone else locked.

    >>> try:
    ...   raise NotMyLock
    ... except UnlockError:
    ...   pass
    Nrrrrr
r
�rrr
c�4�eZdZd�Zdd�Zd�Zd�Zd�Zd�ZdS)	�_SharedBasec��||_dS�N)�path)�selfr)s  r�__init__z_SharedBase.__init__�s
����	�	�	rNc� �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*�timeouts  r�acquirez_SharedBase.acquire�s���4�5�5�5rc� �td���)zX
        Release the lock.

        If the file is not locked, raise NotLocked.
        r-r.�r*s r�releasez_SharedBase.release�s���4�5�5�5rc�.�|���|S)�*
        Context manager support.
        )r1r3s r�	__enter__z_SharedBase.__enter__�s��	
�������rc�.�|���dS)r6N)r4)r*�_excs  r�__exit__z_SharedBase.__exit__�s��	
�������rc�2�d|jj�d|j�d�S)N�<�: �>)�	__class__rr)r3s r�__repr__z_SharedBase.__repr__�s ���!�^�4�4�4�d�i�i�i�@�@rr()	rrrr+r1r4r7r:r@rrrr&r&�sx���������6�6�6�6� 6�6�6�������A�A�A�A�Arr&c�<��eZdZdZd	�fd�	Zd�Zd�Zd�Zd�Z�xZ	S)
rz.Base class for platform-specific lock classes.TNc
���tt|���|��tj�|��dz|_tj��|_	tj
��|_|r?tj
��}t|dt|����}d|dzz|_nd|_tj�|j��}tj�||j	�|j�d|j�t|j������|_||_dS)zi
        >>> lock = LockBase('somefile')
        >>> lock = LockBase('somefile', threaded=False)
        z.lock�identz-%xl����.N)�superrr+�osr)�abspath�	lock_file�socket�gethostname�hostname�getpid�pid�	threadingr�getattr�hash�tname�dirname�join�unique_namer0)r*r)�threadedr0�trCrSr?s       �rr+zLockBase.__init__�s
���
	�h����&�&�t�,�,�,������.�.��8����*�,�,��
��9�;�;����	��(�*�*�A��A�w��Q���0�0�E��%�*�"4�5�D�J�J��D�J��'�/�/�$�.�1�1���7�<�<��7;�}�}�7;�z�z�z�7;�x�x�7;�D�I����)H�I�I���
����rc� �td���)z9
        Tell whether or not the file is locked.
        r-r.r3s r�	is_lockedzLockBase.is_locked�����4�5�5�5rc� �td���)zA
        Return True if this object is locking the file.
        r-r.r3s r�i_am_lockingzLockBase.i_am_locking�rZrc� �td���)zN
        Remove a lock.  Useful if a locking thread failed to unlock.
        r-r.r3s r�
break_lockzLockBase.break_lockrZrc�B�d|jj�d|j�d|j�d�S)Nr<r=z -- r>)r?rrUr)r3s rr@zLockBase.__repr__s0���#'�>�#:�#:�#:�D�<L�<L�<L�#'�9�9�9�.�	.r)TN)
rrrrr+rYr\r^r@�
__classcell__)r?s@rrr�s��������8�8�������B6�6�6�6�6�6�6�6�6�.�.�.�.�.�.�.rrc���tjd|ztd���t|dt��s
|dd�}t|��dkr|sd|d<||i|��S)Nz1Import from %s module instead of lockfile package�)�
stacklevelr�TrV)�warnings�warn�DeprecationWarning�
isinstance�str�len)�cls�mod�args�kwdss    r�
_fl_helperros���M�E��K�$��4�4�4�4�
�d�1�g�s�#�#���A�B�B�x��
�4�y�y�A�~�~�d�~���Z���3������rc�:�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.
    rd��linklockfilezlockfile.linklockfile)rDrrro�LinkLockFile)rmrnrrs   rrrsJ���������l�/�1H�%��%�%�%�#�%�%�%rc�:�ddlm}t|jdg|�Ri|��S)z�Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import MkdirLockFile from the
    lockfile.mkdirlockfile module.
    rd��
mkdirlockfilezlockfile.mkdirlockfile)rDrvro�
MkdirLockFile)rmrnrvs   rrr%sJ�� �������m�1�3K�%��%�%�%�#�%�%�%rc�:�ddlm}t|jdg|�Ri|��S)z�Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import SQLiteLockFile from the
    lockfile.mkdirlockfile module.
    rd)�sqlitelockfilezlockfile.sqlitelockfile)rDryro�SQLiteLockFile)rmrnrys   rrr0sJ��!� � � � � ��n�3�5N�%��%�%�%�#�%�%�%rc������fd�}|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(...):
             ...
    c�L���tj������fd���}|S)Nc���t�����}|���	�|i|��|���S#|���wxYw)N)r0)�FileLockr1r4)rm�kwargs�lock�funcr)r0s   ���r�wrapperz&locked.<locals>.decor.<locals>.wrapperHsZ����D�'�2�2�2�D��L�L�N�N�N�
��t�T�,�V�,�,������������������s�A�A)�	functools�wraps)r�r�r)r0s` ��r�decorzlocked.<locals>.decorGsC����	���	�	�	�	�	�	�	�	�
�	�	��rr)r)r0r�s`` rrr;s)����	�	�	�	�	�	��Lr�linkrdrqrur())r�
__future__rr�rGrJrOre�hasattr�
currentThreadr�Thread�getNamer�__all__�	Exceptionrrrr	r
rrr
�objectr&rrorrrrrDrr�_llfrs�LockFilerv�_mlfrwr~rrr�<module>r�s��1�1�f'�&�&�&�&�&�����	�	�	�	�
�
�
�
����������w�y�*�+�+�7�(�6�I���w�y���,�,�9� )� 0� 8�I���!�!�!��		�		�		�		�		�I�		�		�		�		�		�		�		�		��		�		�		�	�	�	�	�	�)�	�	�	�	�	�	�	�	�I�	�	�	�	�	�	�	�	��	�	�	�		�		�		�		�		�%�		�		�		�	�	�	�	�	��	�	�	�	�	�	�	�	��	�	�	�*A�*A�*A�*A�*A�&�*A�*A�*A�Z7.�7.�7.�7.�7.�{�7.�7.�7.�t���%�%�%�%�%�%�%�%�%�����2�7�2�v���"�&�&�&�&�&�&�� �H�H�'�'�'�'�'�'��!�H����r