U
    d/e                  	   @   s  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ZddlmZ dddgZ	e
eZejeje eje f Zejdddd	ejejejef  ejeje  deejd
ddZejdddejejejef  ejeje  eeejd
ddZejdddddejejejef  eje eje eeejdddZdddd	ejejejef  eje eje eejd
ddZdd ZddddZG dd deZG dd dejZdS )zFRun subprocesses with ``subprocess.run()`` and ``subprocess.Popen()``.    N   )_compat	run_checkExecutableNotFoundCalledProcessError.)input_linesencodingquiet)cmdr   r   r	   returnc                K   s   dS )z9Accept bytes input_lines with default ``encoding=None```.N r
   r   r   r	   kwargsr   r   </tmp/pip-unpacked-wheel-n8ok7rre/graphviz/backend/execute.pyr      s    )r   r	   c                K   s   dS )z2Accept string input_lines when given ``encoding``.Nr   r   r   r   r   r      s    )r   r   capture_outputr	   )r
   r   r   r   r	   r   c                K   s   dS )z=Accept bytes or string input_lines depending on ``encoding``.Nr   )r
   r   r   r   r	   r   r   r   r   r   (   s    Fc             
   K   sN  t d|  tttj| } |dds0td|dk	r@||d< |dt	  zh|dk	r|
ddksltt||ks|t|d	rtj |d
< |d< t| ||d}ntj| f|}W n: tk
r } z|jtjkrt| | W 5 d}~X Y nX |s|jrt|j z|  W n0 tjk
rH } zt|j W 5 d}~X Y nX |S )zRun the command described by ``cmd``
        with ``check=True`` and return its completed process.

    Raises:
        CalledProcessError: if the returncode of the subprocess is non-zero.
    zrun %rcheckTzcheck must be True or omitedNr   startupinfoinputr   stdoutstderr)r   )logdebuglistmapr   Zmake_subprocess_argpopNotImplementedError
setdefaultZget_startupinfogetAssertionErroriter
subprocessPIPE_run_input_linesrunOSErrorerrnoENOENTr   r   _write_stderrcheck_returncoder   args)r
   r   r   r	   r   procer   r   r   r   2   s4    


c                C   sT   t j| fdt ji|}|jj}|D ]}|| q$| \}}t j|j|j||dS )Nstdin)r   r   )	r    Popenr!   r,   writecommunicateCompletedProcessr)   
returncode)r
   r   r   popenZstdin_writeliner   r   r   r   r   r"   b   s    
 r"   r   c                 C   sD   t | tr*ttjdd pt }| |} tj|  tj  d S )Nr   )	
isinstancebytesgetattrsysr   getdefaultencodingdecoder.   flush)r   Zstderr_encodingr   r   r   r'   n   s    


r'   c                       s*   e Zd ZdZdZdd fddZ  ZS )r   zC:exc:`RuntimeError` raised if the Graphviz executable is not found.zTfailed to execute {!r}, make sure the Graphviz executables are on your systems' PATHNr4   c                    s   t  | jj|  d S )N)super__init___msgformat)selfr)   	__class__r   r   r=      s    zExecutableNotFound.__init__)__name__
__module____qualname____doc__r>   r=   __classcell__r   r   rA   r   r   y   s   c                       s&   e Zd ZdZdd fddZ  ZS )r   zY:exc:`~subprocess.CalledProcessError` raised if a subprocess ``returncode`` is not ``0``.strr4   c                    s   t    d| jdS )Nz
 [stderr: ])r<   __str__r   )r@   rA   r   r   rJ      s    zCalledProcessError.__str__)rC   rD   rE   rF   rJ   rG   r   r   rA   r   r      s   )rF   r%   loggingosr    r8   typing r   __all__	getLoggerrC   r   UnionIteratorr6   rH   ZBytesOrStrIteratoroverloadSequencePathLikeOptionalboolr0   r   r"   r'   RuntimeErrorr   r   r   r   r   r   <module>   sp   


0
