AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_process.cpython-310.pyc
o

�b|��@s$dZddlZddlZddlZddlZddlZddlZddlmZddl	Z	ddl
Z
ddlmZddl
mZmZmZddlmZmZddlmZmZddlmZdd	lmZdd
lmZddlmZmZddl m!Z!m"Z"dd
l#m$Z$ddl%m&Z&eej'��(�Z)ee
j*��+��+�Z,dZ-dZ.e/ej0�Z1ej2�3ej4�e1d<zddl5Z6ddlm7Z8e�9�dkr�dZ-dZ.Wne:y�dZ5dZ7dZ-dZ.Ynwe6Z5e8Z7dd�Z;Gdd�de�Z<Gdd�de�Z=Gdd�de=�Z>e?��@e>�A��Gdd�de=�ZBe?��@eB�A��Gd d!�d!e&�ZCGd"d#�d#e&�ZDGd$d%�d%e&�ZEdS)&z�
Tests for implementations of L{IReactorProcess}.

@var properEnv: A copy of L{os.environ} which has L{bytes} keys/values on POSIX
    platforms and native L{str} keys/values on Windows.
�N)�skipIf)�utils)�Deferred�inlineCallbacks�succeed)�ProcessDone�ProcessTerminated)�IProcessTransport�IReactorProcess)�ProcessProtocol)�ReactorBuilder)�
networkString)�FilePath�_asFilesystemBytes)�err�msg)�platform)�TestCaseF��
PYTHONPATH��processTz$Cannot change UID/GID except as rootz Cannot change UID/GID on WindowscCstdurd|_|S)z�
    Only run this test on POSIX platforms.

    @param testMethod: A test function, being decorated.

    @return: the C{testMethod} argument.
    Nz%Test only applies to POSIX platforms.)�resource�skip)�
testMethod�r�D/usr/lib/python3/dist-packages/twisted/internet/test/test_process.py�onlyOnPOSIX=src@s(eZdZdZdd�Zdd�Zdd�ZdS)	� _ShutdownCallbackProcessProtocolz�
    An L{IProcessProtocol} which fires a Deferred when the process it is
    associated with ends.

    @ivar received: A C{dict} mapping file descriptors to lists of bytes
        received from the child process on those file descriptors.
    cCs||_i|_dS�N)�whenFinished�received)�selfr rrr�__init__Ss
