Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/python/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/python/__pycache__/lockfile.cpython-37.pyc

B

:��]&�@s dZddlmZmZddlZddlZddlmZddlm	Z	ddl
mZdd�Zdd	lm
Z
e	��s�dd
lmZddlmZddlmZdd
lmZdZnbdZyddlmZddlZWnek
r�dZYnXdZdZdd�ZeZdd�Zdd�Zdd�ZGdd�de�Zdd�ZddgZ dS)z&
Filesystem-based interprocess mutex.
�)�absolute_import�divisionN)�time)�platform)�_PY3cCsttt�d��S)Ni�)�str�int�_uniquefloat�r
r
�J/opt/alt/python37/lib64/python3.7/site-packages/twisted/python/lockfile.py�uniquesr)�rename)�kill)�symlink)�readlink)�removeFT)�OpenProcess��Wc
Cspytdd|�WnRtjk
rb}z2|jdtkr6dS|jdtkrPttjd���Wdd}~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�er
r
rr5src	Cs�|dt�d}tj�|d�}t�|�tr4d}nd}t||��}|�|�|��WdQRXyt	||�Wn"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�wZwcN)r�os�path�join�mkdirr�_open�write�flushr
r�rmdir)�value�filenameZnewlinknameZ
newvalname�mode�fr
r
rrEs



rc
Cs�yttj�|d�d�}WnHtk
r`}z*|jtjksB|jtjkrNt|jd���Wdd}~XYnX|�|�	�}WdQRX|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%�IOErrorr�ENOENT�EIOr�read)r,ZfObjr �resultr
r
rrbsrcCs"t�tj�|d��t�|�dS)Nr)r#rr$r%r*)r,r
r
r�rmlinkssr5c@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)�selfr7r
r
r�__init__�szFilesystemLock.__init__cCs�d}�xxyttt���|j�W�nLtk
�rn}�z*trR|jtjtj	fkrRdS|jtj
k�r\yt|j�}WnLttfk
r�}z*|jtj
kr�wntr�|jtjkr�dS�Wdd}~XYnXytdk	r�tt|�d�Wn�tk
�rV}z`|jtjk�rDyt|j�Wn6tk
�r<}z|jtj
k�r*w�Wdd}~XYnXd}w�Wdd}~XYnXdS�Wdd}~XYnXd|_||_dSdS)z�
        Acquire this lock.

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

        @raise: Any exception os.symlink() may raise, other than
        EEXIST.
        TFNr)rrr#�getpidr7r�_windowsr�EACCESr2�EEXISTrr0r1rrrr5�locked�clean)r8r?r rr
r
r�lock�sF
zFilesystemLock.lockcCs>t|j�}t|�t��kr*td|jf��t|j�d|_dS)z�
        Release this lock.

        This deletes the directory with the given name.

        @raise: Any exception os.readlink() may raise, or
        ValueError if the lock is not owned by this process.
        z!Lock %r not owned by this processFN)rr7rr#r:�
ValueErrorr5r>)r8rr
r
r�unlock�s	

zFilesystemLock.unlock)	�__name__�
__module__�__qualname__�__doc__r?r>r9r@rBr
r
r
rr6ys>r6cCs.t|�}d}z|��}Wd|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)r6r@rB)r7�lr4r
r
r�isLocked�s

rH)!rF�
__future__rrrr#rr	Ztwisted.python.runtimerZtwisted.python.compatrrr
Z	isWindowsrrrrr5r;�win32apirr�ImportErrorrr�openr'�objectr6rH�__all__r
r
r
r�<module>s<

j