o
    ooij                     @   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 g dZ	e
eZejeje eje f Zejdddddejejejef  d	ejeje  d
ddedejf
ddZejddddejejejef  d	ejeje  d
ededejf
ddZejddddddejejejef  d	eje d
eje dededejfddZdddddejejejef  d	eje d
eje dedejf
ddZdd Z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      dS )z9Accept bytes input_lines with default ``encoding=None```.N r
   r   r   r	   kwargsr   r   L/home/ubuntu/.local/lib/python3.10/site-packages/graphviz/backend/execute.pyr          r   )r   r	   c                K   r   )z2Accept string input_lines when given ``encoding``.Nr   r   r   r   r   r      r   )r   r   capture_outputr	   r   c                K   r   )z=Accept bytes or string input_lines depending on ``encoding``.Nr   )r
   r   r   r   r	   r   r   r   r   r   (   r   Fc             
   K   s&  t d|  |ddstd|dur||d< |dt  z6|durL|ddu s.J t||u s6J |d	rDt	j
 |d
< |d< t| ||d}n	t	j| fi |}W n tyn } z|jtjkrit| | d}~ww |sy|jryt|j z|  W |S  t	jy } zt|j d}~ww )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popNotImplementedError
setdefaultr   get_startupinfoget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   s<   





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   popenstdin_writeliner   r   r   r   r   r"   _   s   
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   stderr_encodingr   r   r   r'   k   s   


r'   c                       s&   e Zd ZdZdZ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' PATHr   Nc                    s   t  | jj|  d S )N)super__init___msgformat)selfr)   	__class__r   r   r>   |      zExecutableNotFound.__init__r   N)__name__
__module____qualname____doc__r?   r>   __classcell__r   r   rB   r   r   v   s    r   c                       s"   e Zd ZdZd fddZ  ZS )r   zY:exc:`~subprocess.CalledProcessError` raised if a subprocess ``returncode`` is not ``0``.r   strc                    s   t    d| jdS )Nz
 [stderr: ])r=   __str__r   )rA   rB   r   r   rM      rD   zCalledProcessError.__str__)r   rK   )rF   rG   rH   rI   rM   rJ   r   r   rB   r   r      s    r   rE   )rI   r%   loggingosr    r8   typing r   __all__	getLoggerrF   r   UnionIteratorr6   rK   BytesOrStrIteratoroverloadSequencePathLikeOptionalboolr0   r   r"   r'   RuntimeErrorr   r   r   r   r   r   <module>   s    


-

