"""Pipe bytes, strings, or string iterators through Graphviz ``dot``.""" import typing from .. import _tools from . import dot_command from . import execute __all__ = ['pipe', 'pipe_string', 'pipe_lines', 'pipe_lines_string'] @_tools.deprecate_positional_args(supported_number=3) def pipe(engine: str, format: str, data: bytes, renderer: typing.Optional[str] = None, formatter: typing.Optional[str] = None, neato_no_op: typing.Union[bool, int, None] = None, quiet: bool = False) -> bytes: """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' str: """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] ' bytes: r"""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' str: r"""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] '