z)_ShutdownCallbackProcessProtocol.__init__cCs|j�|g��|�dSr)r!�
setdefault�append)r"�fd�bytesrrr�childDataReceivedW�z2_ShutdownCallbackProcessProtocol.childDataReceivedcCs|j�d�dSr)r �callback�r"�reasonrrr�processEndedZ�z-_ShutdownCallbackProcessProtocol.processEndedN)�__name__�
__module__�__qualname__�__doc__r#r(r-rrrrrJs
rc@s�eZdZdZegZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zee
edd�dud�dd��Zdd�Zdd�Zedd��Zedd��Zdd�Zdd�Zeee�dd ��Zeee�d!d"��Zd#d$�ZdS)%�ProcessTestsBuilderBasez�
    Base class for L{IReactorProcess} tests which defines some tests which
    can be applied to PTY or non-PTY uses of C{spawnProcess}.

    Subclasses are expected to set the C{usePTY} attribute to C{True} or
    C{False}.
    cs`t�}t|�}|����j|ttddg|jd�}|�t�|��|�	�fdd��|�
��dS)z�
        L{IReactorProcess.spawnProcess} connects the protocol passed to it
        to a transport which provides L{IProcessTransport}.
        �-c���usePTYc����Sr��stop��ignored��reactorrr�<lambda>��zHProcessTestsBuilderBase.test_processTransportInterface.<locals>.<lambda>N)rr�buildReactor�spawnProcess�pyExer7�
assertTruer	�
providedBy�addCallback�
runReactor)r"�ended�protocol�	transportrr=r�test_processTransportInterfaceis�z6ProcessTestsBuilderBase.test_processTransportInterfacecs~|���t�}t|��dttj��d������fdd�}��|�|��fdd��|���|�	�d�
�jd��d	S)
a�
        Helper for testing L{IProcessTransport} write functionality.  This
        method spawns a child process and gives C{write} a chance to write some
        bytes to it.  It then verifies that the bytes were actually written to
        it (by relying on the child process to echo them back).

        @param write: A two-argument callable.  This is invoked with a process
            transport and some bytes to write to it.
        shello, worlds2import sys
sys.stdout.write(sys.stdin.readline())
csN���ttd�g�}z�|��WdSty&tdd�|�d�YdSw)Nr4z!Unhandled exception while writing�KILL)rBrC�
BaseExceptionr�
signalProcess�rJ��bytesToSend�programrIr>�writerr�startup�s
�z3ProcessTestsBuilderBase._writeTest.<locals>.startupcr8rr9r;r=rrr?�r@z4ProcessTestsBuilderBase._writeTest.<locals>.<lambda>r5�N)rArrr
�os�linesep�callWhenRunningrFrG�assertEqual�joinr!)r"rSrHrTrrPr�
_writeTest�s


z"ProcessTestsBuilderBase._writeTestcC�dd�}|�|�dS)z~
        L{IProcessTransport.write} writes the specified C{bytes} to the standard
        input of the child process.
        cSs|�|�dSr�rS�rJrQrrrrS��z1ProcessTestsBuilderBase.test_write.<locals>.writeN�r[�r"rSrrr�
test_write��z"ProcessTestsBuilderBase.test_writecCr\)z�
        L{IProcessTransport.writeSequence} writes the specified C{list} of
        C{bytes} to the standard input of the child process.
        cSs|�|g�dSr)�
writeSequencer^rrrrS�r.z9ProcessTestsBuilderBase.test_writeSequence.<locals>.writeNr`rarrr�test_writeSequence�rcz*ProcessTestsBuilderBase.test_writeSequencecCr\)z�
        L{IProcessTransport.writeToChild} writes the specified C{bytes} to the
        specified file descriptor of the child process.
        cSs|�d|�dS)Nr)�writeToChildr^rrrrS�r.z8ProcessTestsBuilderBase.test_writeToChild.<locals>.writeNr`rarrr�test_writeToChild�rcz)ProcessTestsBuilderBase.test_writeToChildcs�fdd�}��|�dS)z�
        L{IProcessTransport.writeToChild} raises L{KeyError} if passed a file
        descriptor which is was not set up by L{IReactorProcess.spawnProcess}.
        c	s0z��t|jd|�W|�|�dS|�|�w)N�
)�assertRaises�KeyErrorrfrSr^�r"rrrS�szIProcessTestsBuilderBase.test_writeToChildBadFileDescriptor.<locals>.writeNr`rarrkr�"test_writeToChildBadFileDescriptor�sz:ProcessTestsBuilderBase.test_writeToChildBadFileDescriptor�SIGCHLDNz;Platform lacks SIGCHLD, early-spawnProcess test can't work.cs�|���|jr
d}ni}t����fdd�}t�tj|�t�}�jt|�t	t	ddg|j|d���
d����s>|�d�g}|�
|j�|rJdS|�
�fd	d
��|���|�|�dS)z�
        If, before the reactor is started with L{IReactorCore.run}, a
        process is started with L{IReactorProcess.spawnProcess} and
        terminates, the process is reaped once the reactor is started.
        Nc����dSr)�set)�args)�signaledrr�handler��zGProcessTestsBuilderBase.test_spawnProcessEarlyIsReaped.<locals>.handlerr4r5)r7�childFDs�xz,Timed out waiting for child process to exit.cr8rr9r;r=rrr?r@zHProcessTestsBuilderBase.test_spawnProcessEarlyIsReaped.<locals>.<lambda>)rAr7�	threading�Event�signalrmrrBrrC�wait�isSet�failrFr%rGrD)r"rtrrrH�resultr)r>rqr�test_spawnProcessEarlyIsReaped�s2
�


z6ProcessTestsBuilderBase.test_spawnProcessEarlyIsReapedcs�d�ttd���t��d}G��fdd�dt�}�����j�j|�ttd|g�jd���fdd	�}��	|���
t���	�fd
d������dS)
z�
        The C{reason} argument passed to L{IProcessProtocol.processExited} is a
        L{ProcessTerminated} instance if the child process exits with a signal.
        �TERM�SIGsEimport sys
