
    f                     &   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dl
mZ dd	lmZ dd
lmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ  G d de	      Zd Z  G d de!      Z"ed        Z# G d dejH                        Z%d Z&d Z' ede(d      Z) G d de	      Z* G d de*      Z+ G d d e*      Z, G d! d"e*      Z- G d# d$e*      Z. G d% d&e*      Z/ G d' d(e*      Z0 G d) d*e*      Z1 G d+ d,e*      Z2 G d- d.e*      Z3 G d/ d0e*      Z4 G d1 d2e*      Z5 G d3 d4e*      Z6e%jo                  e*       e%jo                  e+       e%jo                  e,       e%jo                  e-       e%jo                  e.       e%jo                  e/       e%jo                  e4       e%jo                  e0       e%jo                  e1       e%jo                  e2       e%jo                  e3       e%jo                  e5       e%jo                  e6       d6d5Z8y)7ziDisplay formatters.

Inheritance diagram:

.. inheritance-diagram:: IPython.core.formatters
   :parts: 3
    N)StringIO)	decorator)Configurable   )get_ipython   )Sentinel)get_real_method)pretty)
BoolDictIntegerUnicodeCUnicode
ObjectNameListForwardDeclaredInstancedefaultobserve)Anyc                      e Zd Z e e       d      j                  d      Z ed      d        Z e	d      d        Z
 ed      Z ed	      d
        Z ed      Z ed      d        Z e       Z ed      d        ZddZed        Zy)DisplayFormatterzList of currently active mime-types to display.
        You can use this to set a white-list for formats to display.
        
        Most users will not need to change this value.
        helpTconfigactive_typesc                     | j                   S N)format_typesselfs    R/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/core/formatters.py_active_types_defaultz&DisplayFormatter._active_types_default,   s           c                 t    | j                   j                         D ]  \  }}||d   v rd|_        d|_         y )NnewTF)
formattersitemsenabled)r"   changekey	formatters       r#   _active_types_changedz&DisplayFormatter._active_types_changed0   s>    "oo335 	*NCfUm#$(	!$)	!		*r%   FormatterABCipython_display_formatterc                     t        |       S Nparent)IPythonDisplayFormatterr!   s    r#   _default_formatterz#DisplayFormatter._default_formatter9   s    &d33r%   mimebundle_formatterc                     t        |       S r2   )MimeBundleFormatterr!   s    r#   _default_mime_formatterz(DisplayFormatter._default_mime_formatter>   s    "$//r%   r(   c           
          t         t        t        t        t        t
        t        t        t        t        g
}i }|D ]  } ||       }|||j                  <    |S )z Activate the default formatters.r3   )PlainTextFormatterHTMLFormatterMarkdownFormatterSVGFormatterPNGFormatterPDFFormatterJPEGFormatterLatexFormatterJSONFormatterJavascriptFormatterformat_type)r"   formatter_classesdclsfs        r#   _formatters_defaultz$DisplayFormatter._formatters_defaultE   s_     
 $ 	!C4 A Aamm	! r%   Nc                    i }i }| j                  |      ri i fS | j                  |||      \  }}|s|r|rP|j                         D ci c]  \  }}||v s|| }}}|j                         D ci c]  \  }}||v s|| }}}|rP|j                         D ci c]  \  }}||vs|| }}}|j                         D ci c]  \  }}||vs|| }}}| j                  j                         D ]f  \  }}	||v r	 |	j	                  |       |r||vr#|r||v r*d}
	  |	|      }t        |t              rt        |      dk(  r|\  }}
||||<   |
b|
||<   h ||fS c c}}w c c}}w c c}}w c c}}w # t
        $ r Y w xY w#   xY w)a  Return a format data dict for an object.

        By default all format types will be computed.

        The following MIME types are usually implemented:

        * text/plain
        * text/html
        * text/markdown
        * text/latex
        * application/json
        * application/javascript
        * application/pdf
        * image/png
        * image/jpeg
        * image/svg+xml

        Parameters
        ----------
        obj : object
            The Python object whose format data will be computed.
        include : list, tuple or set; optional
            A list of format type strings (MIME types) to include in the
            format data dict. If this is set *only* the format types included
            in this list will be computed.
        exclude : list, tuple or set; optional
            A list of format type string (MIME types) to exclude in the format
            data dict. If this is set all format types will be computed,
            except for those included in this argument.
            Mimetypes present in exclude will take precedence over the ones in include

        Returns
        -------
        (format_dict, metadata_dict) : tuple of two dicts
            format_dict is a dictionary of key/value pairs, one of each format that was
            generated for the object. The keys are the format types, which
            will usually be MIME type strings and the values and JSON'able
            data structure containing the raw data for the representation in
            that format.

            metadata_dict is a dictionary of metadata about each mime-type output.
            Its keys will be a strict subset of the keys in format_dict.

        Notes
        -----
            If an object implement `_repr_mimebundle_` as well as various
            `_repr_*_`, the data returned by `_repr_mimebundle_` will take
            precedence and the corresponding `_repr_*_` for this mimetype will
            not be called.

        includeexcludeNr   )	r0   r7   r)   r(   lookupKeyError
isinstancetuplelen)r"   objrN   rO   format_dictmd_dictkvrF   r-   mddatas               r#   formatzDisplayFormatter.formatZ   s   h ))#.r6M#88gW^8_W'.9.?.?.ARsqQ'\qsRR*1--/J31QQ'\1Q3JJ.9.?.?.AVsqQgEUqsVV*1--/N31QQg=M1Q3NN&*oo&;&;&=  	*"Kk)$$S) ;g5;'1B ~ $&3t9>b+/K(~')$A 	*B G##O SJVN   sN   
E E 2E&?E&E,)E,E2E2>E8 F8	FFF
c                 H    t        | j                  j                               S )z>Return the format types (MIME types) of the active formatters.)listr(   keysr!   s    r#   r    zDisplayFormatter.format_types   s     DOO((*++r%   NN)__name__
__module____qualname__r   r   tagr   r   r$   r   r.   r   r0   r6   r7   r:   r   r(   rK   r\   propertyr     r%   r#   r   r   #   s    	
 SS  ^! ! ^* * !8 G()4 *4 3>B#$0 %0
 J\ (f$P , ,r%   r   c                 P    	 t        |       S # t        $ r}d|z  cY d}~S d}~ww xY w)zNTry to return a repr of an object

    always returns a string, at least.
    zun-repr-able object (%r)N)repr	Exception)rU   es     r#   
_safe_reprrk      s,    
.Cy .)A--.s   
 	% %%c                       e Zd ZdZy)FormatterWarningz&Warning class for errors in formattersN)ra   rb   rc   __doc__rf   r%   r#   rm   rm      s    0r%   rm   c                 T   	  | |g|i |}|j                  ||d         S # t         $ r |j                  d|d         cY S t        $ r\ t        j                         }t               }||j                  |       nt        j                  |  |j                  d|d         cY S w xY w)z$show traceback on failed format callNr   )	NotImplementedError_check_returnri   sysexc_infor   showtraceback	tracebackprint_exception)methodr"   argskwargsrrs   ips          r#   catch_format_errorr|      s    14)$)&) aa))  1!!$Q00 1<<>]>X&%%x0!!$Q001s   # B'A!B'&B'c                   <    e Zd ZdZdZdZej                  d        Zy)r/   aE   Abstract base class for Formatters.

    A formatter is a callable class that is responsible for computing the
    raw format data for a particular format type (MIME type). For example,
    an HTML formatter would have a format type of `text/html` and would return
    the HTML representation of the object when called.
    
text/plainTc                     t        |      S )zReturn a JSON'able representation of the object.

        If the object cannot be formatted by this formatter,
        warn and return None.
        )rh   )r"   rU   s     r#   __call__zFormatterABC.__call__   s     Cyr%   N)	ra   rb   rc   rn   rF   r*   abcabstractmethodr   rf   r%   r#   r/   r/      s-     K G r%   r/   )	metaclassc                 >    t        | dd      }t        | dd      }||fS )zgReturn a (__module__, __name__) tuple for a type.

    Used as key in Formatter.deferred_printers.
    rb   Nra   )getattr)typmodulenames      r#   _mod_name_keyr     s*    
 S,-F3
D)DD>r%   c                 6    t        | dd      xs t        |       S )z2Return the type of an instance (old and new-style)	__class__N)r   type)rU   s    r#   	_get_typer     s    3T*7d3i7r%   _raise_key_errorzr
Special value to raise a KeyError

Raise KeyError in `BaseFormatter.pop` if passed as the default value to `pop`
c                   B   e Zd ZU dZ ed      ZeZee	d<    e
d      j                  d      Z ed      Z e       j                  d      Z e       j                  d      Z e       j                  d      Zed        Zd Zd	 Zd
 Zd ZddZddZefdZd Zy)BaseFormattera  A base formatter class that is configurable.

    This formatter should usually be used as the base class of all formatters.
    It is a traited :class:`Configurable` class and includes an extensible
    API for users to determine how their objects are formatted. The following
    logic is used to find a function to format an given object.

    1. The object is introspected to see if it has a method with the name
       :attr:`print_method`. If is does, that object is passed to that method
       for formatting.
    2. If no print method is found, three internal dictionaries are consulted
       to find print method: :attr:`singleton_printers`, :attr:`type_printers`
       and :attr:`deferred_printers`.

    Users should use these dictionaries to register functions that will be
    used to compute the format data for their objects (if those objects don't
    have the special print methods). The easiest way of using these
    dictionaries is through the :meth:`for_type` and :meth:`for_type_by_name`
    methods.

    If no function/callable is found to compute the format data, ``None`` is
    returned and this format type is not used.
    r~   _return_typeTr   __repr__c                     | j                   r	 | j                  |      } ||      S y# t        $ r Y nw xY wt        || j                        }| |       S y)!Compute the format for an object.Nr*   rP   rQ   r
   print_methodr"   rU   printerrw   s       r#   r   zBaseFormatter.__call__J  sg     <<$++c* s|#   
 %S$*;*;<F!x   ( 	44c                 F    	 | j                  |       y# t        $ r Y yw xY w)zmap in to lookup_by_typeTF)lookup_by_typerQ   )r"   r   s     r#   __contains__zBaseFormatter.__contains__]  s.    	$   		s    	  c                 $   |At        || j                        s+t        |t              r|rt        |d   | j                        r|S t        j                  | j
                  dt        |      d| j                  dt        |      t               y)vCheck that a return value is appropriate

        Return the value if so, None otherwise, warning if invalid.
        Nr   z! formatter returned invalid type z (expected z) for object: )	rR   r   rS   warningswarnrF   r   rk   rm   )r"   rz   rU   s      r#   rq   zBaseFormatter._check_returnf  sn    
 9
