U
    d/e#                     @   sT  d Z ddlZddlmZ ddlmZ ddlmZ dd	d
dgZejdddeee	ej
e ej
e ejeedf ee	dddZdddddeeeeej
e ej
e ejeedf eed	dd	Zdddddeeeje eej
e ej
e ejeedf ee	d	dd
Zdddddeeeje eej
e ej
e ejeedf eed	ddZdS )zBPipe bytes, strings, or string iterators through Graphviz ``dot``.    N   )_tools   )dot_command)executepipepipe_string
pipe_linespipe_lines_string   )Zsupported_numberF)engineformatdatarenderer	formatterneato_no_opquietreturnc           
      C   s:   t j| ||||d}d|i}tj|fd|d|}	|	jS )a-  Return ``data`` (``bytes``) piped through ``engine`` into ``format`` as ``bytes``.

    Args:
        engine: Layout engine for rendering (``'dot'``, ``'neato'``, ...).
        format: Output format for rendering (``'pdf'``, ``'png'``, ...).
        data: Binary (encoded) DOT source bytes to render.
        renderer: Output renderer (``'cairo'``, ``'gd'``, ...).
        formatter: Output formatter (``'cairo'``, ``'gd'``, ...).
        neato_no_op: Neato layout engine no-op flag.
        quiet: Suppress ``stderr`` output from the layout subprocess.

    Returns:
        Binary (encoded) stdout of the layout command.

    Raises:
        ValueError: If ``engine``, ``format``, ``renderer``, or ``formatter``
            are unknown.
        graphviz.RequiredArgumentError: If ``formatter`` is given
            but ``renderer`` is None.
        graphviz.ExecutableNotFound: If the Graphviz ``dot`` executable
            is not found.
        graphviz.CalledProcessError: If the returncode (exit status)
            of the rendering ``dot`` subprocess is non-zero.

    Example:
        >>> doctest_mark_exe()
        >>> import graphviz
        >>> graphviz.pipe('dot', 'svg', b'graph { hello -- world }')[:14]
        b'<?xml version='

    Note:
        The layout command is started from the current directory.
    r   r   r   inputTcapture_outputr   r   commandr   Z	run_checkstdout)
