a
    lc!                     @   sl   d Z ddlZddlZddlZddlZddlZddlmZm	Z	 ddl
mZ G dd deZe jZdd	 ZdS )
z}Posix-specific implementation of process utilities.

This file is only meant to be imported by process.py, not by end-users.
    N   )	getoutput	arg_split)DEFAULT_ENCODINGc                   @   sN   e Zd ZdZdZdZdZdZedd Z	dddZ
d	d
 Zdd Zdd ZdS )ProcessHandlerz7Execute subprocesses under the control of pexpect.
    g?g?Nc                 C   sB   | j d u r<tjdd}t|| _ | j d u r<td|| j S )NSHELLshz"{}" shell not found)_shosenvirongetpexpectwhichOSErrorformat)selfZ
shell_name r   X/var/www/html/django/DPS/env/lib/python3.9/site-packages/IPython/utils/_process_posix.pyr   3   s    

zProcessHandler.shc                 C   s@   |du rt jn|| _|du r"t jn|| _|du r6tjn|| _dS )z%Arguments are used for pexpect calls.N)r   read_timeoutterminate_timeoutsysstdoutlogfile)r   r   r   r   r   r   r   __init__=   s    
zProcessHandler.__init__c                 C   sF   zt j| jd|gdddW S  ty@   tdtjdd Y n0 dS 	a"  Run a command and return its stdout/stderr as a string.

        Parameters
        ----------
        cmd : str
            A command to be executed in the system shell.

        Returns
        -------
        output : str
            A string containing the combination of stdout and stderr from the
        subprocess, in whatever order the subprocess originally wrote to its
        file descriptors (so the order of the information in this string is the
        correct order as would be seen if running the command in a terminal).
        -cargsz

z^C )fileendNr   runr   replaceKeyboardInterruptprintr   stderrr   cmdr   r   r   r   F   s    zProcessHandler.getoutputc                 C   sF   zt j| jd|gdddW S  ty@   tdtjdd Y n0 dS r   r"   r(   r   r   r   getoutput_pexpect[   s    z ProcessHandler.getoutput_pexpectc           	      C   s  t }tjtjg}|tj}d}zttdrBtj| jd|gd}ntj| jd|gd}t	j
j}||| j}t|j|d |ddd |  ||krqt|j}q^W n tyD   |td	 zjzDt|j}||| j t|j|d |ddd t	j
  W n ty    Y n0 W |jd
d n|jd
d 0 Y n0 |  |jdu rr|jdu rjdS |j S |jdkr|jd  S |jS )zExecute a command in a subshell.

        Parameters
        ----------
        cmd : str
            A command to be executed in the system shell.

        Returns
        -------
        int : child's exitstatus
        r   spawnbr   r   Nr$   r   )r!      T)force   )r   r   TIMEOUTEOFindexhasattrr+   r   spawnr   r   flushZexpect_listr   r&   beforedecodelenr%   Zsendlinechrr   	terminateZisaliveZ
exitstatusZsignalstatus)	r   r)   encpatternsZ	EOF_indexout_sizechildr4   Zres_idxr   r   r   systemp   sB    

"zProcessHandler.system)NNN)__name__
__module____qualname____doc__r   r   r   r	   propertyr   r   r   r*   r>   r   r   r   r   r   !   s   
	
	r   c              
   C   st   zt | d W nZ tyj } zB|jtjkr:W Y d }~dS |jtjkrTW Y d }~dS  W Y d }~nd }~0 0 dS d S )Nr   FT)r
   killr   errnoZESRCHEPERM)piderrr   r   r   	check_pid   s    rI   )rB   rE   r
   
subprocessspr   r   _process_commonr   r   ZIPython.utils.encodingr   objectr   r>   rI   r   r   r   r   <module>   s    +