403Webshell
Server IP : 65.1.209.187  /  Your IP : 216.73.216.144
Web Server : nginx/1.24.0
System : Linux ip-172-31-5-206 6.14.0-1015-aws #15~24.04.1-Ubuntu SMP Tue Sep 23 22:44:48 UTC 2025 x86_64
User :  ( 1001)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/twisted/application/runner/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/twisted/application/runner/test/__pycache__/test_pidfile.cpython-312.pyc
�

oj]2��|�dZddlZddlmZddlmZmZddlm	Z	m
Z
mZddlm
Z
ddlmZddlZddlmZdd	lmZdd
lmZddlmZd
dlmZmZmZmZmZmZmZde
de	fde
de	ffd�ZGd�dej@jBjD�Z#Gd�dej@jBjD�Z$y)z3
Tests for L{twisted.application.runner._pidfile}.
�N)�wraps)�getpid�name)�Any�Callable�Optional)�verifyObject)�NoReturn)�FilePath)�platform)�SkipTest�)�_pidfile�)�AlreadyRunningError�InvalidPIDFileError�IPIDFile�NonePIDFile�
NoPIDFound�PIDFile�StalePIDFileError�f.�returnc	�`��t��dtdtdtdtf�fd��}|S)a=
    Decorator for tests that are not expected to work on all platforms.

    Calling L{PIDFile.isRunning} currently raises L{NotImplementedError} on
    non-POSIX platforms.

    On an unsupported platform, we expect to see any test that calls
    L{PIDFile.isRunning} to raise either L{NotImplementedError}, L{SkipTest},
    or C{self.failureException}.
    (C{self.failureException} may occur in a test that checks for a specific
    exception but it gets NotImplementedError instead.)

    @param f: The test method to decorate.

    @return: The wrapped callable.
    �self�args�kwargsrc���tj�dk(}|r�|g|��i|��S|jtt|j
f�|g|��i|��}t
|t�r*|jt|�jd��yy)N�posixz isRunning is not implemented on )
r�getType�assertRaises�NotImplementedErrorr
�failureException�
isinstance�
assertTrue�str�
startswith)rrr�	supported�ers     ��N/usr/lib/python3/dist-packages/twisted/application/runner/test/test_pidfile.py�wrapperz$ifPlatformSupported.<locals>.wrapper3s�����$�$�&�'�1�	���T�+�D�+�F�+�+�!��!�!�$�h��0E�0E�F�����	�
��A��!�0�1�����A�� 1� 1�2T� U�V�2�)rr)rr+s` r*�ifPlatformSupportedr-!sD���$�1�X�W�c�W�#�W��W��W��W� �Nr,c�&�eZdZdZddeedeefd�Zdd�Z	dd�Z
dd�Zdd	�Zdd
�Z
dd�Zdd�Zdd
�Zdd�Zdd�Zdd�Zedd��Zedd��Zedd��Zedd��Zedd��Zedd��Zdd�Zdd�Zedd��Zedd��Zy)�PIDFileTestsz
    Tests for L{PIDFile}.
    N�contentrc�^�t|j��}|�|j|�|S�N)r�mktemp�
setContent)rr0�filePaths   r*r5zPIDFileTests.filePathLs+���D�K�K�M�*��������(��r,c�V�t|j��}tt|�y)z5
        L{PIDFile} conforms to L{IPIDFile}.
        N)rr5r	r�r�pidFiles  r*�test_interfacezPIDFileTests.test_interfaceRs���$�-�-�/�*���X�w�'r,c�P�|jtjd��d�y)zR
        L{PIDFile._format} returns the expected format when given a PID.
        �9��pids1337
N)�assertEqualr�_format)rs r*�test_formatWithPIDzPIDFileTests.test_formatWithPIDYs��	
������T�2�I�>r,c��d}t|jtj|����}|j||j	��y)zK
        L{PIDFile.read} returns the PID from the given file path.
        r;r<N)rr5r?r>�read�rr=r8s   r*�test_readWithPIDzPIDFileTests.test_readWithPID_s;�����$�-�-����C�(@�A�B������g�l�l�n�-r,c��d}t|jd��}|jt|j�}|jt
|�d|���y)�f
        L{PIDFile.read} raises L{InvalidPIDFileError} when given an empty file
        path.
        r,�#non-integer PID value in PID file: N�rr5r!rrBr>r&�r�pidValuer8r)s    r*�test_readEmptyPIDzPIDFileTests.test_readEmptyPIDisO��
���$�-�-��,�-�����1�7�<�<�@������Q��#F�x�l�!S�Tr,c��d}t|j|��}|jt|j�}|jt
|�d|���y)rFs$foo!rGNrHrIs    r*�test_readWithBogusPIDz"PIDFileTests.test_readWithBogusPIDtsO��
���$�-�-��1�2�����1�7�<�<�@������Q��#F�x�l�!S�Tr,c��t|j��}|jt|j�}|jt
|�d�y)zc
        L{PIDFile.read} raises L{NoPIDFound} when given a non-existing file
        path.
        �PID file does not existN)rr5r!rrBr>r&�rr8r)s   r*�test_readDoesntExistz!PIDFileTests.test_readDoesntExists?��
�$�-�-�/�*�����j�'�,�,�7������Q��!:�;r,c��ddtdtfd�}|jtd|�t	|j��}|j
t|j�}|j|jtj�y)z�
        L{PIDFile.read} re-raises L{OSError} if the associated C{errno} is
        anything other than L{errno.ENOENT}.
        �moderc�6�ttjd��)Nz	I/O error)�OSError�errno�EIO)rSs r*�oopsz>PIDFileTests.test_readOpenRaisesOSErrorNotENOENT.<locals>.oops�s���%�)�)�[�1�1r,�openN)�r)r&r
�patchrrr5r!rUrBr>rVrW)rrXr8�errors    r*�#test_readOpenRaisesOSErrorNotENOENTz0PIDFileTests.test_readOpenRaisesOSErrorNotENOENT�se��	2�s�	2�X�	2�	
�
�
�8�V�T�*��$�-�-�/�*���!�!�'�7�<�<�8��������e�i�i�0r,c��d}t|j��}|j|�|j|j	�|�y)z9
        L{PIDFile._write} stores the given PID.
        i�N)rr5�_writer>rBrCs   r*�
test_writePIDzPIDFileTests.test_writePID�s;�����$�-�-�/�*�����s����������-r,c�x�t|j��}|jt|jd�y)zS
        L{PIDFile._write} raises L{ValueError} when given an invalid PID.
        �burpN)rr5r!�
ValueErrorr_r7s  r*�test_writePIDInvalidz!PIDFileTests.test_writePIDInvalid�s*���$�-�-�/�*�����*�g�n�n�f�=r,c��t|j��}|j�|j|j	�t��y)zT
        L{PIDFile.writeRunningPID} stores the PID for the current process.
        N)rr5�writeRunningPIDr>rBrr7s  r*�test_writeRunningPIDz!PIDFileTests.test_writeRunningPID�s8���$�-�-�/�*�����!����������2r,c��t|jd��}|j|jj��|j	�|j|jj��y)z9
        L{PIDFile.remove} removes the PID file.
        r,N)rr5r%�exists�remove�assertFalser7s  r*�test_removezPIDFileTests.test_remove�sY���$�-�-��,�-������(�(�/�/�1�2���������)�)�0�0�2�3r,c���t|j��}|jd�dtdtddfd�}|j	t
d|�|j
|j��y)zR
        L{PIDFile.isRunning} returns true for a process that does exist.
        r;r=�signalrNc��yr2��r=rns  r*�killz2PIDFileTests.test_isRunningDoesExist.<locals>.kill����r,rr�rr5r_�intr[rr%�	isRunning�rr8rrs   r*�test_isRunningDoesExistz$PIDFileTests.test_isRunningDoesExist�sa��
�$�-�-�/�*�����t��	�c�	�3�	�4�	�	
�
�
�8�V�T�*�����)�)�+�,r,c��t|j��}|j�|j|j	��y)a@
        L{PIDFile.isRunning} returns true for this process (which is running).

        @note: This differs from L{PIDFileTests.test_isRunningDoesExist} in
        that it actually invokes the C{kill} system call, which is useful for
        testing of our chosen method for probing the existence of a process.
        N)rr5rfr%rvr7s  r*�test_isRunningThiszPIDFileTests.test_isRunningThis�s5���$�-�-�/�*�����!�����)�)�+�,r,c���t|j��}|jd�dtdtddfd�}|j	t
