o
    ooi,                      @   sv   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlmZ dgZ	e
eZG dd dejejejZdS )	zHSave DOT code objects, render with Graphviz ``dot``, and open in viewer.    N   )_tools)backend)savingRenderc                !   @   sR  e Zd ZdZejddd										dddddddejej	e
df d	ejej	e
df d
ededeje
 deje
 deje
 dejeedf dededejej	e
df deje
 dedede
fddZdejej	e
f de
deddfddZejddd					ddejej	e
df d	ejej	e
df dededede
fddZdS ) r   z4Write source lines to file and render with Graphviz.r   self)supported_number
ignore_argNF)outfileengineraise_if_result_existsoverwrite_sourcefilename	directoryviewcleanupformatrenderer	formatterneato_no_opquiet
quiet_viewr
   r   r   r   returnc                C   s   t |}|dur| j||d}|du rt| j|}| j||||||	|||dd
\}}|dur9|du r9| |}| j||dd}|	| | j
|i |}|r[td| t| |
s_|rh| j|| j|
d |S )aS  Save the source to file and render with the Graphviz engine.

        Args:
            filename: Filename for saving the source
                (defaults to ``name`` + ``'.gv'``).s
            directory: (Sub)directory for source saving and rendering.
            view (bool): Open the rendered result
                with the default application.
            cleanup (bool): Delete the source file
                after successful rendering.
            format: The output format used for rendering
                (``'pdf'``, ``'png'``, etc.).
            renderer: The output renderer used for rendering
                (``'cairo'``, ``'gd'``, ...).
            formatter: The output formatter used for rendering
                (``'cairo'``, ``'gd'``, ...).
            neato_no_op: Neato layout engine no-op flag.
            quiet (bool): Suppress ``stderr`` output
                from the layout subprocess.
            quiet_view (bool): Suppress ``stderr`` output
                from the viewer process
                (implies ``view=True``, ineffective on Windows platform).
            outfile: Path for the rendered output file.
            engine: Layout engine for rendering
                (``'dot'``, ``'neato'``, ...).
            raise_if_result_exists: Raise :exc:`graphviz.FileExistsError`
                if the result file exists.
            overwrite_source: Allow ``dot`` to write to the file it reads from.
                Incompatible with ``raise_if_result_exists``.

        Returns:
            The (possibly relative) path of the rendered file.

        Raises:
            ValueError: If ``engine``, ``format``, ``renderer``, or ``formatter``
                are unknown.
            graphviz.RequiredArgumentError: If ``formatter`` is given
                but ``renderer`` is None.
            ValueError: If ``outfile`` is the same file as the source file
                unless ``overwite_source=True``.
            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.
            RuntimeError: If viewer opening is requested but not supported.

        Example:
            >>> doctest_mark_exe()
            >>> import graphviz
            >>> dot = graphviz.Graph(name='spam', directory='doctest-output')
            >>> dot.render(format='png').replace('\\', '/')
            'doctest-output/spam.gv.png'
            >>> dot.render(outfile='spam.svg').replace('\\', '/')
            'doctest-output/spam.svg'

        Note:
            The layout command is started from the directory of ``filepath``,
            so that references to external files
            (e.g. ``[image=images/camelot.png]``)
            can be given as paths relative to the DOT source file.
        N)r   T)
r   r   r   r   r   r   r
   r   r   verify)r   skip_existingz	delete %r)r   r   )r   promote_pathlike_get_formatpathlibPathr   _get_render_parameters_get_filepathsaveappend_renderlogdebugosremove_view_format)r   r   r   r   r   r   r   r   r   r   r   r
   r   r   r   argskwargsfilepathrendered r.   F/home/ubuntu/.local/lib/python3.10/site-packages/graphviz/rendering.pyrender   s6   
M



zRender.renderr,   c                C   st   d| dt jj dt jj g}|D ]}t| |d}|dur! nqt| jd|dt jjd|||d dS )z9Start the right viewer based on file format and platform._view__Nz$ has no built-in viewer support for z on z	 platform)r   )r   viewingPLATFORMgetattrRuntimeError	__class__)r   r,   r   r   methodnamesnameview_methodr.   r.   r/   r(      s   

zRender._viewc                 C   s   | j ||d|||dS )a  Save the source to file, open the rendered result in a viewer.

        Convenience short-cut for running ``.render(view=True)``.

        Args:
            filename: Filename for saving the source
                (defaults to ``name`` + ``'.gv'``).
            directory: (Sub)directory for source saving and rendering.
            cleanup (bool): Delete the source file after successful rendering.
            quiet (bool): Suppress ``stderr`` output from the layout subprocess.
            quiet_view (bool): Suppress ``stderr`` output
                from the viewer process (ineffective on Windows).

        Returns:
            The (possibly relative) path of the rendered file.

        Raises:
            graphviz.ExecutableNotFound: If the Graphviz executable
                is not found.
            graphviz.CalledProcessError: If the exit status is non-zero.
            RuntimeError: If opening the viewer is not supported.

        Short-cut method for calling :meth:`.render` with ``view=True``.

        Note:
            There is no option to wait for the application to close,
            and no way to retrieve the application's exit status.
        T)r   r   r   r   r   r   )r0   )r   r   r   r   r   r   r.   r.   r/   r      s   
#zRender.view)
NNFFNNNNFF)NNFFF)__name__
__module____qualname____doc__r   deprecate_positional_argstypingUnionr&   PathLikestrboolOptionalintr0   r(   r   r.   r.   r.   r/   r      s    	
o
)r>   loggingr&   r   r@    r   r   r   __all__	getLoggerr;   r$   Saver   Viewr.   r.   r.   r/   <module>   s    
