/usr/lib/python3/dist-packages/twisted/python/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/python/__pycache__/lockfile.cpython-310.pyc (5138B)
o
bZ @ s d Z ddlZddlZddlmZ ddlmZ dd ZddlmZ e s3ddlm
Z
mZmZ
mZ d Zn0d
ZzddlZddlmZ W n eyL dZ
Y n w dZd
Zdd Z
eZdd Zdd Zdd Z
G dd dZdd ZddgZdS )z&
Filesystem-based interprocess mutex.
N)time)platformc C s t tt d S )Ni )strint_uniquefloat r r 9/usr/lib/python3/dist-packages/twisted/python/lockfile.pyunique s r )rename)killreadlinkremovesymlinkFT)OpenProcess W c
C sj zt dd| W t d tjy4 } z|jd tkr"W Y d }~d S |jd tkr/ttjd d }~ww )Nr z OpenProcess is required to fail.)
r
pywintypeserrorargsERROR_ACCESS_DENIEDERROR_INVALID_PARAMETEROSErrorerrnoESRCHRuntimeError)pidsignaler r r r 4 s r c C s |d t d }tj|d}t| d}t||}|| | W d n1 s0w Y zt|| W dS t yO t
| t| w )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 ospathjoinmkdir_openwriteflushr
BaseExceptionr
rmdir)valuefilenamenewlinkname
newvalnamemodefr r r r E s
r c
C s zt tj| dd}W n ty+ } z|jtjks |jtjkr&t|jd d}~ww |
| }W d |S 1 s>w Y |S )zq
Read the contents of C{filename}. See the above comment block as to why
this is needed.
r rN) r$ r r! r" r r ENOENTEIOread)r* fObjr resultr r r r ` s
r c C s" t t j| d t | d S )Nr )r r
r! r" r( )r* r r r rmlinkr s r5 c @ s0 e Zd ZdZdZdZdd 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.
NFc C s
|| _ d S )N)name)selfr7 r r r __init__ s
zFilesystemLock.__init__c C s d} zt tt | j W n ty } ztr)|jtjtj fv r)W Y d}~dS |jtj
krzt| j}W n2 tyh } z&|jtjkrOW Y d}~W Y d}~qtrc|jtjkrcW Y d}~W Y d}~dS d}~ww z
t
durut
t|d W nK ty } z?|jtjkrzt| j W n# ty } z|jtjkrW Y d}~W Y d}~W Y d}~q d}~ww d}W Y d}~W Y d}~q d}~ww W Y d}~dS d}~ww d| _|| _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}.
TNFr )r r r getpidr7 r _windowsr EACCESr1 EEXISTr r0 r r r r5 lockedclean)r8 r? r r r r r lock sX
+zFilesystemLock.lockc C s@ t | j}t|t krtd| jdt| 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 r7 r r r:
ValueErrorr5 r> )r8 r r r r unlock s
zFilesystemLock.unlock) __name__
__module____qualname____doc__r? r> r9 r@ rB r r r r r6 w s =r6 c C s: t | }d}z| }W |r| | S |r| w w )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)r6 r@ rB )r7 lr4 r r r isLocked s
rH )rF r r r r twisted.python.runtimer r r
isWindowsr r r
r5 r r; r win32apir ImportErrorr r openr$ r6 rH __all__r r r r
s6
f