sys.stdout.write('x')
sys.stdout.flush()
sys.stdin.read()
cs4eZdZ�fdd�Zdd�Z�fdd�Zdd�Zd	S)
zDProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.Exitercs td||f�|j���dS�NzchildDataReceived(%d, %r))rrJrN�r"r&�data)�sigNamerrr()�zVProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.Exiter.childDataReceivedcSstd|f�dS�N�childConnectionLost(%d)�r)r"r&rrr�childConnectionLost-�zXProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.Exiter.childConnectionLostc� td|�d����|g�dS�NzprocessExited(�)�rr*r+��exitedrr�
processExited0szRProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.Exiter.processExitedcS�td|�d��dS�Nz
processEnded(r�r�r+rrrr-9�zQProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.Exiter.processEndedN�r/r0r1r(r�r�r-r)r�r�rr�Exiter(s
	r�r4r6csZ|\}|�t�|j}t��r��|j���|jd�dS��|j����|j�dS)NrU)	�trapr�valuer�	isWindows�assertIsNonerxrY�exitCode)rp�failurer)r"�sigNumrr�cbExitedEs
zFProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.cbExitedcr8rr9��ignr=rrr?Zr@zFProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.<lambda>N)
�getattrrxrrrArXrBrCr7rF�
addErrbackrrG)r"�sourcer�r�r)r�r>r"r�r�r�test_processExitedWithSignals&��

z4ProcessTestsBuilderBase.test_processExitedWithSignalcsL|���g���fdd�}��|�|���|��dtj�d�g�dS)a�
        If a child process exits while a system call is in progress, the system
        call should not be interfered with.  In particular, it should not fail
        with EINTR.

        Older versions of Twisted installed a SIGCHLD handler on POSIX without
        using the feature exposed by the SA_RESTART flag to sigaction(2).  The
        most noticeable problem this caused was for blocking reads and writes to
        sometimes fail with EINTR.
        cs�zCt�t���}t�|ddg�tj|ddgtjd�}|j���|j�	��Wd�n1s1wYW��
�dSW��
�dS��
�w)N�-czimport time; time.sleep(0.1)z)import time; time.sleep(0.5);print('Foo'))�stdout)rC�decode�sys�getfilesystemencoding�
subprocess�Popen�PIPEr�r%�readr:)�exe�f2�r>r|rr�fls���zJProcessTestsBuilderBase.test_systemCallUninterruptedByChildExit.<locals>.fsFoo�asciiN)rArXrGrYrVrW�encode)r"r�rr�r�'test_systemCallUninterruptedByChildExit^s

z?ProcessTestsBuilderBase.test_systemCallUninterruptedByChildExitc	s�td�tj��}t��\}}|�tj|�|�tj|�d}t�	tj
�d|}t�||�|�tj|�t�
��G��fdd�dt�}|����j�j|�ttdd|g|jd�|���tt�����}gd	�}|�|�t||g��t|��d
S)z�
        Processes spawned with spawnProcess() close all extraneous file
        descriptors in the parent.  They do have a stdin, stdout, and stderr
        open.
        z�
import sys
sys.path.insert(0, '{}')
from twisted.internet import process
sys.stdout.write(repr(process._listOpenFDs()))
sys.stdout.flush()�rc�eZdZ�jZ�fdd�ZdS)zKProcessTestsBuilderBase.test_openFileDescriptors.<locals>.GatheringProtocolcrnrr9r+r=rrr-�rszXProcessTestsBuilderBase.test_openFileDescriptors.<locals>.GatheringProtocol.processEndedN)r/r0r1rS�outReceivedr-r��outputr>rr�GatheringProtocol��r�s-Wignorer4r6�rrU�N)r
�format�twistedRoot�pathrV�pipe�
addCleanup�closer�	getrlimit�
RLIMIT_NOFILE�dup2�io�BytesIOrrArXrBrCr7rGro�eval�getvaluerY�intersection)	r"r��r�w�fudgeFactor�
unlikelyFDr��reportedChildFDs�stdFDsrr�r�test_openFileDescriptors�s:��
�
�z0ProcessTestsBuilderBase.test_openFileDescriptorscsrdd�}|�td|�|�tddd��|���t����j��fdd��}|j�d	d
�|�d�	���
��dS)
z�
        When L{os.execvpe} raises an exception, it will format that exception
        on stderr as UTF-8, regardless of system encoding information.
        c_s0d}t|t�s|�d�}td|d�}t|�dS)Nu<☃>�utf-8z1/0�single)�
isinstance�strr��compiler�)rp�kw�filename�codeobjrrr�execvpe�s


z=ProcessTestsBuilderBase.test_errorDuringExec.<locals>.execvper�r�cSsdS)Nr�rrrrrr?��z>ProcessTestsBuilderBase.test_errorDuringExec.<locals>.<lambda>cs0G��fdd�dt�}��|�ttddg�dS)Ncr�)z[ProcessTestsBuilderBase.test_errorDuringExec.<locals>.whenRunning.<locals>.TracebackCatchercrnrr9r+r=rrr-�rszhProcessTestsBuilderBase.test_errorDuringExec.<locals>.whenRunning.<locals>.TracebackCatcher.processEndedN)r/r0r1rS�errReceivedr-rr�rr�TracebackCatcher�r�r�r4r5)rrBrC)r�r�rr�whenRunning�szAProcessTestsBuilderBase.test_errorDuringExec.<locals>.whenRunning���timeoutu☃N)�patchrVr�rAr�r�rXrG�assertInr�r�)r"r�r�rr�r�test_errorDuringExec�s		z,ProcessTestsBuilderBase.test_errorDuringExeccs`����G��fdd�dt�}|�}�j�j|ttddg�jd��j�dd���|j�dS)	zi
        If a spawned process exits, C{processExited} will be called in a
        timely manner.
        cseZdZdZ��fdd�ZdS)zIProcessTestsBuilderBase.test_timelyProcessExited.<locals>.ExitingProtocolFcs"d|_�����|jjd�dS)NTr)r�r:rYr�r�)�	protoSelfr,�r>r"rrr��szWProcessTestsBuilderBase.test_timelyProcessExited.<locals>.ExitingProtocol.processExitedN)r/r0r1r�r�rr�rr�ExitingProtocol�sr�r4sraise SystemExit(0)r6r�r�N)	rArrXrBrCr7rGrDr�)r"r�rIrr�r�test_timelyProcessExited�s�	z0ProcessTestsBuilderBase.test_timelyProcessExitedc	s�dd|�d�g}g�G��fdd�dt�}|���|�}�j�j|ttdd�|�gfi|di��|���|�d	�d	jj	�d
S)aT
        Launch a child process, using either the C{uid} or C{gid} argument to
        L{IReactorProcess.spawnProcess} to change either its UID or GID to a
        different value.  If the child process reports this hasn't happened,
        raise an exception to fail the test.

        @param which: Either C{b"uid"} or C{b"gid"}.
        z	import oszraise SystemExit(os.getz() != 1)c�eZdZ��fdd�ZdS)z@ProcessTestsBuilderBase._changeIDTest.<locals>.CaptureExitStatuscs��|����dSr)r%r:r+��	containerr>rrr-s
zMProcessTestsBuilderBase._changeIDTest.<locals>.CaptureExitStatus.processEndedN)r/r0r1r-rr�rr�CaptureExitStatus�r�r��
rUrN)
rrArXrBrCrZrGrYr�r�)r"�whichrRr�rIrr�r�
_changeIDTests	��
z%ProcessTestsBuilderBase._changeIDTestcC�|�d�dS)z�
        If a value is passed for L{IReactorProcess.spawnProcess}'s C{uid}, the
        child process is run with that UID.
        �uidN�r�rkrrr�test_changeUID1�z&ProcessTestsBuilderBase.test_changeUIDcCr�)z�
        If a value is passed for L{IReactorProcess.spawnProcess}'s C{gid}, the
        child process is run with that GID.
        �gidNr�rkrrr�test_changeGID9r�z&ProcessTestsBuilderBase.test_changeGIDcs�|���Gdd�dt��G��fdd�dt�}|�}�j|ttddg|jd�}|���tdurLttj	�
��D]\}}||ur@q7t�||�|�d	�q7|�
d
t|�����dS)zY
        If L{IProcessProtocol.processExited} raises an exception, it is logged.
        c@seZdZdS)zGProcessTestsBuilderBase.test_processExitedRaises.<locals>.TestExceptionN)r/r0r1rrrr�
TestExceptionIsr�cr�)zBProcessTestsBuilderBase.test_processExitedRaises.<locals>.Protocolcs����d��)NzprocessedExited raisedr9r+�r�r>rrr�MszPProcessTestsBuilderBase.test_processExitedRaises.<locals>.Protocol.processExitedN)r/r0r1r�rr�rr�ProtocolLr�r�r4r5r6NzEAfter processExited raised, transport was left in reapProcessHandlersrU)rA�	ExceptionrrBrCr7rGr�list�reapProcessHandlers�items�unregisterReapProcessHandlerr{rY�len�flushLoggedErrors)r"r�rIrJ�pidrrrr�r�test_processExitedRaisesAs"�
�z0ProcessTestsBuilderBase.test_processExitedRaises)r/r0r1r2r
�requiredInterfacesrKr[rbrergrlrr�rxr}r�r�rr�r�r�r��_uidgidSkip�_uidgidSkipReasonr�r�rrrrrr3^s6!�
<J#
P
" 

r3c@sneZdZdZdZdZe��rdZndZdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zedd��ZdS)�ProcessTestsBuilderzp
    Builder defining tests relating to L{IReactorProcess} for child processes
    which do not have a PTY.
    Fs$twisted.internet.test.process_helperswindowsr5cs�t��t�t�t�d��G��fdd�dt�}d}|����j�j|�ttd|gt|jd��fdd�}��|��fd	d
�}��|�dd�}��|���	t
��fd
d�}��|�|���dS)z�
        L{IProcessProtocol.childConnectionLost} is called each time a file
        descriptor associated with a child process is closed.
        r�cs$eZdZ�fdd�Z�fdd�ZdS)z<ProcessTestsBuilder.test_childConnectionLost.<locals>.Closercs��|�dSr�r*)r"rJ)�	connectedrr�makeConnection�r_zKProcessTestsBuilder.test_childConnectionLost.<locals>.Closer.makeConnectioncs�|�d�dSrr�r"�childFD��lostrrr��r�zPProcessTestsBuilder.test_childConnectionLost.<locals>.Closer.childConnectionLostN)r/r0r1r
r�r)r	rrr�Closer�srs,twisted.internet.test.process_loseconnection�-m��envr7c� ��d��d��fdd��S)Ns2
r�c��Srrr�rOrrr?�r�zSProcessTestsBuilder.test_childConnectionLost.<locals>.cbConnected.<locals>.<lambda>�rSrFrOr
rOr�cbConnected��
zAProcessTestsBuilder.test_childConnectionLost.<locals>.cbConnectedcr)Ns1
rUcrrrr�rOrrr?�r�zRProcessTestsBuilder.test_childConnectionLost.<locals>.lostSecond.<locals>.<lambda>rrOr
rOr�
lostSecond�rz@ProcessTestsBuilder.test_childConnectionLost.<locals>.lostSecondcSs|�d�dS)N�
r]rOrrr�	lostFirst�r_z?ProcessTestsBuilder.test_childConnectionLost.<locals>.lostFirstcrnrr9r;r=rr�cbEnded�rsz=ProcessTestsBuilder.test_childConnectionLost.<locals>.cbEndedN)rrrArXrBrC�	properEnvr7rFr�rrG)r"r�targetrrrrr)r	rr>r�test_childConnectionLostxs.�	




z,ProcessTestsBuilder.test_childConnectionLostc	s�t��g�G��fdd�dt�}�����j�j|�ttd�jd�jgt�j	d���fdd�}��
|���t���
�fdd	����
��d
S)z�
        L{IProcessProtocol.processEnded} is called after the child process
        exits and L{IProcessProtocol.childConnectionLost} is called for each of
        its file descriptors.
        cs4eZdZdd�Z�fdd�Zdd�Z�fdd�Zd	S)
