/ lib / IPython / core / formatters.pyc
formatters.pyc
  1  o

  2  .��c���@sldZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
  3  mZdd	lm
Z
dd
  4  lmZddlmZddlmZmZmZmZmZmZmZmZmZmZGd
d�de	�Zdd�ZGdd�de�Z edd��Z!Gdd�dej"d�Z#dd�Z$dd�Z%e
de&d�Z'Gdd�de	�Z(Gd d!�d!e(�Z)Gd"d#�d#e(�Z*Gd$d%�d%e(�Z+Gd&d'�d'e(�Z,Gd(d)�d)e(�Z-Gd*d+�d+e(�Z.Gd,d-�d-e(�Z/Gd.d/�d/e(�Z0Gd0d1�d1e(�Z1Gd2d3�d3e(�Z2Gd4d5�d5e(�Z3Gd6d7�d7e(�Z4e#�5e(�e#�5e)�e#�5e*�e#�5e+�e#�5e,�e#�5e-�e#�5e2�e#�5e.�e#�5e/�e#�5e0�e#�5e1�e#�5e3�e#�5e4�d:d8d9�Z6dS);ziDisplay formatters.
  5  
  6  Inheritance diagram:
  7  
  8  .. inheritance-diagram:: IPython.core.formatters
  9     :parts: 3
 10  �N)�StringIO)�	decorator)�Configurable�)�get_ipython�)�Sentinel)�get_real_method)�pretty)
 11  �Bool�Dict�Integer�Unicode�CUnicode�
 12  ObjectName�List�ForwardDeclaredInstance�default�observec@s�eZdZee�dd�jdd�Zed�dd��Ze	d�dd	��Z
 13  ed
 14  �Zed�dd
��Z
ed
 15  �Zed�dd��Ze�Zed�dd��Zddd�Zedd��ZdS)�DisplayFormatterz�List of currently active mime-types to display.
 16          You can use this to set a white-list for formats to display.
 17          
 18          Most users will not need to change this value.
 19          ��helpT��config�active_typescCs|jS�N)�format_types��self�r��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\IPython\core\formatters.py�_active_types_default*sz&DisplayFormatter._active_types_defaultcCs2|j��D]\}}||dvrd|_qd|_qdS)N�newTF)�
 20  formatters�items�enabled)r�change�key�	formatterrrr �_active_types_changed.s
 21  �z&DisplayFormatter._active_types_changed�FormatterABC�ipython_display_formattercC�
 22  t|d�S�N��parent)�IPythonDisplayFormatterrrrr �_default_formatter7�
 23  z#DisplayFormatter._default_formatter�mimebundle_formattercCr,r-)�MimeBundleFormatterrrrr �_default_mime_formatter<r2z(DisplayFormatter._default_mime_formatterr#c
 24  Cs>tttttttttt	g
 25  }i}|D]}||d�}|||j
 26  <q|S)z Activate the default formatters.r.)�PlainTextFormatter�
HTMLFormatter�MarkdownFormatter�SVGFormatter�PNGFormatter�PDFFormatter�
JPEGFormatter�LatexFormatter�
JSONFormatter�JavascriptFormatter�format_type)rZformatter_classes�d�cls�frrr �_formatters_defaultCs �
 27  z$DisplayFormatter._formatters_defaultNc
 28  	sPi}i}|�|�r