d|�|j
t|j�y)z{
        L{PIDFile.isRunning} raises L{StalePIDFileError} for a process that
        does not exist (errno=ESRCH).
        r;r=rnrNc�6�ttjd���NzNo such process�rUrV�ESRCHrqs  r*rrz5PIDFileTests.test_isRunningDoesNotExist.<locals>.kill�����%�+�+�'8�9�9r,rr)	rr5r_rur[rr!rrvrws   r*�test_isRunningDoesNotExistz'PIDFileTests.test_isRunningDoesNotExist�sc���$�-�-�/�*�����t��	:�c�	:�3�	:�4�	:�	
�
�
�8�V�T�*����+�W�->�->�?r,c���t|j��}|jd�dtdtddfd�}|j	t
d|�|j
|j��y)zx
        L{PIDFile.isRunning} returns true for a process that we are not allowed
        to kill (errno=EPERM).
        r;r=rnrNc�6�ttjd��)NzOperation not permitted)rUrV�EPERMrqs  r*rrz3PIDFileTests.test_isRunningNotAllowed.<locals>.kill�s���%�+�+�'@�A�Ar,rrrtrws   r*�test_isRunningNotAllowedz%PIDFileTests.test_isRunningNotAllowed�se���$�-�-�/�*�����t��	B�c�	B�3�	B�4�	B�	
�
�
�8�V�T�*�����)�)�+�,r,c��tdk7rtd��t|j��}|j	d�|j|j
��y)ac
        L{PIDFile.isRunning} returns true for a process that we are not allowed
        to kill (errno=EPERM).

        @note: This differs from L{PIDFileTests.test_isRunningNotAllowed} in
        that it actually invokes the C{kill} system call, which is useful for
        testing of our chosen method for probing the existence of a process
        that we are not allowed to kill.

        @note: In this case, we try killing C{init}, which is process #1 on
        POSIX systems, so this test is not portable.  C{init} should always be
        running and should not be killable by non-root users.
        rzThis test assumes POSIX�N)�SYSTEM_NAMEr
rr5r_r%rvr7s  r*�test_isRunningInitzPIDFileTests.test_isRunningInit�sI���'�!��4�5�5��$�-�-�/�*�����q������)�)�+�,r,c���t|j��}|j�dtdtddfd�}|j	t
d|�|j
t|j�y)z�
        L{PIDFile.isRunning} re-raises L{OSError} if the attached C{errno}
        value from L{os.kill} is not an expected one.
        r=rnrNc�6�ttjd��)NzFile exists)rUrV�EEXISTrqs  r*rrz5PIDFileTests.test_isRunningUnknownErrno.<locals>.kills���%�,�,�
�6�6r,rr)	rr5rfrur[rr!rUrvrws   r*�test_isRunningUnknownErrnoz'PIDFileTests.test_isRunningUnknownErrnosb���$�-�-�/�*�����!�	7�c�	7�3�	7�4�	7�	
�
�
�8�V�T�*����'�7�#4�#4�5r,c�t�t|j��}|j|j��y)zS
        L{PIDFile.isRunning} returns false if the PID file doesn't exist.
        N)rr5rkrvr7s  r*�test_isRunningNoPIDFilez$PIDFileTests.test_isRunningNoPIDFile#s+���$�-�-�/�*������*�*�,�-r,c��t|j��}|j|jj��|5|j	|jj��|j|j
�t��ddd�|j|jj��y#1swY�3xYw)z�
        When used as a context manager, a L{PIDFile} will store the current pid
        on entry, then removes the PID file on exit.
        N)rr5rkrir%r>rBrr7s  r*�test_contextManagerz PIDFileTests.test_contextManager+s���
�$�-�-�/�*������)�)�0�0�2�3�
�	7��O�O�G�,�,�3�3�5�6����W�\�\�^�V�X�6�	7�	
����)�)�0�0�2�3�		7�	7�s
�AC	�	Cc��t|j��}|jd�dtdtddfd�}|j	t
d|�|j
t|j�}|jt|�d�|5|j|j�t��ddd�y#1swYyxYw)	z�
        When used as a context manager, a L{PIDFile} will replace the
        underlying PIDFile rather than raising L{AlreadyRunningError} if the
        contained PID file exists but refers to a non-running PID.
        r;r=rnrNc�6�ttjd��r}r~rqs  r*rrz9PIDFileTests.test_contextManagerDoesntExist.<locals>.killCr�r,rrz'PID file refers to non-existing process)