r   r   r   r   r   r   r   cmdkwargsproc r   ;/tmp/pip-unpacked-wheel-n8ok7rre/graphviz/backend/piping.pyr      s    ')r   r   r   r   )	r   r   input_stringencodingr   r   r   r   r   c                C   s<   t j| ||||d}||d}	tj|fd|d|	}
|
jS )a  Return ``input_string`` piped through ``engine`` into ``format`` as string.

    Args:
        engine: Layout engine for rendering (``'dot'``, ``'neato'``, ...).
        format: Output format for rendering (``'pdf'``, ``'png'``, ...).
        input_string: Binary (encoded) DOT source bytes to render.
        encoding: Encoding to en/decode subprocess stdin and stdout (required).
        renderer: Output renderer (``'cairo'``, ``'gd'``, ...).
        formatter: Output formatter (``'cairo'``, ``'gd'``, ...).
        neato_no_op: Neato layout engine no-op flag.
        quiet: Suppress ``stderr`` output from the layout subprocess.

    Returns:
        Decoded stdout of the layout command.

    Raises:
        ValueError: If ``engine``, ``format``, ``renderer``, or ``formatter``
            are unknown.
        graphviz.RequiredArgumentError: If ``formatter`` is given
            but ``renderer`` is None.
        graphviz.ExecutableNotFound: If the Graphviz ``dot`` executable
            is not found.
        graphviz.CalledProcessError: If the returncode (exit status)
            of the rendering ``dot`` subprocess is non-zero.

    Example:
        >>> doctest_mark_exe()
        >>> import graphviz
        >>> graphviz.pipe_string('dot', 'svg', 'graph { spam }',
        ...                      encoding='ascii')[:14]
        '<?xml version='

    Note:
        The layout command is started from the current directory.
    r   )r   r!   Tr   r   )r   r   r    r!   r   r   r   r   r   r   r   r   r   r   r   ?   s    )
)	r   r   input_linesinput_encodingr   r   r   r   r   c                   sH   t j| ||||d}d fdd|D i}	tj|fd|d|	}
|
jS )a  Return ``input_lines`` piped through ``engine`` into ``format`` as ``bytes``.

    Args:
        engine: Layout engine for rendering (``'dot'``, ``'neato'``, ...).
        format: Output format for rendering (``'pdf'``, ``'png'``, ...).
        input_lines: DOT source lines to render (including final newline).
        input_encoding: Encode input_lines for subprocess stdin (required).
        renderer: Output renderer (``'cairo'``, ``'gd'``, ...).
        formatter: Output formatter (``'cairo'``, ``'gd'``, ...).
        neato_no_op: Neato layout engine no-op flag.
        quiet: Suppress ``stderr`` output from the layout subprocess.

    Returns:
        Binary stdout of the layout command.

    Raises:
        ValueError: If ``engine``, ``format``, ``renderer``, or ``formatter``
            are unknown.
        graphviz.RequiredArgumentError: If ``formatter`` is given
            but ``renderer`` is None.
        graphviz.ExecutableNotFound: If the Graphviz ``dot`` executable
            is not found.
        graphviz.CalledProcessError: If the returncode (exit status)
            of the rendering ``dot`` subprocess is non-zero.

    Example:
        >>> doctest_mark_exe()
        >>> import graphviz
        >>> graphviz.pipe_lines('dot', 'svg', iter(['graph { spam }\n']),
        ...                     input_encoding='ascii')[:14]
        b'<?xml version='

    Note:
        The layout command is started from the current directory.
    r   r"   c                 3   s   | ]}|  V  qd S )N)encode).0liner#   r   r   	<genexpr>   s     zpipe_lines.<locals>.<genexpr>Tr   r   )r   r   r"   r#   r   r   r   r   r   r   r   r   r'   r   r	   r   s    ))	r   r   r"   r!   r   r   r   r   r   c                C   s<   t j| ||||d}||d}	tj|fd|d|	}
|
jS )a  Return ``input_lines`` piped through ``engine`` into ``format`` as string.

    Args:
        engine: Layout engine for rendering (``'dot'``, ``'neato'``, ...).
        format: Output format for rendering (``'pdf'``, ``'png'``, ...).
        input_lines: DOT source lines to render (including final newline).
        encoding: Encoding to en/decode subprocess stdin and stdout (required).
        renderer: Output renderer (``'cairo'``, ``'gd'``, ...).
        formatter: Output formatter (``'cairo'``, ``'gd'``, ...).
        neato_no_op: Neato layout engine no-op flag.
        quiet: Suppress ``stderr`` output from the layout subprocess.

    Returns:
        Decoded stdout of the layout command.

    Raises:
        ValueError: If ``engine``, ``format``, ``renderer``, or ``formatter``
            are unknown.
        graphviz.RequiredArgumentError: If ``formatter`` is given
            but ``renderer`` is None.
        graphviz.ExecutableNotFound: If the Graphviz ``dot`` executable
            is not found.
        graphviz.CalledProcessError: If the returncode (exit status)
            of the rendering ``dot`` subprocess is non-zero.

    Example:
        >>> doctest_mark_exe()
        >>> import graphviz
        >>> graphviz.pipe_lines_string('dot', 'svg', iter(['graph { spam }\n']),
        ...                            encoding='ascii')[:14]
        '<?xml version='

    Note:
        The layout command is started from the current directory.
    r   )r"   r!   Tr   r   )r   r   r"   r!   r   r   r   r   r   r   r   r   r   r   r
      s    )
)NNNF)__doc__typing r   r   r   __all__Zdeprecate_positional_argsstrbytesOptionalUnionboolintr   r   Iteratorr	   r
   r   r   r   r   <module>   sp    
     2
 5 5 