
    cic                        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
 eD              Z
ddddZej                          eej                               k(  sJ dZdedefdZdedefdZ G d dej$                        Zy)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              #   ,   K   | ]  }|d k(  s	|  yw)r   N ).0_s     C/tmp/pip-target-z3e9_cxr/lib/python/graphviz/jupyter_integration.py	<genexpr>r      s     QAa5jaQs   
_repr_image_jpeg_repr_image_png_repr_image_svg_xml)r   r   r   zutf-8jupyter_formatreturnc           	      n    	 t         |    S # t        $ r  t        d| dt        t                d      w xY w)Nzunknown jupyter_format:  (must be one of ))r   KeyError
ValueErrorsorted)r   s    r   r	   r	       sP    I~.. I3N3E,VO-D,EQH I 	IIs    )4mimetypec                     | t         vrt        d| dt        t                d      | t        j	                         v sJ t        j                         D ]  \  }}|| k(  s|c S  t        )Nzunsupported mimetype: r   r   )
MIME_TYPESr!   r"   r   valuesitemsRuntimeError)r#   formatjupyter_mimetypes      r   get_jupyter_mimetype_formatr+   (   s    z!1(,VJ-?,@C D 	D --////$3$9$9$;   x'M     c                      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ZdefdZdefdZde
fd	Zy)r
   r   Nincludeexcluder   c           
          |t        |      n| j                  h}|t        |xs g       z  }t        j                         D ci c]  \  }}||v r| t	        | |              c}}S c c}}w )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
        )set_jupyter_mimetyper%   r'   getattr)selfr.   r/   r   r#   method_names         r   _repr_mimebundle_z$JupyterIntegration._repr_mimebundle_;   sx    J #*"5#g,D<R<R;S3w}"%%-7-=-=-?()Hkw& 4'$466 ( 	( (s    A(c                 &    | j                  d      S )z(Return the rendered graph as JPEG bytes.r   r)   piper4   s    r   r   z#JupyterIntegration._repr_image_jpegf   s    yyy''r,   c                 &    | j                  d      S )z'Return the rendered graph as PNG bytes.r   r8   r9   r;   s    r   r   z"JupyterIntegration._repr_image_pngj   s    yyy&&r,   c                 0    | j                  dt              S )z(Return the rendered graph as SVG string.r   )r)   encoding)r:   SVG_ENCODINGr;   s    r   r   z&JupyterIntegration._repr_image_svg_xmln   s    yyy==r,   )NN)__name__
__module____qualname____doc__r	   r   r2   typingOptionalIterablestrDictUnionbytesr6   r   r   r   r   r,   r   r
   r
   6   s    K34JK LPKO)(#)??6??33G#H)(#)??6??33G#H)( #)++c6<<s
3K.K"L)(V(% (' '>S >r,   r
   )rC   rD    r   __all___IMAGE_JPEGr   r1   r   nextr   r%   keysr&   r?   rG   r	   r+   Piper
   r   r,   r   <module>rQ      s    G  !
 &%%)+
  0 Q)BQQ .,46
 C 6 6 899 99I I I# # :> :>r,   