z4ProcessTestsBuilder.test_processEnded.<locals>.EndercSstd||f�|j��dSr�)rrJ�loseConnectionr�rrrr(�szFProcessTestsBuilder.test_processEnded.<locals>.Ender.childDataReceivedcstd|f���|�dSr�)rr%rr
rrr��szHProcessTestsBuilder.test_processEnded.<locals>.Ender.childConnectionLostcSr�r�r�r+rrrr��r�zBProcessTestsBuilder.test_processEnded.<locals>.Ender.processExitedcr�r�r�r+)rHrrr-�r�zAProcessTestsBuilder.test_processEnded.<locals>.Ender.processEndedNr�r)rHrrr�Ender�s
r r�childrcs(|\}|�t���t��hd��dS�N>rrUr�)r�rrYro�rpr��rr"rrr�s
z6ProcessTestsBuilder.test_processEnded.<locals>.cbEndedcr8rr9r�r=rrr?�r@z7ProcessTestsBuilder.test_processEnded.<locals>.<lambda>N�rrrArXrBrC�keepStdioOpenProgram�keepStdioOpenArgrr7rFr�rrG)r"r rr)rHrr>r"r�test_processEnded�s"�	

z%ProcessTestsBuilder.test_processEndedc
s�t��t��g�G���fdd�dt�}�����j�j|�ttdd�jd�jgt�j	d����fdd�}��
|���fd	d
�}��
|���t���
�fdd����
��d
S)z�
        L{IProcessProtocol.processExited} is called when the child process
        exits, even if file descriptors associated with the child are still
        open.
        cs.eZdZdd�Z��fdd�Z�fdd�ZdS)z6ProcessTestsBuilder.test_processExited.<locals>.WaitercSstd||f�dSr�r�r�rrrr(�r�zHProcessTestsBuilder.test_processExited.<locals>.Waiter.childDataReceivedcs6td|f���|�t��dkr��d�dSdS)Nr��)rr%rr*r)�allLostrrrr��s

�zJProcessTestsBuilder.test_processExited.<locals>.Waiter.childConnectionLostcs*td|�d����|g�|j��dSr�)rr*rJrr+r�rrr��szDProcessTestsBuilder.test_processExited.<locals>.Waiter.processExitedN)r/r0r1r(r�r�r)r*r�rrr�Waiter�sr+s-urr!rcs.|\}|�t�td�������g��S)NzcbExited; lost = )r�rrrYr#)r*rr"rrr�
s

z8ProcessTestsBuilder.test_processExited.<locals>.cbExitedcs��t��hd��dSr")rYror;r$rr�	cbAllLostr)z9ProcessTestsBuilder.test_processExited.<locals>.cbAllLostcr8rr9r�r=rrr?r@z8ProcessTestsBuilder.test_processExited.<locals>.<lambda>Nr%)r"r+r�r,r)r*r�rr>r"r�test_processExited�s4��


z&ProcessTestsBuilder.test_processExitedcCsZt|���}t|d��}|�tj�|�tj�Wd�n1s"wYtj�|�S)zj
        Write the given list of lines to a text file and return the absolute
        path to it.
        �wtN)	r�mktemp�openrSrVrWrZr��abspath)r"�sourceLines�script�
scriptFilerrr�makeSourceFiles
�z"ProcessTestsBuilder.makeSourceFilec	s�d���d�t�d��dd���d��dg��t��d�������fdd	���fd
d������fdd
�}��|�����dS)z�
        Spawning a process with an executable which is a script starting
        with an interpreter definition line (#!) uses that interpreter to
        evaluate the script.
        sthis is the shebang outputz#!{}r�z
import syszsys.stdout.write('{}')zsys.stdout.flush()i�csD|\}}}td|||f���|����|d���|d�dS)NzcbProcessExited((%r, %r, %d))r5r)rrY)rp�outr�code)r"�
shebangOutputrr�cbProcessExited;s

z9ProcessTestsBuilder.test_shebang.<locals>.cbProcessExitedc����|Srr9)�passthroughr=rr�shutdownB�z2ProcessTestsBuilder.test_shebang.<locals>.shutdowncs0tj��d�}|���|���|�t�dS)Nr=)r�getProcessOutputAndValue�addBothrFr�r��d)r9r>r4r<rr�startFs

