HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/test/__pycache__/test_lockfile.cpython-38.pyc
U


W[�<�@s�dZddlmZmZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
dZe
��r|ed�dkr|ed	�dkr|d
ZGdd�dej�ZGd
d�dej�ZdS)z'
Tests for L{twisted.python.lockfile}.
�)�absolute_import�divisionN)�unittest)�lockfile)�
requireModule)�platformzwin32api.OpenProcessZ
pywintypeszZOn windows, lockfile.kill is not implemented in the absence of win32api and/or pywintypes.c@speZdZdZdd�Zdd�Ze��s*de_dd�Z	d	d
�Z
e��sHde
_dd
�Zee_dd�Z
ee
_dd�ZdS)�	UtilTestszM
    Tests for the helper functions used to implement L{FilesystemLock}.
    cCs:|��}t�d|�|�ttjd|�}|�|jtj�dS)z�
        L{lockfile.symlink} raises L{OSError} with C{errno} set to L{EEXIST}
        when an attempt is made to create a symlink which already exists.
        �fooN)�mktempr�symlink�assertRaises�OSError�assertEqual�errnoZEEXIST��self�name�exc�r�</usr/lib/python3/dist-packages/twisted/test/test_lockfile.py�test_symlinkEEXISTszUtilTests.test_symlinkEEXISTcCsD|��}dd�}|�td|�|�ttj|d�}|�|jtj�dS)a<
        L{lockfile.symlink} raises L{OSError} with C{errno} set to L{EIO} when
        the underlying L{rename} call fails with L{EIO}.

        Renaming a file on Windows may fail if the target of the rename is in
        the process of being deleted (directory deletion appears not to be
        atomic).
        cSsttjd��dS�N)�IOErrorr�EIO��srcZdstrrr�
fakeRename4sz4UtilTests.test_symlinkEIOWindows.<locals>.fakeRename�renamer	N)	r
�patchrrrrrrr)rrrrrrr�test_symlinkEIOWindows*s
	z UtilTests.test_symlinkEIOWindows�Bspecial rename EIO handling only necessary and correct on Windows.cCs,|��}|�ttj|�}|�|jtj�dS)z�
        L{lockfile.readlink} raises L{OSError} with C{errno} set to L{ENOENT}
        when an attempt is made to read a symlink which does not exist.
        N)r
rr
r�readlinkrrZENOENTrrrr�test_readlinkENOENT?szUtilTests.test_readlinkENOENTcCsB|��}dd�}|�td|�|�ttj|�}|�|jtj�dS)a\
        L{lockfile.readlink} raises L{OSError} with C{errno} set to L{EACCES}
        on Windows when the underlying file open attempt fails with C{EACCES}.

        Opening a file on Windows may fail if the path is inside a directory
        which is in the process of being deleted (directory deletion appears
        not to be atomic).
        cSsttjd��dSr�rr�EACCES)�path�moderrr�fakeOpenSsz6UtilTests.test_readlinkEACCESWindows.<locals>.fakeOpenZ_openN)	r
rrrrr!rrr$)rrr'rrrr�test_readlinkEACCESWindowsIs
	z$UtilTests.test_readlinkEACCESWindows�Gspecial readlink EACCES handling only necessary and correct on Windows.cCst�t��d�dS)z}
        L{lockfile.kill} returns without error if passed the PID of a
        process which exists and signal C{0}.
        rN)r�kill�os�getpid�rrrr�	test_kill^szUtilTests.test_killcCs&|�ttjdd�}|�|jtj�dS)z�
        L{lockfile.kill} raises L{OSError} with errno of L{ESRCH} if
        passed a PID which does not correspond to any process.
        i���rN)rr
rr*rr�ESRCH)rrrrr�test_killESRCHgszUtilTests.test_killESRCHcCs6|�tdd�t�|���}|��|�|���dS)z�
        Verify that when L{lockfile.kill} does end up as None (e.g. on Windows
        without pywin32), it doesn't end up being called and raising a
        L{TypeError}.
        r*N)rr�FilesystemLockr