1d&7&785!aJqtT=N=N,OHMM!!47D,=,=z#P r%   c                     t        |      }|| j                  v r| j                  |   S | j                  t        |            S )aA  Look up the formatter for a given instance.

        Parameters
        ----------
        obj : object instance

        Returns
        -------
        f : callable
            The registered formatting callable for the type.

        Raises
        ------
        KeyError if the type has not been registered.
        )idsingleton_printersr   r   )r"   rU   obj_ids      r#   rP   zBaseFormatter.lookupu  sA    " CT,,,**622""9S>22r%   c                    t        |t              rit        |j                  dd            }|| j                  vr1| j
                  D ]!  }t        |      |k(  s| j
                  |   c S  nY| j                  |   S t        j                  |      D ]2  }|| j
                  v s| j                  |      s#| j
                  |   c S  t        dj                  |            )ab  Look up the registered formatter for a type.

        Parameters
        ----------
        typ : type or '__module__.__name__' string for a type

        Returns
        -------
        f : callable
            The registered formatting callable for the type.

        Raises
        ------
        KeyError if the type has not been registered.
        .r   zNo registered printer for {0!r})rR   strrS   rsplitdeferred_printerstype_printersr   r   _get_mro_in_deferred_typesrQ   r\   )r"   r   typ_keyrI   s       r#   r   zBaseFormatter.lookup_by_type  s      c3CJJs1-.Gd444  -- 7C$S)W4#11#667 --g66s+ 3$,,,0G0G0L--c223
 8??DEEr%   Nc                     t        |t              r(|j                  dd      \  }}| j                  |||      S 	 | j	                  |      }||| j                  |<   |S # t
        $ r d}Y  w xY w)at  Add a format function for a given type.

        Parameters
        ----------
        typ : type or '__module__.__name__' string for a type
            The class of the object that will be formatted using `func`.

        func : callable
            A callable for computing the format data.
            `func` will be called with the object to be formatted,
            and will return the raw data in this formatter's format.
            Subclasses may use a different call signature for the
            `func` argument.

            If `func` is None or not specified, there will be no change,
            only returning the current value.

        Returns
        -------
        oldfunc : callable
            The currently registered callable.
            If you are registering a new formatter,
            this will be the previous value (to enable restoring later).
        r   r   N)rR   r   r   for_type_by_namer   rQ   r   )r"   r   functype_module	type_nameoldfuncs         r#   for_typezBaseFormatter.for_type  s    4 c3%(ZZQ%7"K((iFF	))#.G &*Ds#  	G	s   A A,+A,c                 |    ||f}	 | j                  d|z        }||| j                  |<   |S # t        $ r d}Y  w xY w)a"  Add a format function for a type specified by the full dotted
        module and name of the type, rather than the type of the object.

        Parameters
        ----------
        type_module : str
            The full dotted name of the module the type is defined in, like
            ``numpy``.

        type_name : str
            The name of the type (the class name), like ``dtype``

        func : callable
            A callable for computing the format data.
            `func` will be called with the object to be formatted,
            and will return the raw data in this formatter's format.
            Subclasses may use a different call signature for the
            `func` argument.

            If `func` is None or unspecified, there will be no change,
            only returning the current value.

        Returns
        -------
        oldfunc : callable
            The currently registered callable.
            If you are registering a new formatter,
            this will be the previous value (to enable restoring later).
        z%s.%sN)r   rQ   r   )r"   r   r   r   r,   r   s         r#   r   zBaseFormatter.for_type_by_name  sZ    < I&	))'C-8G *.D""3'  	G	s   - ;;c                    t        |t              rt        |j                  dd            }|| j                  vr?| j
                  D ]-  }t        |      |k(  s| j
                  j                  |      } no |}nk| j                  j                  |      }nO|| j
                  v r| j
                  j                  |      }n%| j                  j                  t        |      |      }|t        u rt        dj                  |            |S )a  Pop a formatter for the given type.

        Parameters
        ----------
        typ : type or '__module__.__name__' string for a type
        default : object
            value to be returned if no formatter is registered for typ.

        Returns
        -------
        obj : object
            The last registered object for the type.

        Raises
        ------
        KeyError if the type is not registered and default is not specified.
        r   r   zNo registered value for {0!r})rR   r   rS   r   r   r   r   popr   rQ   r\   )r"   r   r   r   rI   olds         r#   r   zBaseFormatter.pop  s    & c3CJJs1-.Gd444  -- "C$S)W4"0044S9"
 "C,,009d(((((,,S1,,00s1CWM"":AA#FGG
r%   c                     t        |dd      }t        |dd      }||f}|| j                  v r+| j                  j                  |      }|| j                  |<   yy)z
        Check if the given class is specified in the deferred type registry.

        Successful matches will be moved to the regular type registry for future use.
        rb   Nra   TF)r   r   r   r   )r"   rI   modr   r,   r   s         r#   r   z BaseFormatter._in_deferred_types(  sc     c<.sJ-Dk$(((,,005G&-Ds#r%   r   )ra   rb   rc   rn   r   rF   r   r   r   __annotations__r   rd   r*   r   r   r   r   r   r   r|   r   r   rq   rP   r   r   r   r   r   r   rf   r%   r#   r   r     s    0 ,'KL#4jnnDn)Gj)L 40 FJJdJ+M 

$
/ $3. FD&P'R  0 'Rr%   r   c                   (   e Zd ZdZ ed      Z ed      j                  d      Z e	e
j                  d      j                  d      Z ed      Z ed      j                  d      Z ed      j                  d      Z e	d	      j                  d      Z ed
      j                  d      Z ed      Z ed      j                  d      Z ed      d        Z ed      d        Z ed      d        Z ed      d        Zed        Zy)r<   a`  The default pretty-printer.

    This uses :mod:`IPython.lib.pretty` to compute the format data of
    the object. If the object cannot be pretty printed, :func:`repr` is used.
    See the documentation of :mod:`IPython.lib.pretty` for details on
    how to write pretty printers.  Here is a simple example::

        def dtype_pprinter(obj, p, cycle):
            if cycle:
                return p.text('dtype(...)')
            if hasattr(obj, 'fields'):
                if obj.fields is None:
                    p.text(repr(obj))
                else:
                    p.begin_group(7, 'dtype([')
                    for i, field in enumerate(obj.descr):
                        if i > 0:
                            p.text(',')
                            p.breakable()
                        p.pretty(field)
                    p.end_group(7, '])')
    r~   TFr   zTruncate large collections (lists, dicts, tuples, sets) to this size.
        
        Set to 0 to disable truncation.
        r   _repr_pretty_O   
%r float_precisionc                    |d   }d|v r|}	 |dz   || _        y|rI	 t        |      }|dk\  sJ 	 d|z  }d	t        j
                  v rHddl}|j                  |
       || _        yd}d	t        j
                  v rddl}|j                  d
       || _        y# t         $ r}t        d|z        |d}~ww xY w# t        $ r}t        d|z        |d}~wt        $ r}t        dz        |d}~ww xY w)a  float_precision changed, set float_format accordingly.

        float_precision can be set by int or str.
        This will set float_format, after interpreting input.
        If numpy has been imported, numpy print precision will also be set.

        integer `n` sets format to '%.nf', otherwise, format set directly.

        An empty string returns to defaults (repr for float, 8 for numpy).

        This parameter can be set via the '%precision' magic.
        r'   %gn!	@z.Precision must be int or format string, not %rNr   z*int precision must be non-negative, not %rz%%.%ifnumpy)	precisionr      )	ri   
ValueErrorintAssertionErrorrr   modulesr   set_printoptionsfloat_format)r"   r+   r'   fmtrj   ir   s          r#   _float_precision_changedz+PlainTextFormatter._float_precision_changeds  s"    Um#:C^G2  - XHAvv 1*C#++%&&&3   C#++%&&&31  ^ !QRU!UV\]]^  ^ !QRU!UV\]]! X !Ma!OPVWWXs:   B B7 	B4 B//B47	C/ CC/C**C/r   c                 >    t         j                  j                         S r   )r   _singleton_pprinterscopyr!   s    r#   _singleton_printers_defaultz.PlainTextFormatter._singleton_printers_default  s    **//11r%   r   c                      t         j                  j                         } fd|t        <   dt        j
                  v rdd l} fd||j                  <   |S )Nc                 @    |j                  j                  | z        S r   textr   rU   pcycler"   s      r#   <lambda>z;PlainTextFormatter._type_printers_default.<locals>.<lambda>  s    qvvd.?.?.C'D r%   r   r   c                 @    |j                  j                  | z        S r   r   r   s      r#   r   z;PlainTextFormatter._type_printers_default.<locals>.<lambda>  s    QVVD<M<MPS<S5T r%   )r   _type_pprintersr   floatrr   r   r   float64)r"   rH   r   s   `  r#   _type_printers_defaultz)PlainTextFormatter._type_printers_default  sB    ""'')D%ckk!TAemmr%   r   c                 >    t         j                  j                         S r   )r   _deferred_type_pprintersr   r!   s    r#   _deferred_printers_defaultz-PlainTextFormatter._deferred_printers_default  s    ..3355r%   c           
      l   | j                   st        |      S t               }t        j                  || j
                  | j                  | j                  | j                  | j                  | j                  | j                        }|j                  |       |j                          |j                         S )z0Compute the pretty representation of the object.)max_seq_lengthsingleton_pprinterstype_pprintersdeferred_pprinters)pprintrh   r   r   RepresentationPrinterverbose	max_widthnewliner   r   r   r   flushgetvalue)r"   rU   streamr   s       r#   r   zPlainTextFormatter.__call__  s     {{9ZF2264<<#22$($;$;#11#'#9#9;G NN3MMO??$$r%   N)ra   rb   rc   rn   r   rF   r   rd   r*   r   r   MAX_SEQ_LENGTHr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r|   r   rf   r%   r#   r<   r<   9  sT   0 ,'K 4jnnEn*GV22
 