iifS|j|��d�\}}|s|rK�r3�fdd�|��D�}�fdd�|��D�}�rK�fdd�|��D�}�fdd�|��D�}|j��D]S\}}||vriz|�|�Wn	tyhYqPw�rp|�vrpqP�rw|�vrwqPd}z||�}	Wn�t|	t�r�t|	�dkr�|	\}	}|	dur�|	||<|dur�|||<qP||fS)	a�Return a format data dict for an object.
 29  
 30          By default all format types will be computed.
 31  
 32          The following MIME types are usually implemented:
 33  
 34          * text/plain
 35          * text/html
 36          * text/markdown
 37          * text/latex
 38          * application/json
 39          * application/javascript
 40          * application/pdf
 41          * image/png
 42          * image/jpeg
 43          * image/svg+xml
 44  
 45          Parameters
 46          ----------
 47          obj : object
 48              The Python object whose format data will be computed.
 49          include : list, tuple or set; optional
 50              A list of format type strings (MIME types) to include in the
 51              format data dict. If this is set *only* the format types included
 52              in this list will be computed.
 53          exclude : list, tuple or set; optional
 54              A list of format type string (MIME types) to exclude in the format
 55              data dict. If this is set all format types will be computed,
 56              except for those included in this argument.
 57              Mimetypes present in exclude will take precedence over the ones in include
 58  
 59          Returns
 60          -------
 61          (format_dict, metadata_dict) : tuple of two dicts
 62              format_dict is a dictionary of key/value pairs, one of each format that was
 63              generated for the object. The keys are the format types, which
 64              will usually be MIME type strings and the values and JSON'able
 65              data structure containing the raw data for the representation in
 66              that format.
 67  
 68              metadata_dict is a dictionary of metadata about each mime-type output.
 69              Its keys will be a strict subset of the keys in format_dict.
 70  
 71          Notes
 72          -----
 73              If an object implement `_repr_mimebundle_` as well as various
 74              `_repr_*_`, the data returned by `_repr_mimebundle_` will take
 75              precedence and the corresponding `_repr_*_` for this mimetype will
 76              not be called.
 77  
 78          ��include�excludec�i|]\}}|�vr||�qSrr��.0�k�v�rFrr �
 79  <dictcomp>��z+DisplayFormatter.format.<locals>.<dictcomp>crHrrrIrMrr rN�rOc�i|]\}}|�vr||�qSrrrI�rGrr rN�rOcrPrrrIrQrr rN�rONr)	r+r3r$r#�lookup�KeyError�
 80  isinstance�tuple�len)
 81  r�objrFrG�format_dict�md_dictr@r(�md�datar)rGrFr �formatXsH4
 82  ��zDisplayFormatter.formatcCst|j���S)z>Return the format types (MIME types) of the active formatters.)�listr#�keysrrrr r�szDisplayFormatter.format_types�NN)�__name__�
 83  __module__�__qualname__rr�tagrrr!rr)rr+r1r3r5rr#rDr\�propertyrrrrr r!s,��
 84  
 85  
 86  
 87  
 88  
 89  hrc
 90  Cs8zt|�WSty}z
 91  d|WYd}~Sd}~ww)zNTry to return a repr of an object
 92  
 93      always returns a string, at least.
 94      zun-repr-able object (%r)N)�repr�	Exception)rW�errr �
 95  _safe_repr�s
 96  ��rhc@seZdZdZdS)�FormatterWarningz&Warning class for errors in formattersN)r`rarb�__doc__rrrr ri�sricOs�z
||g|�Ri|��}Wn7ty|�d|d�YStyDt��}t�}|dur5|�|�ntj|�|�d|d�YSw|�||d�S)z$show traceback on failed format callNr)	�NotImplementedError�
_check_returnrf�sys�exc_infor�
showtraceback�	traceback�print_exception)�methodr�args�kwargs�rrn�iprrr �catch_format_error�s
 97  �rwc@s&eZdZdZdZdZejdd��ZdS)r*aE Abstract base class for Formatters.
 98  
 99      A formatter is a callable class that is responsible for computing the
100      raw format data for a particular format type (MIME type). For example,
101      an HTML formatter would have a format type of `text/html` and would return
102      the HTML representation of the object when called.
103104  text/plainTcCst|�S)z�Return a JSON'able representation of the object.
105  
106          If the object cannot be formatted by this formatter,
107          warn and return None.
108          )re)rrWrrr �__call__�szFormatterABC.__call__N)	r`rarbrjr@r%�abc�abstractmethodryrrrr r*�s	r*)�	metaclasscCs t|dd�}t|dd�}||fS)zgReturn a (__module__, __name__) tuple for a type.
109  
110      Used as key in Formatter.deferred_printers.
111      raNr`)�getattr)�typ�module�namerrr �
_mod_name_keysr�cCst|dd�p	t|�S)z2Return the type of an instance (old and new-style)�	__class__N)r}�type)rWrrr �	_get_typesr��_raise_key_errorzr
112  Special value to raise a KeyError
113  
114  Raise KeyError in `BaseFormatter.pop` if passed as the default value to `pop`
115  c@s�eZdZdZed�ZeZed�j	dd�Z
116  ed�Ze
�j	dd�Ze
�j	dd�Ze
�j	dd�Zedd��Zdd	�Zd
117  d�Zdd
�Zdd�Zddd�Zddd�Zefdd�Zdd�ZdS)�
BaseFormattera�A base formatter class that is configurable.
118  
119      This formatter should usually be used as the base class of all formatters.
120      It is a traited :class:`Configurable` class and includes an extensible
121      API for users to determine how their objects are formatted. The following
122      logic is used to find a function to format an given object.
123  
124      1. The object is introspected to see if it has a method with the name
125         :attr:`print_method`. If is does, that object is passed to that method
126         for formatting.
127      2. If no print method is found, three internal dictionaries are consulted
128         to find print method: :attr:`singleton_printers`, :attr:`type_printers`
129         and :attr:`deferred_printers`.
130  
131      Users should use these dictionaries to register functions that will be
132      used to compute the format data for their objects (if those objects don't
133      have the special print methods). The easiest way of using these
134      dictionaries is through the :meth:`for_type` and :meth:`for_type_by_name`
135      methods.
136  
137      If no function/callable is found to compute the format data, ``None`` is
138      returned and this format type is not used.
139      rxTr�__repr__cCsP|jr&z
140  |�|�}W||�StyYnwt||j�}|dur$|�SdSdS)�!Compute the format for an object.N�r%rRrSr	�print_method�rrW�printerrrrrr ryHs��zBaseFormatter.__call__cCs&z|�|�WdStyYdSw)zmap in to lookup_by_typeFT)�lookup_by_typerS)rr~rrr �__contains__[s��zBaseFormatter.__contains__cCs^|dust||j�st|t�r|rt|d|j�r|St�d|jt|�|jt|�ft�dS)�vCheck that a return value is appropriate
141  
142          Return the value if so, None otherwise, warning if invalid.
143          NrzB%s formatter returned invalid type %s (expected %s) for object: %s)	rT�_return_typerU�warnings�warnr@r�rhri�rrurWrrr rlds�����zBaseFormatter._check_returncCs*t|�}||jvr|j|S|�t|��S)aALook up the formatter for a given instance.
144  
145          Parameters
146          ----------
147          obj : object instance
148  
149          Returns
150          -------
151          f : callable
152              The registered formatting callable for the type.
153  
154          Raises
155          ------
156          KeyError if the type has not been registered.
157          )�id�singleton_printersr�r�)rrW�obj_idrrr rRss
158  
159  zBaseFormatter.lookupcCs�t|t�r+t|�dd��}||jvr&|jD]}t|�|kr$|j|Sqn|j|St�|�D]}||jvs<|�	|�rC|j|Sq0t
160  d�|���)abLook up the registered formatter for a type.
161  
162          Parameters
163          ----------
164          typ : type or '__module__.__name__' string for a type
165  
166          Returns
167          -------
168          f : callable
169              The registered formatting callable for the type.
170  
171          Raises
172          ------
173          KeyError if the type has not been registered.
174          �.rzNo registered printer for {0!r})rT�strrU�rsplit�deferred_printers�
type_printersr�r
175  �_get_mro�_in_deferred_typesrSr\)rr~�typ_keyrBrrr r��s
176  
177  
178  ��
179  �zBaseFormatter.lookup_by_typeNcCsdt|t�r|�dd�\}}|�|||�Sz|�|�}Wnty&d}Ynw|dur0||j|<|S)atAdd a format function for a given type.
180  
181          Parameters
182          ----------
183          typ : type or '__module__.__name__' string for a type
184              The class of the object that will be formatted using `func`.
185  
186          func : callable
187              A callable for computing the format data.
188              `func` will be called with the object to be formatted,
189              and will return the raw data in this formatter's format.
190              Subclasses may use a different call signature for the
191              `func` argument.
192  
193              If `func` is None or not specified, there will be no change,
194              only returning the current value.
195  
196          Returns
197          -------
198          oldfunc : callable
199              The currently registered callable.
200              If you are registering a new formatter,
201              this will be the previous value (to enable restoring later).
202          r�rN)rTr�r��for_type_by_namer�rSr�)rr~�func�type_module�	type_name�oldfuncrrr �for_type�s
203  �
204  zBaseFormatter.for_typecCsH||f}z	|�d|�}Wntyd}Ynw|dur"||j|<|S)a"Add a format function for a type specified by the full dotted
205          module and name of the type, rather than the type of the object.
206  
207          Parameters
208          ----------
209          type_module : str
210              The full dotted name of the module the type is defined in, like
211              ``numpy``.
212  
213          type_name : str
214              The name of the type (the class name), like ``dtype``
215  
216          func : callable
217              A callable for computing the format data.
218              `func` will be called with the object to be formatted,
219              and will return the raw data in this formatter's format.
220              Subclasses may use a different call signature for the
221              `func` argument.
222  
223              If `func` is None or unspecified, there will be no change,
224              only returning the current value.
225  
226          Returns
227          -------
228          oldfunc : callable
229              The currently registered callable.
230              If you are registering a new formatter,
231              this will be the previous value (to enable restoring later).
232          z%s.%sN)r�rSr�)rr�r�r�r'r�rrr r��s�
233  zBaseFormatter.for_type_by_namecCs�t|t�r0t|�dd��}||jvr)|jD]}t|�|kr%|j�|�}nq|}n|j�|�}n||jvr<|j�|�}n	|j�t|�|�}|turPt	d�
234  |���|S)a�Pop a formatter for the given type.
235  
236          Parameters
237          ----------
238          typ : type or '__module__.__name__' string for a type
239          default : object
240              value to be returned if no formatter is registered for typ.
241  
242          Returns
243          -------
244          obj : object
245              The last registered object for the type.
246  
247          Raises
248          ------
249          KeyError if the type is not registered and default is not specified.
250          r�rzNo registered value for {0!r})rTr�rUr�r�r�r��popr�rSr\)rr~rr�rB�oldrrr r��s"
251  
252  
253  ��
254  zBaseFormatter.popcCsHt|dd�}t|dd�}||f}||jvr"|j�|�}||j|<dSdS)z�
255          Check if the given class is specified in the deferred type registry.
256  
257          Successful matches will be moved to the regular type registry for future use.
258          raNr`TF)r}r�r�r�)rrB�modr�r'r�rrr r�&s
259  
260  z BaseFormatter._in_deferred_typesr)r`rarbrjrr@r�r�rrcr%rr�rr�r�r�rwryr�rlrRr�r�r�r�r�r�rrrr r�s&
261  	
262  "
263  ())r�c@s�eZdZdZed�Zed�jdd�Ze	e
264  jdd�jdd�Ze
d�Zed�jdd�Zed�jdd�Ze	d	�jdd�Zed
265  �jdd�Zed�Zed�jdd�Zed
�dd��Zed�dd��Zed�dd��Zed�dd��Zedd��ZdS)r6a`The default pretty-printer.
266  
267      This uses :mod:`IPython.lib.pretty` to compute the format data of
268      the object. If the object cannot be pretty printed, :func:`repr` is used.
269      See the documentation of :mod:`IPython.lib.pretty` for details on
270      how to write pretty printers.  Here is a simple example::
271  
272          def dtype_pprinter(obj, p, cycle):
273              if cycle:
274                  return p.text('dtype(...)')
275              if hasattr(obj, 'fields'):
276                  if obj.fields is None:
277                      p.text(repr(obj))
278                  else:
279                      p.begin_group(7, 'dtype([')
280                      for i, field in enumerate(obj.descr):
281                          if i > 0:
282                              p.text(',')
283                              p.breakable()
284                          p.pretty(field)
285                      p.end_group(7, '])')
286      rxTFrzTruncate large collections (lists, dicts, tuples, sets) to this size.
287          
288          Set to 0 to disable truncation.
289          r�
_repr_pretty_�O�
290  �%r��float_precisionc
291  Cs|d}d|vr$|}z|dWnlty#}ztd|�|�d}~ww|rlzt|�}|dks1J�Wn%tyE}ztd|�|�d}~wtyW}ztd|�|�d}~wwd|}d	tjvrkddl}|j|d
292  �nd}d	tjvr}ddl}|jdd
293  �||_dS)
a�float_precision changed, set float_format accordingly.
294  
295          float_precision can be set by int or str.
296          This will set float_format, after interpreting input.
297          If numpy has been imported, numpy print precision will also be set.
298  
299          integer `n` sets format to '%.nf', otherwise, format set directly.
300  
301          An empty string returns to defaults (repr for float, 8 for numpy).
302  
303          This parameter can be set via the '%precision' magic.
304          r"�%gn���!	@z.Precision must be int or format string, not %rNrz*int precision must be non-negative, not %rz%%.%if�numpy)�	precisionr��)	rf�
305  ValueError�int�AssertionErrorrm�modulesr��set_printoptions�float_format)rr&r"�fmtrg�ir�rrr �_float_precision_changedqs<�����
306  �
307  
308  z+PlainTextFormatter._float_precision_changedr�cC�
309  tj��Sr)r
310  �_singleton_pprinters�copyrrrr �_singleton_printers_default�r2z.PlainTextFormatter._singleton_printers_defaultr�csBtj��}�fdd�|t<dtjvrddl}�fdd�||j<|S)Nc�|��j|�Sr��textr��rW�p�cyclerrr �<lambda>��z;PlainTextFormatter._type_printers_default.<locals>.<lambda>r�rcr�rr�r�rrr r��r�)r
311  �_type_pprintersr��floatrmr�r��float64)rrAr�rrr �_type_printers_default�s
312  
313  z)PlainTextFormatter._type_printers_defaultr�cCr�r)r
314  �_deferred_type_pprintersr�rrrr �_deferred_printers_default�r2z-PlainTextFormatter._deferred_printers_defaultc
315  CsV|jst|�St�}tj||j|j|j|j|j	|j
316  |jd�}|�|�|��|�
�S)z0Compute the pretty representation of the object.)�max_seq_length�singleton_pprinters�type_pprinters�deferred_pprinters)�pprintrerr
317  �RepresentationPrinter�verbose�	max_width�newliner�r�r�r��flush�getvalue)rrW�streamr�rrr ry�s
318  �
319  zPlainTextFormatter.__call__N)r`rarbrjrr@rrcr%r
r
320  �MAX_SEQ_LENGTHr�rr�r�r�r�r�r�rr�rr�rr�r�r�rwryrrrr r67s4��
321  .
322  
323  
324  
325  r6c@� eZdZdZed�Zed�ZdS)r7a�An HTML formatter.
326  
327      To define the callables that compute the HTML representation of your
328      objects, define a :meth:`_repr_html_` method or use the :meth:`for_type`
329      or :meth:`for_type_by_name` methods to register functions that handle
330      this.
331  
332      The return value of this formatter should be a valid HTML snippet that
333      could be injected into an existing DOM. It should *not* include the
334      ```<html>`` or ```<body>`` tags.
335      z	text/html�_repr_html_N�r`rarbrjrr@rr�rrrr r7��r7c@r�)r8aQA Markdown formatter.
336  
337      To define the callables that compute the Markdown representation of your
338      objects, define a :meth:`_repr_markdown_` method or use the :meth:`for_type`
339      or :meth:`for_type_by_name` methods to register functions that handle
340      this.
341  
342      The return value of this formatter should be a valid Markdown.
343      z
text/markdown�_repr_markdown_Nr�rrrr r8�s	r8c@r�)r9a�An SVG formatter.
344  
345      To define the callables that compute the SVG representation of your
346      objects, define a :meth:`_repr_svg_` method or use the :meth:`for_type`
347      or :meth:`for_type_by_name` methods to register functions that handle
348      this.
349  
350      The return value of this formatter should be valid SVG enclosed in
351      ```<svg>``` tags, that could be injected into an existing DOM. It should
352      *not* include the ```<html>`` or ```<body>`` tags.
353      z
image/svg+xml�
354  _repr_svg_Nr�rrrr r9�r�r9c@�(eZdZdZed�Zed�Zee	fZ
355  dS)r:aXA PNG formatter.
356  
357      To define the callables that compute the PNG representation of your
358      objects, define a :meth:`_repr_png_` method or use the :meth:`for_type`
359      or :meth:`for_type_by_name` methods to register functions that handle
360      this.
361  
362      The return value of this formatter should be raw PNG data, *not*
363      base64 encoded.
364      z	image/png�
365  _repr_png_N�r`rarbrjrr@rr��bytesr�r�rrrr r:��
366  
367  r:c@r�)r<a\A JPEG formatter.
368  
369      To define the callables that compute the JPEG representation of your
370      objects, define a :meth:`_repr_jpeg_` method or use the :meth:`for_type`
371      or :meth:`for_type_by_name` methods to register functions that handle
372      this.
373  
374      The return value of this formatter should be raw JPEG data, *not*
375      base64 encoded.
376      z
377  image/jpeg�_repr_jpeg_Nr�rrrr r<	r�r<c@r�)r=a�A LaTeX formatter.
378  
379      To define the callables that compute the LaTeX representation of your
380      objects, define a :meth:`_repr_latex_` method or use the :meth:`for_type`
381      or :meth:`for_type_by_name` methods to register functions that handle
382      this.
383  
384      The return value of this formatter should be a valid LaTeX equation,
385      enclosed in either ```$```, ```$$``` or another LaTeX equation
386      environment.
387      z
388  text/latex�_repr_latex_Nr�rrrr r=r�r=cs8eZdZdZed�ZeefZe	d�Z
389  �fdd�Z�ZS)r>a�A JSON string formatter.
390  
391      To define the callables that compute the JSONable representation of
392      your objects, define a :meth:`_repr_json_` method or use the :meth:`for_type`
393      or :meth:`for_type_by_name` methods to register functions that handle
394      this.
395  
396      The return value of this formatter should be a JSONable list or dict.
397      JSON scalars (None, number, string) are not allowed, only dict or list containers.
398      zapplication/json�_repr_json_csV|durdSd}t|t�r|\}}t|t�rJd��|dur"||f}tt|��||�S)r�Nz4JSON-as-string has been deprecated since IPython < 3)rTrUr��superr>rl)rrurWrZ�r�rr rl<s
399  ��zJSONFormatter._check_return)
r`rarbrjrr@r]�dictr�rr�rl�
__classcell__rrr�r r>,s
400  r>c@r�)r?a�A Javascript formatter.
401  
402      To define the callables that compute the Javascript representation of
403      your objects, define a :meth:`_repr_javascript_` method or use the
404      :meth:`for_type` or :meth:`for_type_by_name` methods to register functions
405      that handle this.
406  
407      The return value of this formatter should be valid Javascript code and
408      should *not* be enclosed in ```<script>``` tags.
409      zapplication/javascript�_repr_javascript_Nr�rrrr r?Rs
410  r?c@r�)r;aXA PDF formatter.
411  
412      To define the callables that compute the PDF representation of your
413      objects, define a :meth:`_repr_pdf_` method or use the :meth:`for_type`
414      or :meth:`for_type_by_name` methods to register functions that handle
415      this.
416  
417      The return value of this formatter should be raw PDF data, *not*
418      base64 encoded.
419      zapplication/pdfZ
420  _repr_pdf_Nr�rrrr r;br�r;c@s0eZdZdZed�Zed�efZe	dd��Z
421  dS)r0a�An escape-hatch Formatter for objects that know how to display themselves.
422      
423      To define the callables that compute the representation of your
424      objects, define a :meth:`_ipython_display_` method or use the :meth:`for_type`
425      or :meth:`for_type_by_name` methods to register functions that handle
426      this. Unlike mime-type displays, this method should not return anything,
427      instead calling any appropriate display methods itself.
428      
429      This display formatter has highest priority.
430      If it fires, no other display formatter will be called.
431  
432      Prior to IPython 6.1, `_ipython_display_` was the only way to display custom mime-types
433      without registering a new Formatter.
434      
435      IPython 6.1 introduces `_repr_mimebundle_` for displaying custom mime-types,
436      so `_ipython_display_` should only be used for objects that require unusual
437      display patterns, such as multiple display calls.
438      �_ipython_display_NcCsZ|jr)z|�|�}Wn	tyYnw||�dSt||j�}|dur+|�dSdSdS)r�TNr�r�rrr ry�s��z IPythonDisplayFormatter.__call__)r`rarbrjrr�r��boolr�rwryrrrr r0ssr0cs:eZdZdZed�ZeZ�fdd�Ze	ddd��Z
439  �ZS)	r4a
A Formatter for arbitrary mime-types.
440  
441      Unlike other `_repr_<mimetype>_` methods,
442      `_repr_mimebundle_` should return mime-bundle data,
443      either the mime-keyed `data` dictionary or the tuple `(data, metadata)`.
444      Any mime-type is valid.
445  
446      To define the callables that compute the mime-bundle representation of your
447      objects, define a :meth:`_repr_mimebundle_` method or use the :meth:`for_type`
448      or :meth:`for_type_by_name` methods to register functions that handle
449      this.
450  
451      .. versionadded:: 6.1
452      �_repr_mimebundle_cs8tt|��||�}|duriifSt|t�s|ifS|Sr)r�r4rlrTrUr�r�rr rl�s
453  z!MimeBundleFormatter._check_returnNcCsV|jr)z
454  |�|�}W||�StyYnwt||j�}|dur'|||d�SdSdS)z�Compute the format for an object.
455  
456          Identical to parent's method but we pass extra parameters to the method.
457  
458          Unlike other _repr_*_ `_repr_mimebundle_` should allow extra kwargs, in
459          particular `include` and `exclude`.
460          NrEr�)rrWrFrGr�rrrrr ry�s	��zMimeBundleFormatter.__call__r_)r`rarbrjrr�r�r�rlrwryr�rrr�r r4�s	r4cCs ddlm}|��j�|||�S)a�Return a format data dict for an object.
461  
462      By default all format types will be computed.
463  
464      Parameters
465      ----------
466      obj : object
467          The Python object whose format data will be computed.
468  
469      Returns
470      -------
471      format_dict : dict
472          A dictionary of key/value pairs, one or each format that was
473          generated for the object. The keys are the format types, which
474          will usually be MIME type strings and the values and JSON'able
475          data structure containing the raw data for the representation in
476          that format.
477      include : list or tuple, optional
478          A list of format type strings (MIME types) to include in the
479          format data dict. If this is set *only* the format types included
480          in this list will be computed.
481      exclude : list or tuple, optional
482          A list of format type string (MIME types) to exclude in the format
483          data dict. If this is set all format types will be computed,
484          except for those included in this argument.
485      r)�InteractiveShell)�interactiveshellr��instance�display_formatterr\)rWrFrGr�rrr �format_display_data�s
486  �r�r_)7rjrzrmrpr��iorr�traitlets.config.configurablerZ
487  getipythonr�utils.sentinelrZ
488  utils.dir2r	�libr
489  �	traitletsrrr
rrrrrrrrrh�UserWarningrirw�ABCMetar*r�r�r`r�r�r6r7r8r9r:r<r=r>r?r;r0r4�registerr�rrrr �<module>sn0+
490  
491  �&)
492  6
493  
494  
495  
496  
497  
498  
499  
500  
501  
502  
503  
504