�lock�assertFalse)rZflrrr�test_noKillCallrszUtilTests.test_noKillCallN)�__name__�
__module__�__qualname__�__doc__rrr�	isWindows�skipr"r(r.�skipKillr0r4rrrrrs �
�rc@s�eZdZdd�Zdd�Zdd�Ze��r.de_dd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Ze��slde_dd�Ze��s�de_dd�Zdd�Zdd�Ze��r�de_dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(S))�LockingTestscsL�fdd�}|�td|�|��}t�|�}|�t|j�}|�|j��dS)Ncst�d��dSr)r
)�source�dest�rrr�fakeSymlink�sz3LockingTests._symlinkErrorTest.<locals>.fakeSymlinkr)	rrr
r1rr
r2rr)rrr@�lockfr2rrr?r�_symlinkErrorTest�s
zLockingTests._symlinkErrorTestcCs|�tj�dS)z�
        An exception raised by C{symlink} other than C{EEXIST} is passed up to
        the caller of L{FilesystemLock.lock}.
        N)rBr�ENOSYSr-rrr�test_symlinkError�szLockingTests.test_symlinkErrorcCs|�tj�|�tj�dS)a 
        An L{OSError} raised by C{symlink} on a POSIX platform with an errno of
        C{EACCES} or C{EIO} is passed to the caller of L{FilesystemLock.lock}.

        On POSIX, unlike on Windows, these are unexpected errors which cannot
        be handled by L{FilesystemLock}.
        N)rBrr$rr-rrr�test_symlinkErrorPOSIX�sz#LockingTests.test_symlinkErrorPOSIXz9POSIX-specific error propagation not expected on Windows.cCs<|��}t�|�}|�|���|�|j�|�|j�dS)z�
        If the lock has never been held, it can be acquired and the C{clean}
        and C{locked} attributes are set to C{True}.
        N)r
rr1�
assertTruer2�clean�locked�rrAr2rrr�test_cleanlyAcquire�s

z LockingTests.test_cleanlyAcquirecCsh|��}t�|�}|�|���|��|�|j�t�|�}|�|���|�|j�|�|j�dS)z�
        If a lock is released cleanly, it can be re-acquired and the C{clean}
        and C{locked} attributes are set to C{True}.
        N)	r
rr1rFr2�unlockr3rHrGrIrrr�test_cleanlyRelease�s

z LockingTests.test_cleanlyReleasecCsH|��}t�|�}|�|���t�|�}|�|���|�|j�dS)zK
        If a lock is currently locked, it cannot be locked again.
        N)r
rr1rFr2r3rH)rrAZ	firstLockZ
secondLockrrr�test_cannotLockLocked�s

z"LockingTests.test_cannotLockLockedcs�d��fdd�}|��}|�td|�t�t��|�t�|�}|�|���|�|j	�|�|j
�|�t�|�tt
����dS)z�
        If a lock was held by a process which no longer exists, it can be
        acquired, the C{clean} attribute is set to C{False}, and the
        C{locked} attribute is set to C{True}.
        i90cs,|dkrttjd��|�kr(ttjd��dS)Nr�r
r�EPERMr/��pid�signal��ownerrr�fakeKill�sz4LockingTests.test_uncleanlyAcquire.<locals>.fakeKillr*N)r
rrr�strr1rFr2r3rGrHrr!r+r,)rrUrAr2rrSr�test_uncleanlyAcquire�s
z"LockingTests.test_uncleanlyAcquirecs~��fdd�}|�td|��dd�}|�td|�|���t���}t�td���|�|���|�|j�|�|j	�dS)	z�
        If the lock is initially held but then released before it can be
        examined to determine if the process which held it still exists, it is
        acquired and the C{clean} and C{locked} attributes are set to C{True}.
        cst������t�|�Sr)r�rmlink�restorer!�r�rAZ
readlinkPatchrr�fakeReadlink�s
z?LockingTests.test_lockReleasedBeforeCheck.<locals>.fakeReadlinkr!cSs,|dkrttjd��|dkr(ttjd��dS�Nr�u�rNrPrrrrU�sz;LockingTests.test_lockReleasedBeforeCheck.<locals>.fakeKillr*r^N�
rrr
r1rrVrFr2rGrH)rr\rUr2rr[r�test_lockReleasedBeforeCheck�s
z)LockingTests.test_lockReleasedBeforeCheckcCsFdd�}|�td|�|��}t�|�}|�|���|�|j�dS)a�
        If the lock is released while an attempt is made to acquire
        it, the lock attempt fails and C{FilesystemLock.lock} returns
        C{False}.  This can happen on Windows when L{lockfile.symlink}
        fails with L{IOError} of C{EIO} because another process is in
        the middle of a call to L{os.rmdir} (implemented in terms of
        RemoveDirectory) which is not atomic.
        cSsttjd��dSr)r
rrrrrrr@szGLockingTests.test_lockReleasedDuringAcquireSymlink.<locals>.fakeSymlinkrN)rrr
r1r3r2rH)rr@rAr2rrr�%test_lockReleasedDuringAcquireSymlinks	
z2LockingTests.test_lockReleasedDuringAcquireSymlinkr cCsVdd�}|�td|�|��}t�|�}t�td�|�|�|���|�|j�dS)z�
        If the lock is initially held but is released while an attempt
        is made to acquire it, the lock attempt fails and
        L{FilesystemLock.lock} returns C{False}.
        cSsttjd��dSrr#rZrrrr\#szILockingTests.test_lockReleasedDuringAcquireReadlink.<locals>.fakeReadlinkr!r^N)	rrr
