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/internet/test/__pycache__/test_process.cpython-38.pyc
U

��W[-}�@s$dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZmZddlmZddlmZmZdd	lmZmZmZmZmZdd
lmZddl m!Z!m"Z"ddl#m$Z$m%Z%dd
l&m'Z'ddl(m)Z)m*Z*eej+��,�Z-ee
j.��/��/�Z0dZ1e�2��rPdZ3dZ4dZ1e5ej6�Z7ej8�9ej:�e7d<nHddl3Z3ddlm4Z4e�;�dk�rvdZ1e�Z7ej8�9ej:��<e�=��e7d<dd�Z>Gdd�de'�Z?Gdd�de�Z@Gdd�de@�ZAeB��CeA�D��Gdd�de@�ZEeB��CeE�D��Gdd�de
�ZFGd d!�d!e
�ZGdS)"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.
�)�division�absolute_import�print_functionN)�TestCase)�ReactorBuilder)�msg�err)�platform)�FilePath�_asFilesystemBytes)�
networkString�range�items�bytesEnviron�unicode)�utils)�IReactorProcess�IProcessTransport)�Deferred�succeed)�ProcessProtocol)�ProcessDone�ProcessTerminatedz Cannot change UID/GID on Windows�
PYTHONPATH)�processz$Cannot change UID/GID except as roots
PYTHONPATHcCstdkrd|_|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)Z
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__Qsz)_ShutdownCallbackProcessProtocol.__init__cCs|j�|g��|�dSr!)r#�
setdefault�append)r$�fd�bytesrrr�childDataReceivedVsz2_ShutdownCallbackProcessProtocol.childDataReceivedcCs|j�d�dSr!)r"�callback�r$�reasonrrr�processEndedZsz-_ShutdownCallbackProcessProtocol.processEndedN)�__name__�
__module__�__qualname__�__doc__r%r*r.rrrrr Isr c@s�eZdZdZegZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Ze
edd�dkr`de_dd�Zdd�Zedd��Zedd��Zdd�Zdd�Zdd �Zedk	r�ee_d!d"�Zedk	r�ee_d#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���usePTYcs���Sr!��stop�Zignored��reactorrr�<lambda>�r5zHProcessTestsBuilderBase.test_processTransportInterface.<locals>.<lambda>N)rr �buildReactor�spawnProcess�pyExer7�
assertTruerZ
providedBy�addCallback�
runReactor)r$�ended�protocol�	transportrr;r�test_processTransportInterfacejs�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())
csH���ttd�g�}z�|��Wn tdd�|�d�YnXdS)Nr4z!Unhandled exception while writingZKILL)r?r@r�
signalProcess�rF��bytesToSend�programrEr<�writerr�startup�s�
z3ProcessTestsBuilderBase._writeTest.<locals>.startupcs���Sr!r8r:r;rrr=�r5z4ProcessTestsBuilderBase._writeTest.<locals>.<lambda>r5�N)r>rr r�os�linesep�callWhenRunningrBrC�assertEqual�joinr#)r$rMrDrNrrJr�
_writeTest�s
�

z"ProcessTestsBuilderBase._writeTestcCsdd�}|�|�dS)z~
        L{IProcessTransport.write} writes the specified C{bytes} to the standard
        input of the child process.
        cSs|�|�dSr!�rM�rFrKrrrrM�sz1ProcessTestsBuilderBase.test_write.<locals>.writeN�rU�r$rMrrr�
test_write�sz"ProcessTestsBuilderBase.test_writecCsdd�}|�|�dS)z�
        L{IProcessTransport.writeSequence} writes the specified C{list} of
        C{bytes} to the standard input of the child process.
        cSs|�|g�dSr!)Z
writeSequencerWrrrrM�sz9ProcessTestsBuilderBase.test_writeSequence.<locals>.writeNrXrYrrr�test_writeSequence�sz*ProcessTestsBuilderBase.test_writeSequencecCsdd�}|�|�dS)z�
        L{IProcessTransport.writeToChild} writes the specified C{bytes} to the
        specified file descriptor of the child process.
        cSs|�d|�dS)Nr)�writeToChildrWrrrrM�sz8ProcessTestsBuilderBase.test_writeToChild.<locals>.writeNrXrYrrr�test_writeToChild�sz)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	s(z��t|jd|�W5|�|�XdS)N�
)rM�assertRaises�KeyErrorr\rW�r$rrrM�szIProcessTestsBuilderBase.test_writeToChildBadFileDescriptor.<locals>.writeNrXrYrrar�"test_writeToChildBadFileDescriptor�sz:ProcessTestsBuilderBase.test_writeToChildBadFileDescriptorcs�|���|jrd}ni}t����fdd�}t�tj|�t�}�jt|�t	t	ddg|j|d���
d����s||�d�g}|�
|j�|r�dS|�
�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.
        Ncs���dSr!)�set)�args)�signaledrr�handler�szGProcessTestsBuilderBase.test_spawnProcessEarlyIsReaped.<locals>.handlerr4r5)r7�childFDs�xz,Timed out waiting for child process to exit.cs���Sr!r8r:r;rrr=r5zHProcessTestsBuilderBase.test_spawnProcessEarlyIsReaped.<locals>.<lambda>)r>r7�	threadingZEvent�signal�SIGCHLDrr?r r@�waitZisSet�failrBr'rCrA)r$rgrfrD�resultr)r<rer�test_spawnProcessEarlyIsReaped�s2�


z6ProcessTestsBuilderBase.test_spawnProcessEarlyIsReapedrkNz;Platform lacks SIGCHLD, early-spawnProcess test can't work.cs�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.
        ZTERMZSIGsEimport 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))rrFrH�r$r(�data)�sigNamerrr*%szVProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.Exiter.childDataReceivedcSstd|f�dS�N�childConnectionLost(%d)�r)r$r(rrr�childConnectionLost)szXProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.Exiter.childConnectionLostcstd|f���|g�dS�NzprocessExited(%r)�rr+r,��exitedrr�
processExited,szRProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.Exiter.processExitedcSstd|f�dS�NzprocessEnded(%r)rvr,rrrr.5szQProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.Exiter.processEndedN�r/r0r1r*rwr|r.r)r{rsrr�Exiter$s	rr4r6csX|\}|�t�|j}t��r:��|j���|jd�n��|j����|j�dS)NrO)	�trapr�valuer	�	isWindowsZassertIsNonerjrS�exitCode)rd�failurer)r$�sigNumrr�cbExited=s
zFProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.cbExitedcs���Sr!r8�Zignr;rrr=Rr5zFProcessTestsBuilderBase.test_processExitedWithSignal.<locals>.<lambda>N)
�getattrrjrrr>rRr?r@r7rB�
addErrbackrrC)r$�sourcerr�r)r{r<r$rsr�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.
        c	sjzZt�t���}t�|ddg�tj|ddgtjd�}|j���	|j�
��W5QRXW5���XdS)N�-czimport time; time.sleep(0.1)z)import time; time.sleep(0.5);print('Foo'))�stdout)r9r@�decode�sys�getfilesystemencoding�
subprocess�Popen�PIPEr�r'�read)�exe�f2�r<rnrr�fes��zJProcessTestsBuilderBase.test_systemCallUninterruptedByChildExit.<locals>.fsFoo�asciiN)r>rRrCrSrPrQ�encode)r$r�rr�r�'test_systemCallUninterruptedByChildExitWs

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�����}dd	d
g}|�|�t||g��t|��dS)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, '{0}')
from twisted.internet import process
sys.stdout.write(repr(process._listOpenFDs()))
sys.stdout.flush()�rcseZdZ�jZ�fdd�ZdS)zKProcessTestsBuilderBase.test_openFileDescriptors.<locals>.GatheringProtocolcs���dSr!r8r,r;rrr.�szXProcessTestsBuilderBase.test_openFileDescriptors.<locals>.GatheringProtocol.processEndedN)r/r0r1rMZoutReceivedr.r��outputr<rr�GatheringProtocol�sr�s-Wignorer4r6rO�N)r�format�twistedRoot�pathrP�pipeZ
addCleanup�closerZ	getrlimitZ
RLIMIT_NOFILE�dup2�io�BytesIOrr>rRr?r@r7rCrc�eval�getvaluerS�intersection)	r$r��r�wZfudgeFactorZ
unlikelyFDr�ZreportedChildFDsZstdFDsrr�r�test_openFileDescriptors{s:��
�

�z0ProcessTestsBuilderBase.test_openFileDescriptorscstdd�}|�td|�|�tddd��|���t����j��fdd��}|j�d	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/0Zsingle)�
isinstance�strr��compiler�)rd�kw�filenameZcodeobjrrr�execvpe�s


z=ProcessTestsBuilderBase.test_errorDuringExec.<locals>.execvper�r�cSsdS)Nr�rrrrrr=�r5z>ProcessTestsBuilderBase.test_errorDuringExec.<locals>.<lambda>cs2G��fdd�dtt�}��|�ttddg�dS)NcseZdZ�jZ�fdd�ZdS)z[ProcessTestsBuilderBase.test_errorDuringExec.<locals>.whenRunning.<locals>.TracebackCatchercs���dSr!r8r,r;rrr.�szhProcessTestsBuilderBase.test_errorDuringExec.<locals>.whenRunning.<locals>.TracebackCatcher.processEndedN)r/r0r1rMZerrReceivedr.rr�rr�TracebackCatcher�sr�r4r5)r�objectr?r@)r�r�rr�whenRunning�s
�zAProcessTestsBuilderBase.test_errorDuringExec.<locals>.whenRunning��Ztimeoutu☃r�N)ZpatchrPr�r>r�r�rRrCZassertInr�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{r9rSr�r�)Z	protoSelfr-�r<r$rrr|�szWProcessTestsBuilderBase.test_timelyProcessExited.<locals>.ExitingProtocol.processExitedN)r/r0r1r{r|rr�rr�ExitingProtocol�sr�r4sraise SystemExit(0)r6r�r�N)	r>rrRr?r@r7rCrAr{)r$r�rErr�r�test_timelyProcessExited�s�z0ProcessTestsBuilderBase.test_timelyProcessExitedc	s~dd|fg}g�G��fdd�dt�}|���|�}�j�j|ttdd�|�gf|di�|���|�d�djj	�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 osz!raise SystemExit(os.get%s() != 1)cseZdZ��fdd�ZdS)z@ProcessTestsBuilderBase._changeIDTest.<locals>.CaptureExitStatuscs��|����dSr!)r'r9r,�Z	containerr<rrr.s
zMProcessTestsBuilderBase._changeIDTest.<locals>.CaptureExitStatus.processEndedN)r/r0r1r.rr�rr�CaptureExitStatussr�r��
rOrN)
rr>rRr?r@rTrCrSr�r�)r$ZwhichrLr�rErr�r�
_changeIDTests"
���
z%ProcessTestsBuilderBase._changeIDTestcCs|�d�dS)z�
        If a value is passed for L{IReactorProcess.spawnProcess}'s C{uid}, the
        child process is run with that UID.
        ZuidN�r�rarrr�test_changeUID!sz&ProcessTestsBuilderBase.test_changeUIDcCs|�d�dS)z�
        If a value is passed for L{IReactorProcess.spawnProcess}'s C{gid}, the
        child process is run with that GID.
        �gidNr�rarrr�test_changeGID+sz&ProcessTestsBuilderBase.test_changeGIDcs�|���Gdd�dt��G��fdd�dt�}|�}�j|ttddg|jd�}|���tdk	r�ttj	�D](\}}||k	r|qjt�
||�|�d	�qj|�d
t
|�����dS)zY
        If L{IProcessProtocol.processExited} raises an exception, it is logged.
        c@seZdZdS)zGProcessTestsBuilderBase.test_processExitedRaises.<locals>.TestExceptionN)r/r0r1rrrr�
TestException=sr�cseZdZ��fdd�ZdS)zBProcessTestsBuilderBase.test_processExitedRaises.<locals>.Protocolcs����d��dS)NzprocessedExited raisedr8r,�r�r<rrr|AszPProcessTestsBuilderBase.test_processExitedRaises.<locals>.Protocol.processExitedN)r/r0r1r|rr�rr�Protocol@sr�r4r5r6NzEAfter processExited raised, transport was left in reapProcessHandlersrO)r>�	Exceptionrr?r@r7rCrrZreapProcessHandlersZunregisterReapProcessHandlerrmrS�lenZflushLoggedErrors)r$r�rErF�pidrfrr�r�test_processExitedRaises5s$�
z0ProcessTestsBuilderBase.test_processExitedRaises)r/r0r1r2rZrequiredInterfacesrGrUrZr[r]rbror�rjrr�r�rr�r�r�r�r��_uidgidSkipr�r�rrrrr3_s6%


6�F$
I
"r3c@sZeZdZdZdZdZe��r"dZndZdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�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.
        )rrOr�cs$eZdZ�fdd�Z�fdd�ZdS)z<ProcessTestsBuilder.test_childConnectionLost.<locals>.Closercs��|�dSr!�r+)r$rF)�	connectedrr�makeConnectiontszKProcessTestsBuilder.test_childConnectionLost.<locals>.Closer.makeConnectioncs�|�d�dSr!r��r$ZchildFD��lostrrrwwszPProcessTestsBuilder.test_childConnectionLost.<locals>.Closer.childConnectionLostN)r/r0r1r�rwr)r�r�rr�Closerssr�s,twisted.internet.test.process_loseconnection�-m��envr7cs ��d��d��fdd��S)Ns2
r�cs�Sr!rr�rIrrr=�r5zSProcessTestsBuilder.test_childConnectionLost.<locals>.cbConnected.<locals>.<lambda>�rMrBrIr�rIr�cbConnected�s
zAProcessTestsBuilder.test_childConnectionLost.<locals>.cbConnectedcs ��d��d��fdd��S)Ns1
rOcs�Sr!rr�rIrrr=�r5zRProcessTestsBuilder.test_childConnectionLost.<locals>.lostSecond.<locals>.<lambda>r�rIr�rIr�
lostSecond�s
z@ProcessTestsBuilder.test_childConnectionLost.<locals>.lostSecondcSs|�d�dS)N�
rVrIrrr�	lostFirst�sz?ProcessTestsBuilder.test_childConnectionLost.<locals>.lostFirstcs���dSr!r8r:r;rr�cbEnded�sz=ProcessTestsBuilder.test_childConnectionLost.<locals>.cbEndedN)rrr>rRr?r@�	properEnvr7rBr�rrC)r$r��targetr�r�r�r�r)r�r�r<r�test_childConnectionLostks.�




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��dSrp)rrF�loseConnectionrqrrrr*�szFProcessTestsBuilder.test_processEnded.<locals>.Ender.childDataReceivedcstd|f���|�dSrt)rr'r�r�rrrw�szHProcessTestsBuilder.test_processEnded.<locals>.Ender.childConnectionLostcSstd|f�dSrxrvr,rrrr|�szBProcessTestsBuilder.test_processEnded.<locals>.Ender.processExitedcstd|f���|g�dSr}ryr,)rDrrr.�szAProcessTestsBuilder.test_processEnded.<locals>.Ender.processEndedNr~r)rDr�rr�Ender�sr�r��childr�cs.|\}|�t���t��tdddg��dS�NrrOr�)r�rrSrc�rdr��r�r$rrr��s
z6ProcessTestsBuilder.test_processEnded.<locals>.cbEndedcs���Sr!r8r�r;rrr=�r5z7ProcessTestsBuilder.test_processEnded.<locals>.<lambda>N�rrr>rRr?r@�keepStdioOpenProgram�keepStdioOpenArgr�r7rBr�rrC)r$r�r�r)rDr�r<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�dSrprvrqrrrr*�szHProcessTestsBuilder.test_processExited.<locals>.Waiter.childDataReceivedcs2td|f���|�t��dkr.��d�dS)Nru�)rr'r�r+r�)�allLostr�rrrw�s
zJProcessTestsBuilder.test_processExited.<locals>.Waiter.childConnectionLostcs(td|f���|g�|j��dSrx)rr+rFr�r,rzrrr|�szDProcessTestsBuilder.test_processExited.<locals>.Waiter.processExitedN)r/r0r1r*rwr|r)r�r{r�rr�Waiter�sr�s-ur�r�r�cs.|\}|�t�td�f����g��S)NzcbExited; lost = %s)r�rrrSr�)r�r�r$rrr��s

z8ProcessTestsBuilder.test_processExited.<locals>.cbExitedcs��t��tdddg��dSr�)rSrcr:r�rr�	cbAllLost�sz9ProcessTestsBuilder.test_processExited.<locals>.cbAllLostcs���Sr!r8r�r;rrr=�r5z8ProcessTestsBuilder.test_processExited.<locals>.<lambda>Nr�)r$r�r�r�r)r�r{r�r<r$r�test_processExited�s,��


z&ProcessTestsBuilder.test_processExitedc	CsFt|���}t|d��}|�tj�|�tj�W5QRXtj�|�S)zj
        Write the given list of lines to a text file and return the absolute
        path to it.
        Zwt)	rZmktemp�openrMrPrQrTr��abspath)r$ZsourceLinesZscript�
scriptFilerrr�makeSourceFile�s"z"ProcessTestsBuilder.makeSourceFilecs�d���dt�d�fdd��d�fdg��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#!%sr�z
import syszsys.stdout.write('%s')zsys.stdout.flush()i�csD|\}}}td|||f���|����|d���|d�dS)NzcbProcessExited((%r, %r, %d))r5r)rrS)rd�outr�code)r$�
shebangOutputrr�cbProcessExiteds

z9ProcessTestsBuilder.test_shebang.<locals>.cbProcessExitedcs���|Sr!r8)Zpassthroughr;rr�shutdownsz2ProcessTestsBuilder.test_shebang.<locals>.shutdowncs0tj��d�}|���|���|�t�dS)Nr;)r�getProcessOutputAndValue�addBothrBr�r��d)r�r<r�r�rr�start!s

z/ProcessTestsBuilder.test_shebang.<locals>.startN)r�r@r�rP�chmodr>rRrC)r$r�r)r�r<r�r$r�r�r�test_shebangs�
z ProcessTestsBuilder.test_shebangcs�d�dddddg�d�tttdd	���}t|t�r<|�d
�������fdd���fd
d�������fdd�}��|���	��dS)zq
        Arguments given to spawnProcess are passed to the child process as
        originally intended.
        s!twisted.internet.test.process_clishello�"s 	|<>^&s"\\"hello\\"s"foo\ bar baz\""�rO�r�cs,|\}}}|�d�}|�����|�dS)N�)�split�poprS)ZfinishedArgsr�rr�)rdr$rr�processFinished:s

zMProcessTestsBuilder.test_processCommandLineArguments.<locals>.processFinishedcs���|Sr!r8)rnr;rrr�AszFProcessTestsBuilder.test_processCommandLineArguments.<locals>.shutdowncs6td�}|����fdd��|���|���dS)Ncstjtd�g�t�d�S)Nr�)r�r<)rr�r@r�)Zdummy)rdr<�usrrr=Gs

�zZProcessTestsBuilder.test_processCommandLineArguments.<locals>.spawnChild.<locals>.<lambda>)rrBr�r�)rdrr<r�r	rr�
spawnChildEs
zHProcessTestsBuilder.test_processCommandLineArguments.<locals>.spawnChildN)
rT�map�chrr
r�rr�r>rRrC)r$ZallCharsr
r)rdrr<r$r�r	r� test_processCommandLineArguments+s


z4ProcessTestsBuilder.test_processCommandLineArgumentsN)r/r0r1r2r7r�r	r�r�r�r�r�r�rr
rrrrr�Zs-/3&r�c@s6eZdZdZdZe��rdZne��r2dZddiZ	dS)�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/r0r1r2r7r	r�rZisMacOSXZskippedReactorsrrrrrSs�rc@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.rON)�twisted.internetrZPotentialZombieWarningZ
flushWarnings�test_deprecatedrS�DeprecationWarningr�)r$r�warningsrrrrjs
�z+PotentialZombieWarningTests.test_deprecatedN)r/r0r1r2rrrrrrfsrc@s&eZdZdZdd�Ze��s"de_dS)�/ProcessIsUnimportableOnUnsupportedPlatormsTestsz�
    Tests to ensure that L{twisted.internet.process} is unimportable on
    platforms where it does not work (namely Windows).
    c	Cs*|�t��ddl}|jjW5QRXdS)zI
        L{twisted.internet.process} is unimportable on Windows.
        rN)r_�ImportErrorZtwisted.internet.processZinternetr)r$�twistedrrr�test_unimportableOnWindows�szJProcessIsUnimportableOnUnsupportedPlatormsTests.test_unimportableOnWindowszOnly relevant on Windows.N)r/r0r1r2rr	r�rrrrrr~sr)Hr2Z
__future__rrrr�rPrjr�rirr�Ztwisted.trial.unittestrZ#twisted.internet.test.reactormixinsrZtwisted.python.logrrZtwisted.python.runtimer	Ztwisted.python.filepathr
rZtwisted.python.compatrr
rrrrrZtwisted.internet.interfacesrrZtwisted.internet.deferrrZtwisted.internet.protocolrZtwisted.internet.errorrr�
executableZ_asBytesPathr@�__file__�parentr�r�r�rr�dict�environr��pathseprTr��getuidr�r�rr r3r��globals�updateZmakeTestCaseClassesrrrrrrr�<module>sb

�~v