cc  o.L $Z^^4^(F 5kooTo*G t,I dmt,G 4=Lrl&&d&3O+   + \ !"2 #2 _   !6 "6
 % %r%   r<   c                   0    e Zd ZdZ ed      Z ed      Zy)r=   a  An HTML formatter.

    To define the callables that compute the HTML representation of your
    objects, define a :meth:`_repr_html_` method or use the :meth:`for_type`
    or :meth:`for_type_by_name` methods to register functions that handle
    this.

    The return value of this formatter should be a valid HTML snippet that
    could be injected into an existing DOM. It should *not* include the
    ```<html>`` or ```<body>`` tags.
    z	text/html_repr_html_Nra   rb   rc   rn   r   rF   r   r   rf   r%   r#   r=   r=     s    
 +&Km,Lr%   r=   c                   0    e Zd ZdZ ed      Z ed      Zy)r>   aQ  A Markdown formatter.

    To define the callables that compute the Markdown representation of your
    objects, define a :meth:`_repr_markdown_` method or use the :meth:`for_type`
    or :meth:`for_type_by_name` methods to register functions that handle
    this.

    The return value of this formatter should be a valid Markdown.
    ztext/markdown_repr_markdown_Nr   rf   r%   r#   r>   r>     s     /*K/0Lr%   r>   c                   0    e Zd ZdZ ed      Z ed      Zy)r?   a  An SVG formatter.

    To define the callables that compute the SVG representation of your
    objects, define a :meth:`_repr_svg_` method or use the :meth:`for_type`
    or :meth:`for_type_by_name` methods to register functions that handle
    this.

    The return value of this formatter should be valid SVG enclosed in
    ```<svg>``` tags, that could be injected into an existing DOM. It should
    *not* include the ```<html>`` or ```<body>`` tags.
    zimage/svg+xml