z/ProcessTestsBuilder.test_shebang.<locals>.startN)	r5r�rCr�rV�chmodrArXrG)r"rBr)r9r>r4r"r8r<r�test_shebang's��
z ProcessTestsBuilder.test_shebangcs.�fdd�}���}|�||���|�dS)z<
        Pause producing and then resume producing.
        csJzt�}|j|ttddg�jd�}|��|��W|��dS|��w)Nr4r5r6)rrBrCr7�pauseProducing�resumeProducingr:)r>rIrJrkrr�pauseAndResumeTs�
zHProcessTestsBuilder.test_pauseAndResumeProducing.<locals>.pauseAndResumeN)rArXrG)r"rGr>rrkr�test_pauseAndResumeProducingOsz0ProcessTestsBuilder.test_pauseAndResumeProducingcs�d�gd��d�tttdd���}t|t�r|�d�������fdd���fd	d
�������fdd�}��|���	��d
S)zq
        Arguments given to spawnProcess are passed to the child process as
        originally intended.
        s!twisted.internet.test.process_cli)shello�"s 	|<>^&s"\\"hello\\"s"foo\ bar baz\""rrU�r�cs,|\}}}|�d�}|�����|�dS)N�)�split�poprY)�finishedArgsr�rr7)rpr"rr�processFinishedrs

zMProcessTestsBuilder.test_processCommandLineArguments.<locals>.processFinishedcr:rr9)r|r=rrr<yr=zFProcessTestsBuilder.test_processCommandLineArguments.<locals>.shutdowncs6td�}|����fdd��|���|���dS)Ncstjtd�g�t�d�S)Nr)rr>)rr>rCr)�dummy)rpr>�usrrr?�s�zZProcessTestsBuilder.test_processCommandLineArguments.<locals>.spawnChild.<locals>.<lambda>)rrFr?r@)rprOr>r<rQrr�
spawnChild}s�
zHProcessTestsBuilder.test_processCommandLineArguments.<locals>.spawnChildN)
rZ�map�chr�ranger�r�r�rArXrG)r"�allCharsrRr)rprOr>r"r<rQr� test_processCommandLineArgumentscs



z4ProcessTestsBuilder.test_processCommandLineArgumentscs`g�G�fdd�dt��t��fdd��}|��}|�||�|�|�t��t�dg��dS)z�
        Process is removed from reapProcessHandler dict before running
        ProcessProtocol.processEnded() callback.
        cs$eZdZdZdd�Z�fdd�ZdS)ziProcessTestsBuilder.test_process_unregistered_before_protocol_ended_callback.<locals>.TestProcessProtocola7
            Process protocol captures own presence in
            process.reapProcessHandlers at time of .processEnded() callback.

            @ivar deferred: A deferred fired when the .processEnded() callback
                has completed.
            @type deferred: L{Deferred<defer.Deferred>}
            cSst�|_dSr)r�deferredrkrrrr#�rszrProcessTestsBuilder.test_process_unregistered_before_protocol_ended_callback.<locals>.TestProcessProtocol.__init__csJddlm}|j}|��}|j|vr��d�n��d�|j�d�dS)z�
                Capture whether the process has already been removed
                from process.reapProcessHandlers.

                @param status: unused
                rrz!process present but should not be�"process already removed as desiredN)�twisted.internetrr��valuesrJr%rXr*)r"�statusr�handlers�	processes��resultsrrr-�s

zvProcessTestsBuilder.test_process_unregistered_before_protocol_ended_callback.<locals>.TestProcessProtocol.processEndedN)r/r0r1r2r#r-rr_rr�TestProcessProtocol�s	rac
3s~�z8z��}|�|ttdg�|jVWnty+}z��|�WYd}~nd}~wwW|��dSW|��dS|��w)a
            Launch and wait for a subprocess and allow the TestProcessProtocol
            to capture the order of the .processEnded() callback vs. removal
            from process.reapProcessHandlers.

            @param reactor: Reactor used to spawn the test process and to be
                stopped when checks are complete.
            @type reactor: object providing
                L{twisted.internet.interfaces.IReactorProcess} and
                L{twisted.internet.interfaces.IReactorCore}.
            z	--versionN)rBrCrXr�r%r:)r>�testProcessProtocol�e�rar`rr�launchProcessAndWait�s"�
�����zjProcessTestsBuilder.test_process_unregistered_before_protocol_ended_callback.<locals>.launchProcessAndWaitrYN)rrrArXrG�hamcrest�assert_that�equal_to)r"rer>rrdr�8test_process_unregistered_before_protocol_ended_callback�s 

�zLProcessTestsBuilder.test_process_unregistered_before_protocol_ended_callbackN)r/r0r1r2r7r&rr�r'rr(r-r5rDrHrWrrirrrrrgs 52>
('rc@s<eZdZdZdZe��rdZdSe��rdZddiZ	dSdS)�PTYProcessTestsBuilderzi
    Builder defining tests relating to L{IReactorProcess} for child processes
    which have a PTY.
    Tz"PTYs are not supported on Windows.z,PTYs are flaky from a Darwin bug. See #8840.z(twisted.internet.pollreactor.PollReactorz$macOS's poll() does not support PTYsN)
r/r0r1r2r7rr�r�isMacOSX�skippedReactorsrrrrrj�s��rjc@seZdZdZdd�ZdS)�PotentialZombieWarningTestszE
    Tests for L{twisted.internet.error.PotentialZombieWarning}.
    cCs\ddlm}|j|�|jg�}|�|ddt�|�|ddd�|�t|�d�dS)z�
        Accessing L{PotentialZombieWarning} via the
        I{PotentialZombieWarning} attribute of L{twisted.internet.error}
        results in a deprecation warning being emitted.
        r)�error�category�messagez�twisted.internet.error.PotentialZombieWarning was deprecated in Twisted 10.0.0: There is no longer any potential for zombie process.rUN)rZrn�PotentialZombieWarning�
flushWarnings�test_deprecatedrY�DeprecationWarningr)r"rn�warningsrrrrs�s
�z+PotentialZombieWarningTests.test_deprecatedN)r/r0r1r2rsrrrrrm�srmc@s(eZdZdZee��d�dd��ZdS)�/ProcessIsUnimportableOnUnsupportedPlatormsTestsz�
    Tests to ensure that L{twisted.internet.process} is unimportable on
    platforms where it does not work (namely Windows).
    zOnly relevant on Windows.cCs@|�t��ddl}|jjWd�dS1swYdS)zI
        L{twisted.internet.process} is unimportable on Windows.
        rN)ri�ImportError�twisted.internet.process�internetr)r"�twistedrrr�test_unimportableOnWindowss
"�zJProcessIsUnimportableOnUnsupportedPlatormsTests.test_unimportableOnWindowsN)r/r0r1r2rrr�r{rrrrrvsrvc
@sjeZdZze�dd�Wney&Zzee�Ze	e�Z
WYdZ[ndZ[wwedd��Zedd��Z
dS)�ReapingNonePidsLogsProperlyNcCsFt�dd�|��\}|�t|j�|jd�|�t|j�|jd�dS�NzWrong error type loggedzWrong error message logged)	r�registerReapProcessHandlerrrY�typer��
expected_typer��expected_message)r"rnrrr�test_registerReapProcessHandler"s
��z;ReapingNonePidsLogsProperly.test_registerReapProcessHandlercCsLt�d�}|��|��\}|�t|j�|jd�|�t|j�|j	d�dSr})
r�_BaseProcess�reapProcessrrYrr�r�r�r�)r"�_baseProcessrnrrr�test__BaseProcess_reapProcess2s

��z9ReapingNonePidsLogsProperly.test__BaseProcess_reapProcess)r/r0r1rV�waitpidr�rcr�r�rr�rr�r�rrrrr|s��
r|)Fr2r�rVrxr�r�rv�unittestrrfrzrZr�twisted.internet.deferrrr�twisted.internet.errorrr�twisted.internet.interfacesr	r
�twisted.internet.protocolr�#twisted.internet.test.reactormixinsr�twisted.python.compatr
�twisted.python.filepathrr�twisted.python.logrr�twisted.python.runtimer�twisted.trial.unittestr�
executable�_asBytesPathrC�__file__�parentr�rr�dict�environr�pathseprZr�r�	_resourcer�_process�getuidrwrrr3r�globals�update�makeTestCaseClassesrjrmrvr|rrrr�<module>st
��

q

Anon7 - 2022
AnonSec Team