rr5r_rur[rr!rrvr>r&rBr)rr8rrr)s    r*�test_contextManagerDoesntExistz+PIDFileTests.test_contextManagerDoesntExist9s����$�-�-�/�*�����t��	:�c�	:�3�	:�4�	:�	
�
�
�8�V�T�*����/��1B�1B�C������Q��!J�K�
�	7����W�\�\�^�V�X�6�	7�	7�	7�s�)C�Cc�(�t|j��}|jd�dtdtddfd�}|j	t
d|�|j
|j��|jt|j�y)z�
        When used as a context manager, a L{PIDFile} will raise
        L{AlreadyRunningError} if the there is already a running process with
        the contained PID.
        r;r=rnrNc��yr2rprqs  r*rrz<PIDFileTests.test_contextManagerAlreadyRunning.<locals>.killXrsr,rr)rr5r_rur[rr%rvr!r�	__enter__rws   r*�!test_contextManagerAlreadyRunningz.PIDFileTests.test_contextManagerAlreadyRunningNsx���$�-�-�/�*�����t��	�c�	�3�	�4�	�	
�
�
�8�V�T�*�����)�)�+�,����-�w�/@�/@�Ar,r2�rN)�__name__�
__module__�__qualname__�__doc__r�bytesrr&r5r9r@rDrKrMrQr]r`rdrgrlr-rxrzr�r�r�r�r�r�r�r�rpr,r*r/r/Gs	��������8�C�=��(�?�.�	U�	U�<�1� 	.�>�3�4��-��-��-��-��
@��
@��
-��
-��-��-�,�
6��
6�.�4��7��7�(�B��Br,r/c�H�eZdZdZd
d�Zd
d�Zd
d�Zd
d�Zd
d�Zd
d�Z	d
d	�Z
y)�NonePIDFileTestsz#
    Tests for L{NonePIDFile}.
    Nc�8�t�}tt|�y)z9
        L{NonePIDFile} conforms to L{IPIDFile}.
        N)rr	rr7s  r*r9zNonePIDFileTests.test_interfacegs���-���X�w�'r,c��t�}|jt|j�}|j	t|�d�y)z;
        L{NonePIDFile.read} raises L{NoPIDFound}.
        rON)rr!rrBr>r&rPs   r*�	test_readzNonePIDFileTests.test_readns6���-�����j�'�,�,�7������Q��!:�;r,c��t�}|jt|jd�}|j	|j
t
j�y)zZ
        L{NonePIDFile._write} raises L{OSError} with an errno of L{errno.EPERM}.
        rN)rr!rUr_r>rVr��rr8r\s   r*�
test_writezNonePIDFileTests.test_writews;���-���!�!�'�7�>�>�1�=��������e�k�k�2r,c��t�}|jt|j�}|j	|j
t
j�y)zk
        L{NonePIDFile.writeRunningPID} raises L{OSError} with an errno of
        L{errno.EPERM}.
        N)rr!rUrfr>rVr�r�s   r*rgz%NonePIDFileTests.test_writeRunningPID�s;��
�-���!�!�'�7�+B�+B�C��������e�k�k�2r,c��t�}|jt|j�}|j	|j
t
j�y)zZ
        L{NonePIDFile.remove} raises L{OSError} with an errno of L{errno.EPERM}.
        N)rr!rUrjr>rV�ENOENTr�s   r*rlzNonePIDFileTests.test_remove�s9���-���!�!�'�7�>�>�:��������e�l�l�3r,c�X�t�}|j|j�d�y)z<
        L{NonePIDFile.isRunning} returns L{False}.
        FN)rr>rvr7s  r*�test_isRunningzNonePIDFileTests.test_isRunning�s$���-������*�*�,�e�4r,c�H�t�}|5	ddd�y#1swYyxYw)zo
        When used as a context manager, a L{NonePIDFile} doesn't raise, despite
        not existing.
        N)rr7s  r*r�z$NonePIDFileTests.test_contextManager�s&��
�-��
�	��	�	�	�s��!r�)r�r�r�r�r9r�r�rgrlr�r�rpr,r*r�r�bs*���(�<�3�3�4�5�r,r�)%r�rV�	functoolsr�osrrr��typingrrr�zope.interface.verifyr	r
�twisted.trial.unittest�twisted�twisted.python.filepathr�twisted.python.runtimerr
�runnerrrrrrrrrr-�trial�unittest�TestCaser/r�rpr,r*�<module>r�s����
��*�*�*�.���,�+�+�����#�8�C��H�-�#�(�3��8�2D�#�LXB�7�=�=�)�)�2�2�XB�vA�w�}�}�-�-�6�6�Ar,

Youez - 2016 - github.com/yon3zu
LinuXploit