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: //lib/python3/dist-packages/twisted/internet/__pycache__/_dumbwin32proc.cpython-38.pyc
U


W[33�@sJdZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZe
��Zde_ddlmZddlmZmZmZddlmZmZddlmZdd	lmZdd
lm Z ddlm!Z!ddl"m#Z#eee$ed
d��dd��Z%dd�Z&Gdd�de!j'�Z(dd�Z)dd�Z*eeee�Gdd�de!j+e#��Z,dS)z-
http://isometri.cc/strips/gates_in_the_head
�)�absolute_import�division�print_functionN�)�implementer)�IProcessTransport�	IConsumer�	IProducer)�items�_PY3)�quoteArguments)�
_replaceIf)�error)�_pollingfile)�BaseProcess�fsdecodecCs t|t�r|�t���S|SdS)z�
    Decode a string to a L{unicode} representation, passing
    through existing L{unicode} unchanged.

    @param x: The string to be conditionally decoded.
    @type x: L{bytes} or L{unicode}

    @return: L{unicode}
    N)�
isinstance�bytes�decode�sys�getfilesystemencoding)�x�r�A/usr/lib/python3/dist-packages/twisted/internet/_dumbwin32proc.py�	_fsdecode*s
rcCst|�tj��dS�N)�printr�stdout�flush)�msgrrr�debug<sr c@seZdZdd�Zdd�ZdS)�_ReapercCs
||_dSr)�proc)�selfr"rrr�__init__Dsz_Reaper.__init__cCs@t�|jjd�tjkrdSt�|jj�}|��|j�|�dS�Nr)	�
win32eventZWaitForSingleObjectr"�hProcessZ
WAIT_OBJECT_0�win32processZGetExitCodeProcessZ
deactivateZprocessEnded)r#ZexitCoderrr�	checkWorkHsz_Reaper.checkWorkN)�__name__�
__module__�__qualname__r$r)rrrrr!Bsr!c
CsHt|d��4}|�d�dkr:|�d��d�}|W5QR�SW5QRXdS)a 
    Look for a #! line, and return the value following the #! if one exists, or
    None if this file is not a script.

    I don't know if there are any conventions for quoting in Windows shebang
    lines, so this doesn't support any; therefore, you may not pass any
    arguments to scripts invoked as filters.  That's probably wrong, so if
    somebody knows more about the cultural expectations on Windows, please feel
    free to fix.

    This shebang line support was added in support of the CGI tests;
    appropriately enough, I determined that shebang lines are culturally
    accepted in the Windows world through this page::

        http://www.cgi101.com/learn/connect/winxp.html

    @param filename: str representing a filename

    @return: a str representing another filename.
    ZrU�z#!i�
N)�open�read�readline�strip)�filename�f�exerrr�_findShebangRsr6cCs|jddkS)z�
    Determine if a pywintypes.error is telling us that the given process is
    'not a valid win32 application', i.e. not a PE format executable.

    @param pywinerr: a pywintypes.error instance raised by CreateProcess

    @return: a boolean
    r�)�args)Zpywinerrrrr�_invalidWin32Appnsr9c@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/S)0�Processa�
    A process that integrates with the Twisted event loop.

    If your subprocess is a python program, you need to:

     - Run python.exe with the '-u' command line option - this turns on
       unbuffered I/O. Buffering stdout/err/in can cause problems, see e.g.
       http://support.microsoft.com/default.aspx?scid=kb;EN-US;q1903

     - If you don't want Windows messing with data passed over
       stdin/out/err, set the pipes to be in binary mode::

        import os, sys, mscvrt
        msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
        msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
        msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)

    rc
s>tj��|�t��|�t��}d|_t�|d�\�_	}t�|d�\�_
}	t�|d�\}
�_t��jtj
dd�t���|�_|	�_|
�_tj�_t��}t�|�j	|ddtj�}t��j	�|�_	t�|�j
|ddtj�}t��j
�|�_
t�|�j|ddtj�}t��j�|�_tj�����|�p0i�i}
t ��D]"\}}t!|�}t!|�}||
|<�q@|
�dd�|D�}t"|����r�t!��n����r�t!��n��������fdd�}z
|�Wn�t#j$k
�r�}z�t%|��s�t&|��n�t'��}|dk�rt&d���nxt(|�}|�)d��t"|���}|�z
|�WnHt#j$k
�r�}z&t%|��rjt&d	||f��t&|��W5d}~XYnXW5d}~XYnXt�|	�t�|�t�|
�t�*�j	�fd
d��j+��_,t�*�j
�fdd��j-��_.t�/�j�j0��_1�j,�j.�j1fD]}��2|��q�j3�4����2t5���dS)
z-
        Create a new child process.
        rrNcSsg|]}t|��qSr)r)�.0rrrr�
<listcomp>�sz$Process.__init__.<locals>.<listcomp>cs2tj}t���ddd|����	\�_�_�_}dS�Nr)�win32conZCREATE_NO_WINDOWr(Z
CreateProcessr'�hThread�pid)�flagsZdwTid�ZStartupInfoZcmdline�command�env�pathr#rr�doCreate�s�z"Process.__init__.<locals>.doCreatezD%r is neither a Windows executable, nor a script with a shebang linez<%r has an invalid shebang line: %r is not a valid executablecs�j�d|�Sr=��protoZchildDataReceived��data�r#rr�<lambda>�z"Process.__init__.<locals>.<lambda>cs�j�d|�S�Nr-rGrIrKrrrLrM)6r�
_PollingTimerr$r�
win32security�SECURITY_ATTRIBUTES�bInheritHandle�	win32pipeZ
CreatePipeZhStdoutRZhStderrRZhStdinWZSetNamedPipeHandleStateZPIPE_NOWAITr(ZSTARTUPINFOZ
hStdOutputZ	hStdErrorZ	hStdInputZSTARTF_USESTDHANDLESZdwFlags�win32apiZGetCurrentProcessZDuplicateHandler>ZDUPLICATE_SAME_ACCESS�	win32file�CloseHandle�os�environ�copy�updater
rr�
pywintypesrr9�OSErrorr6�list�insertZ_PollableReadPipe�outConnectionLostr�errConnectionLost�stderrZ_PollableWritePipe�inConnectionLost�stdinZ_addPollableResourcerHZmakeConnectionr!)r#ZreactorZprotocolrCr8ZenvironmentrEZsAttrsZhStdoutWZhStderrWZhStdinRZ
currentPidZtmpZnewenv�key�valuerFZpwteZshebZorigcmdZpwte2ZpipewatcherrrBrr$�s�����




��

���,



�
��zProcess.__init__cCs,|jdkrt���|dkr(t�|jd�dS)N)ZINTZTERMZKILLr)r@rZProcessExitedAlreadyr(ZTerminateProcessr')r#ZsignalIDrrr�
signalProcesss
zProcess.signalProcesscCs|dkrt�|�St�|�Sr%)rZProcessDoneZProcessTerminated)r#Zstatusrrr�
_getReason&s
zProcess._getReasoncCs|j�|�dS)zQ
        Write data to the process' stdin.

        @type data: C{bytes}
        N)rc�write)r#rJrrrrh,sz
Process.writecCs|j�|�dS)z\
        Write data to the process' stdin.

        @type data: C{list} of C{bytes}
        N)rc�
writeSequence)r#�seqrrrri5szProcess.writeSequencecCs"|dkr|j�|�nt|��dS)a;
        Similar to L{ITransport.write} but also allows the file descriptor in
        the child process which will receive the bytes to be specified.

        This implementation is limited to writing to the child's standard input.

        @param fd: The file descriptor to which to write.  Only stdin (C{0}) is
            supported.
        @type fd: C{int}

        @param data: The bytes to write.
        @type data: C{bytes}

        @return: L{None}

        @raise KeyError: If C{fd} is anything other than the stdin file
            descriptor (C{0}).
        rN)rcrh�KeyError)r#�fdrJrrr�writeToChild>szProcess.writeToChildcCsB|dkr|��n,|dkr$|��n|dkr6|��ntd��dS)Nrrr-z4Only standard-IO file descriptors available on win32)�
closeStdin�closeStdout�closeStderr�NotImplementedError)r#rlrrr�closeChildFDWs


zProcess.closeChildFDcCs|j��dS)z"Close the process' stdin.
        N)rc�closerKrrrrnbszProcess.closeStdincCs|j��dSr)rarsrKrrrrphszProcess.closeStderrcCs|j��dSr)rrsrKrrrrolszProcess.closeStdoutcCs|��|��|��dS)z8
        Close the process' stdout, in and err.
        N)rnrorprKrrr�loseConnectionpszProcess.loseConnectioncCs|j�d�|��dSr=�rHZchildConnectionLost�connectionLostNotifyrKrrrr_yszProcess.outConnectionLostcCs|j�d�|��dSrNrurKrrrr`~szProcess.errConnectionLostcCs|j�d�|��dSr%rurKrrrrb�szProcess.inConnectionLostcCs|jd7_|��dS)zS
        Will be called 3 times, by stdout/err threads and process handle.
        rN)�closedNotifies�maybeCallProcessEndedrKrrrrv�szProcess.connectionLostNotifycCsB|jdkr>|jr>t�|j�t�|j�d|_d|_t�|�dS)N�)rwZlostProcessrUrVr'r?rrxrKrrrrx�szProcess.maybeCallProcessEndedcCs|j�||�dSr)rc�registerProducer)r#ZproducerZ	streamingrrrrz�szProcess.registerProducercCs|j��dSr)rc�unregisterProducerrKrrrr{�szProcess.unregisterProducercCs|��dSr)Z_pauserKrrr�pauseProducing�szProcess.pauseProducingcCs|��dSr)Z_unpauserKrrr�resumeProducing�szProcess.resumeProducingcCs|��dSr)rtrKrrr�
stopProducing�szProcess.stopProducingcCsd|jj|jfS)z@
        Return a string representation of the process.
        z<%s pid=%s>)�	__class__r*r@rKrrr�__repr__�szProcess.__repr__N)r*r+r,�__doc__rwr$rfrgrhrirmrrrnrprortr_r`rbrvrxrzr{r|r}r~r�rrrrr:�s2
				r:)-r�Z
__future__rrrrWrrTr>r&rUrSr(rPr[rQZPIPE_ATTRS_INHERITABLErRZzope.interfacerZtwisted.internet.interfacesrrr	Ztwisted.python.compatr
rZtwisted.python.win32rZtwisted.python.utilr
Ztwisted.internetrrZtwisted.internet._baseprocessr�getattrrr Z_PollableResourcer!r6r9rOr:rrrr�<module>s: