U
    d/ec                     @   s   d Z ddlZddlmZ ddddd	g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svtdZeedddZeed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)jpegZjpgpngsvgc                 c   s   | ]}|d kr|V  qdS )r   N ).0_r   r   @/tmp/pip-unpacked-wheel-n8ok7rre/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   s>   z
t |  W S  tk
r8   td| dtt  dY nX d S )Nzunknown jupyter_format:  (must be one of ))r   KeyError
ValueErrorsorted)r   r   r   r   r       s    
)mimetyper   c                 C   s\   | t kr"td| dtt  d| t ks2tt D ]\}}|| kr:|  S q:td S )Nzunsupported mimetype: r   r   )
MIME_TYPESr   r   r   valuesAssertionErroritemsRuntimeError)r   formatZjupyter_mimetyper   r   r   get_jupyter_mimetype_format(   s    
r&   c                   @   s   e Zd ZdZeeZdejej	e
  ejej	e
  eje
ejee
f f dddZedddZedd	d
Ze
dddZdS )r	   r   N)includeexcluder   c                    s@    dk	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 | ]\}}| k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_)r   c                 C   s   | j ddS )z(Return the rendered graph as JPEG bytes.r   r%   piper,   r   r   r   r   f   s    z#JupyterIntegration._repr_image_jpegc                 C   s   | j ddS )z'Return the rendered graph as PNG bytes.r   r1   r2   r4   r   r   r   r   j   s    z"JupyterIntegration._repr_image_pngc                 C   s   | j dtdS )z(Return the rendered graph as SVG string.r   )r%   encoding)r3   SVG_ENCODINGr4   r   r   r   r   n   s    z&JupyterIntegration._repr_image_svg_xml)NN)__name__
__module____qualname____doc__r   r   r/   typingOptionalIterablestrDictUnionbytesr0   r   r   r   r   r   r   r   r	   6   s     +)r:   r;    r   __all__Z_IMAGE_JPEGr   r.   r   nextr   r    keysr!   r"   r6   r>   r   r&   ZPiper	   r   r   r   r   <module>   s2    