o
    ooic                     @   s   d Z ddlZddlmZ g dZdZeeddd	ZeeZe	d
d eD Z
ddddZe ee ks8J dZdedefddZdedefddZG dd dejZdS )ADisplay rendered graph as SVG in Jupyter Notebooks and QtConsole.    N   )piping)JUPYTER_FORMATSSUPPORTED_JUPYTER_FORMATSDEFAULT_JUPYTER_FORMATget_jupyter_format_mimetypeJupyterIntegration
image/jpeg	image/pngimage/svg+xml)jpegjpgpngsvgc                 c   s    | ]	}|d kr|V  qdS )r   N ).0_r   r   P/home/ubuntu/.local/lib/python3.10/site-packages/graphviz/jupyter_integration.py	<genexpr>   s    r   _repr_image_jpeg_repr_image_png_repr_image_svg_xml)r
   r   r   zutf-8jupyter_formatreturnc              	   C   s4   zt |  W S  ty   td| dtt  dw )Nzunknown jupyter_format:  (must be one of ))r   KeyError
ValueErrorsorted)r   r   r   r   r       s   


r   mimetypec                 C   sX   | t vrtd| dtt  d| t v sJ t D ]\}}|| kr)|  S qt)Nzunsupported mimetype: r   r   )
MIME_TYPESr   r   r   valuesitemsRuntimeError)r    formatjupyter_mimetyper   r   r   get_jupyter_mimetype_format(   s   

r'   c                   @   s   e Zd ZdZeeZ		ddejej	e
  dejej	e
  deje
ejee
f f fddZdefdd	Zdefd
dZde
fddZdS )r	   r   Nincludeexcluder   c                    s@    durt  njh  t |pg 8   fddt D S )a+  Return the rendered graph as IPython mimebundle.

        Args:
            include: Iterable of mimetypes to include in the result.
                If not given or ``None``: ``['image/sxg+xml']``.
            exclude: Iterable of minetypes to exclude from the result.
                Overrides ``include``.

        Returns:
            Mapping from mimetypes to data.

        Example:
            >>> doctest_mark_exe()
            >>> import graphviz
            >>> dot = graphviz.Graph()
            >>> dot._repr_mimebundle_()  # doctest: +ELLIPSIS
            {'image/svg+xml': '<?xml version=...
            >>> dot._repr_mimebundle_(include=['image/png'])  # doctest: +ELLIPSIS
            {'image/png': b'\x89PNG...
            >>> dot._repr_mimebundle_(include=[])
            {}
            >>> dot._repr_mimebundle_(include=['image/svg+xml', 'image/jpeg'],
            ...                       exclude=['image/svg+xml'])  # doctest: +ELLIPSIS
            {'image/jpeg': b'\xff...
            >>> list(dot._repr_mimebundle_(include=['image/png', 'image/jpeg']))
            ['image/jpeg', 'image/png']

        See also:
            IPython documentation:
            - https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#functions
            - https://ipython.readthedocs.io/en/stable/config/integrating.html#MyObject._repr_mimebundle_  # noqa: E501
            - https://nbviewer.org/github/ipython/ipython/blob/master/examples/IPython%20Kernel/Custom%20Display%20Logic.ipynb#Custom-Mimetypes-with-_repr_mimebundle_  # noqa: E501
        Nc                    s&   i | ]\}}| v r|t | qS r   )getattr)r   r    method_namer(   selfr   r   
<dictcomp>b   s
    z8JupyterIntegration._repr_mimebundle_.<locals>.<dictcomp>)set_jupyter_mimetyper!   r#   )r-   r(   r)   r   r   r,   r   _repr_mimebundle_;   s
   %z$JupyterIntegration._repr_mimebundle_c                 C      | j ddS )z(Return the rendered graph as JPEG bytes.r   r%   piper-   r   r   r   r   f      z#JupyterIntegration._repr_image_jpegc                 C   r2   )z'Return the rendered graph as PNG bytes.r   r3   r4   r6   r   r   r   r   j   r7   z"JupyterIntegration._repr_image_pngc                 C   s   | j dtdS )z(Return the rendered graph as SVG string.r   )r%   encoding)r5   SVG_ENCODINGr6   r   r   r   r   n   s   z&JupyterIntegration._repr_image_svg_xml)NN)__name__
__module____qualname____doc__r   r   r0   typingOptionalIterablestrDictUnionbytesr1   r   r   r   r   r   r   r   r	   6   s    
+r	   )r=   r>    r   __all___IMAGE_JPEGr   r/   r   nextr   r!   keysr"   r9   rA   r   r'   Piper	   r   r   r   r   <module>   s*    