r1rrVr3r2rH)rr\rAr2rrr�&test_lockReleasedDuringAcquireReadlinks
z3LockingTests.test_lockReleasedDuringAcquireReadlinkr)csj��fdd�}|�td|�|��}t�td�|�t�|�}|��|j�}|�|j	��|�
|j�dS)Ncs��d��dSrrrZ�r�
exceptionTyperrr\6sz5LockingTests._readlinkErrorTest.<locals>.fakeReadlinkr!r^)rrr
rrVr1rr2rrr3rH)rrdrr\rAr2rrrcr�_readlinkErrorTest5s
zLockingTests._readlinkErrorTestcCs |�ttj�|�ttj�dS)z�
        An exception raised by C{readlink} other than C{ENOENT} is passed up to
        the caller of L{FilesystemLock.lock}.
        N)rer
rrCrr-rrr�test_readlinkErrorEszLockingTests.test_readlinkErrorcCs |�ttj�|�ttj�dS)z�
        Any L{IOError} raised by C{readlink} on a POSIX platform passed to the
        caller of L{FilesystemLock.lock}.

        On POSIX, unlike on Windows, these are unexpected errors which cannot
        be handled by L{FilesystemLock}.
        N)rerrrCr$r-rrr�test_readlinkErrorPOSIXNsz$LockingTests.test_readlinkErrorPOSIXcs~��fdd�}|�td|��dd�}|�td|�|���t���}t�td���|�|���|�|j�|�|j	�dS)	z�
        If a second process cleans up the lock after a first one checks the
        lock and finds that no process is holding it, the first process does
        not fail when it tries to clean up the lock.
        cs���t���t�|�Sr)rYrrXrZ�rAZrmlinkPatchrr�
fakeRmlinkcs
z?LockingTests.test_lockCleanedUpConcurrently.<locals>.fakeRmlinkrXcSs,|dkrttjd��|dkr(ttjd��dSr]rNrPrrrrUksz=LockingTests.test_lockCleanedUpConcurrently.<locals>.fakeKillr*r^Nr_)rrirUr2rrhr�test_lockCleanedUpConcurrently]s
z+LockingTests.test_lockCleanedUpConcurrentlycCs|dd�}|�td|�dd�}|�td|�|��}t�td�|�t�|�}|�t|j�}|�	|j
t
j�|�|j
�dS)	z�
        An exception raised by L{rmlink} other than C{ENOENT} is passed up
        to the caller of L{FilesystemLock.lock}.
        cSsttjd��dSr)r
rrCrZrrrrisz1LockingTests.test_rmlinkError.<locals>.fakeRmlinkrXcSs,|dkrttjd��|dkr(ttjd��dSr]rNrPrrrrU�sz/LockingTests.test_rmlinkError.<locals>.fakeKillr*r^N)rrr
rrVr1rr
r2rrrCr3rH)rrirUrAr2rrrr�test_rmlinkErrorzs
zLockingTests.test_rmlinkErrorcCsfdd�}|�td|�|��}t�td�|�t�|�}|�t|j�}|�	|j
t
j�|�|j
�dS)z�
        If L{kill} raises an exception other than L{OSError} with errno set to
        C{ESRCH}, the exception is passed up to the caller of
        L{FilesystemLock.lock}.
        cSsttjd��dSr)r
rrOrPrrrrU�sz-LockingTests.test_killError.<locals>.fakeKillr*r^N)rrr
rrVr1rr
r2rrrOr3rH)rrUrAr2rrrr�test_killError�s
zLockingTests.test_killErrorcCs<|��}t�tt��d�|�t�|�}|�t|j	�dS)z�
        L{FilesystemLock.unlock} raises L{ValueError} if called for a lock
        which is held by a different process.
        �N)
r
rrrVr+r,r1r�
ValueErrorrKrIrrr�test_unlockOther�s
zLockingTests.test_unlockOthercCs\|��}|�t�|��t�|�}|�|���|�t�|��|��|�t�|��dS)zp
        L{isLocked} returns C{True} if the named lock is currently locked,
        C{False} otherwise.
        N)r
r3rZisLockedr1rFr2rKrIrrr�
test_isLocked�s
zLockingTests.test_isLockedN)r5r6r7rBrDrErr9r:rJrLrMrWr`rarbrerfrgrjrkrlrorprrrrr<s<
�
��	
�r<)r8Z
__future__rrrr+Z
twisted.trialrZtwisted.pythonrZtwisted.python.reflectrZtwisted.python.runtimerr;r9ZTestCaserr<rrrr�<module>s
�d