HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/twisted/python/__pycache__/lockfile.cpython-38.pyc
U

�bZ�@s�dZddlZddlZddlmZddlmZdd�ZddlmZe�	�sfddlm
Z
mZmZ
mZd	Znbd
ZzddlZddlmZWnek
r�dZ
YnXdZd
Zdd�Z
eZdd�Zdd�Zdd�Z
Gdd�d�Zdd�ZddgZdS)z&
Filesystem-based interprocess mutex.
�N)�time)�platformcCsttt�d��S)Ni�)�str�int�_uniquefloat�rr�9/usr/lib/python3/dist-packages/twisted/python/lockfile.py�uniquesr	)�rename)�kill�readlink�remove�symlinkFT)�OpenProcess��Wc
Csvztdd|�WnXtjk
rh}z8|jdtkr<WY�$dS|jdtkrVttjd���W5d}~XYn
Xt	d��dS)Nrz OpenProcess is required to fail.)
r�
pywintypes�error�args�ERROR_ACCESS_DENIED�ERROR_INVALID_PARAMETER�OSError�errno�ESRCH�RuntimeError)�pid�signal�errrr4s
rc	Cs�|dt�d}tj�|d�}t�|�d}t||��}|�|�|��W5QRXzt||�Wn*t	k
r�t�
|�t�|��YnXdS)z�
        Write a file at C{filename} with the contents of C{value}. See the
        above comment block as to why this is needed.
        �.z.newlinkr�wN)r	�os�path�join�mkdir�_open�write�flushr
�
BaseExceptionr
�rmdir)�value�filenameZnewlinknameZ
newvalname�mode�frrrrEs



rc
Cs�zttj�|d�d�}WnHtk
r`}z*|jtjksB|jtjkrNt|jd���W5d}~XYnX|�|��}W5QRX|SdS)zq
        Read the contents of C{filename}. See the above comment block as to why
        this is needed.
        r�rN)	r$r r!r"rr�ENOENT�EIO�read)r*ZfObjr�resultrrrr`srcCs"t�tj�|d��t�|�dS)Nr)r r
r!r"r()r*rrr�rmlinkrsr2c@s0eZdZdZdZdZdd�Zdd�Zdd	�ZdS)
�FilesystemLocka
    A mutex.

    This relies on the filesystem property that creating
    a symlink is an atomic operation and that it will
    fail if the symlink already exists.  Deleting the
    symlink will release the lock.

    @ivar name: The name of the file associated with this lock.

    @ivar clean: Indicates whether this lock was released cleanly by its
        last owner.  Only meaningful after C{lock} has been called and
        returns True.

    @ivar locked: Indicates whether the lock is currently held by this
        object.
    NFcCs
||_dS)N)�name)�selfr4rrr�__init__�szFilesystemLock.__init__cCs�d}zttt���|j�W�n�tk
�r�}�zltrV|jtjtj	fkrVWY��NdS|jtj
k�r�zt|j�}Wnbtk
r�}zD|jtjkr�WY�2WY��qn tr�|jtjkr�WY�WY��dS�W5d}~XYnXzt
dk	r�t
t|�d�Wn�tk
�r�}z~|jtjk�r|zt|j�WnHtk
�rh}z(|jtjk�rVWY�WY�4WY�Lq�W5d}~XYnXd}WY�WY�&q�W5d}~XYnXWY�
dS�W5d}~XYnXd|_||_dS)z�
        Acquire this lock.

        @rtype: C{bool}
        @return: True if the lock is acquired, false otherwise.

        @raise OSError: Any exception L{os.symlink()} may raise,
            other than L{errno.EEXIST}.
        TFNr)rrr �getpidr4r�_windowsrZEACCESr/�EEXISTrr.rrrr2�locked�clean)r5r;rrrrr�lock�sD

zFilesystemLock.lockcCs@t|j�}t|�t��kr,td|j�d���t|j�d|_dS)z�
        Release this lock.

        This deletes the directory with the given name.

        @raise OSError: Any exception L{os.readlink()} may raise.
        @raise ValueError: If the lock is not owned by this process.
        zLock z not owned by this processFN)rr4rr r7�
ValueErrorr2r:)r5rrrr�unlock�s
	

zFilesystemLock.unlock)	�__name__�
__module__�__qualname__�__doc__r;r:r6r<r>rrrrr3ws=r3cCs.t|�}d}z|��}W5|r&|��X|S)z�
    Determine if the lock of the given name is held or not.

    @type name: C{str}
    @param name: The filesystem path to the lock to test

    @rtype: C{bool}
    @return: True if the lock is held, False otherwise.
    N)r3r>r<)r4�lr1rrr�isLocked�s

rD)rBrr rr�twisted.python.runtimerr	r
�	isWindowsrrr
r2rr8r�win32apir�ImportErrorrr�openr$r3rD�__all__rrrr�<module>s2

f