_repr_svg_Nr   rf   r%   r#   r?   r?     s    
 /*Kl+Lr%   r?   c                   8    e Zd ZdZ ed      Z ed      Zee	fZ
y)r@   aX  A PNG formatter.

    To define the callables that compute the PNG representation of your
    objects, define a :meth:`_repr_png_` method or use the :meth:`for_type`
    or :meth:`for_type_by_name` methods to register functions that handle
    this.

    The return value of this formatter should be raw PNG data, *not*
    base64 encoded.
    z	image/png
_repr_png_Nra   rb   rc   rn   r   rF   r   r   bytesr   r   rf   r%   r#   r@   r@     s&    	 +&Kl+L3<Lr%   r@   c                   8    e Zd ZdZ ed      Z ed      Zee	fZ
y)rB   a\  A JPEG formatter.

    To define the callables that compute the JPEG representation of your
    objects, define a :meth:`_repr_jpeg_` method or use the :meth:`for_type`
    or :meth:`for_type_by_name` methods to register functions that handle
    this.

    The return value of this formatter should be raw JPEG data, *not*
    base64 encoded.
    z
image/jpeg_repr_jpeg_Nr   rf   r%   r#   rB   rB     s&    	 ,'Km,L3<Lr%   rB   c                   0    e Zd ZdZ ed      Z ed      Zy)rC   a  A LaTeX formatter.

    To define the callables that compute the LaTeX representation of your
    objects, define a :meth:`_repr_latex_` method or use the :meth:`for_type`
    or :meth:`for_type_by_name` methods to register functions that handle
    this.

    The return value of this formatter should be a valid LaTeX equation,
    enclosed in either ```$```, ```$$``` or another LaTeX equation
    environment.
    z
text/latex_repr_latex_Nr   rf   r%   r#   rC   rC     s    
 ,'Kn-Lr%   rC   c                   J     e Zd ZdZ ed      ZeefZ e	d      Z
 fdZ xZS )rD   a  A JSON string formatter.

    To define the callables that compute the JSONable representation of
    your objects, define a :meth:`_repr_json_` method or use the :meth:`for_type`
    or :meth:`for_type_by_name` methods to register functions that handle
    this.

    The return value of this formatter should be a JSONable list or dict.
    JSON scalars (None, number, string) are not allowed, only dict or list containers.
    zapplication/json_repr_json_c                     |yd}t        |t              r|\  }}t        |t              rJ d       |||f}t        t        |   ||      S )r   Nz4JSON-as-string has been deprecated since IPython < 3)rR   rS   r   superrD   rq   )r"   rz   rU   rZ   r   s       r#   rq   zJSONFormatter._check_return>  sj    
 9aEArs
 	BA	B 
 >BA]D73??r%   )ra   rb   rc   rn   r   rF   r^   dictr   r   r   rq   __classcell__r   s   @r#   rD   rD   .  s4    	 ,-K$<Lm,L@ @r%   rD   c                   0    e Zd ZdZ ed      Z ed      Zy)rE   a  A Javascript formatter.

    To define the callables that compute the Javascript representation of
    your objects, define a :meth:`_repr_javascript_` method or use the
    :meth:`for_type` or :meth:`for_type_by_name` methods to register functions
    that handle this.

    The return value of this formatter should be valid Javascript code and
    should *not* be enclosed in ```<script>``` tags.
    zapplication/javascript_repr_javascript_Nr   rf   r%   r#   rE   rE   T  s    	 23K12Lr%   rE   c                   8    e Zd ZdZ ed      Z ed      Zee	fZ
y)rA   aX  A PDF formatter.

    To define the callables that compute the PDF representation of your
    objects, define a :meth:`_repr_pdf_` method or use the :meth:`for_type`
    or :meth:`for_type_by_name` methods to register functions that handle
    this.

    The return value of this formatter should be raw PDF data, *not*
    base64 encoded.
    zapplication/pdf
_repr_pdf_Nr   rf   r%   r#   rA   rA   d  s'    	 +,Kl+L3<Lr%   rA   c                   D    e Zd ZdZ ed      Z ed      efZe	d        Z
y)r5   a  An escape-hatch Formatter for objects that know how to display themselves.
    
    To define the callables that compute the representation of your
    objects, define a :meth:`_ipython_display_` method or use the :meth:`for_type`
    or :meth:`for_type_by_name` methods to register functions that handle
    this. Unlike mime-type displays, this method should not return anything,
    instead calling any appropriate display methods itself.
    
    This display formatter has highest priority.
    If it fires, no other display formatter will be called.

    Prior to IPython 6.1, `_ipython_display_` was the only way to display custom mime-types
    without registering a new Formatter.
    
    IPython 6.1 introduces `_repr_mimebundle_` for displaying custom mime-types,
    so `_ipython_display_` should only be used for objects that require unusual
    display patterns, such as multiple display calls.
    _ipython_display_Nc                     | j                   r	 | j                  |      } ||       yyy# t        $ r Y nw xY wt        || j                        }|* |        y)r   TNr   r   s       r#   r   z IPythonDisplayFormatter.__call__  sj     <<++c*  "    %S$*;*;<F!s   * 	66)ra   rb   rc   rn   r   r   r   boolr   r|   r   rf   r%   r#   r5   r5   u  s4    $ 12LJ%L r%   r5   c                   H     e Zd ZdZ ed      ZeZ fdZe	dd       Z
 xZS )r9   a  A Formatter for arbitrary mime-types.

    Unlike other `_repr_<mimetype>_` methods,
    `_repr_mimebundle_` should return mime-bundle data,
    either the mime-keyed `data` dictionary or the tuple `(data, metadata)`.
    Any mime-type is valid.

    To define the callables that compute the mime-bundle representation of your
    objects, define a :meth:`_repr_mimebundle_` method or use the :meth:`for_type`
    or :meth:`for_type_by_name` methods to register functions that handle
    this.

    .. versionadded:: 6.1
    _repr_mimebundle_c                 d    t         t        |   ||      }|i i fS t        |t              s|i fS |S r   )r  r9   rq   rR   rS   )r"   rz   rU   r   s      r#   rq   z!MimeBundleFormatter._check_return  s=    %t:1cB9r6M!U#b5Lr%   c                     | j                   r	 | j                  |      } ||      S y# t        $ r Y nw xY wt        || j                        }|
 |||      S y)zCompute the format for an object.

        Identical to parent's method but we pass extra parameters to the method.

        Unlike other _repr_*_ `_repr_mimebundle_` should allow extra kwargs, in
        particular `include` and `exclude`.
        NrM   r   )r"   rU   rN   rO   r   rw   s         r#   r   zMimeBundleFormatter.__call__  sm     <<$++c* s|#   
 %S$*;*;<F!gw??r   r`   )ra   rb   rc   rn   r   r   r  r   rq   r|   r   r  r  s   @r#   r9   r9     s3     12LL  r%   r9   c                 d    ddl m} |j                         j                  j	                  | ||      S )a  Return a format data dict for an object.

    By default all format types will be computed.

    Parameters
    ----------
    obj : object
        The Python object whose format data will be computed.

    Returns
    -------
    format_dict : dict
        A dictionary of key/value pairs, one or each format that was
        generated for the object. The keys are the format types, which
        will usually be MIME type strings and the values and JSON'able
        data structure containing the raw data for the representation in
        that format.
    include : list or tuple, optional
        A list of format type strings (MIME types) to include in the
        format data dict. If this is set *only* the format types included
        in this list will be computed.
    exclude : list or tuple, optional
        A list of format type string (MIME types) to exclude in the format
        data dict. If this is set all format types will be computed,
        except for those included in this argument.
    r   )InteractiveShell)interactiveshellr  instancedisplay_formatterr\   )rU   rN   rO   r  s       r#   format_display_datar    s2    6 3$$&88?? r%   r`   )9rn   r   rr   ru   r   ior   r   traitlets.config.configurabler   
getipythonr   utils.sentinelr	   
utils.dir2r
   libr   	traitletsr   r   r   r   r   r   r   r   r   r   typingr   r   rk   UserWarningrm   r|   ABCMetar/   r   r   ra   r   r   r<   r=   r>   r?   r@   rB   rC   rD   rE   rA   r5   r9   registerr  rf   r%   r#   <module>r&     s    
     6 # % (    b,| b,T.1{ 1 * *$S[[ 28
 . XL XvM% M%`-M -"1 1,= ," =  $ M  $.] ."#@M #@L3- 3  =  "&m &R3- 3l   m $   ( )   m $   ' (   l #   l #   l #   m $   n %   m $   ) *   - .   ) *!r%   