Format: application/x-python-code
⬇ Download File (11.6 KB)
   1  o
   2  
   3  ��hw2�@s�dZddlmZddlZddlZddlZgd�Zdd�ZGdd�d�Ze�Z	de	fdd	�d
   4  d�Z
   5  dd
   6  �Zdddddddd�dd�Zdd�Z
   7  Gdd�de�Zddd�ZdS)zGTop-level display functions for displaying object in different formats.�)�b2a_hexN)�display�clear_output�publish_display_data�update_display�
   8  DisplayHandlecCsBt|t�r
   9  t|t�s|S|��D]\}}t|�|�|�||<q|S)zgLike update, but merges sub-dicts instead of clobbering at the top level.
  10  
  11      Updates d1 in-place
  12      )�
  13  isinstance�dict�items�_merge�get)Zd1Zd2�key�value�r�Tc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/display_functions.pyrs
  14  rc@seZdZdd�ZdS)�	_SentinelcCsdS)Nz<deprecated>r��selfrrr�__repr__&sz_Sentinel.__repr__N)�__name__�
  15  __module__�__qualname__rrrrrr%sr)�	transientcKsTddlm}|turtjdtdd�|��j}|r||d<|jd	||d�|��dS)
  16  atPublish data and metadata to all frontends.
  17  
  18      See the ``display_data`` message in the messaging documentation for
  19      more details about this message type.
  20  
  21      Keys of data and metadata can be any mime-type.
  22  
  23      Parameters
  24      ----------
  25      data : dict
  26          A dictionary having keys that are valid MIME types (like
  27          'text/plain' or 'image/svg+xml') and values that are the data for
  28          that MIME type. The data itself must be a JSON'able data
  29          structure. Minimally all data should have the 'text/plain' data,
  30          which can be displayed by all frontends. If more than the plain
  31          text is given, it is up to the frontend to decide which
  32          representation to use.
  33      metadata : dict
  34          A dictionary for metadata related to the data. This can contain
  35          arbitrary key, value pairs that frontends can use to interpret
  36          the data. mime-type keys matching those in data can be used
  37          to specify metadata about particular representations.
  38      source : str, deprecated
  39          Unused.
  40      transient : dict, keyword-only
  41          A dictionary of transient data, such as display_id.
  42      r��InteractiveShellz�The `source` parameter emit a  deprecation warning since IPython 8.0, it had no effects for a long time and will  be removed in future versions.�)�
  43  stacklevelr��data�metadataNr)	�IPython.core.interactiveshellr�	_sentinel�warnings�warn�DeprecationWarning�instance�display_pub�publish)rr�sourcer�kwargsrr&rrrr-s �
  44  �
  45  �rcCstt�d���d�S)z*Generate a new random text id with urandom��ascii)r�os�urandom�decoderrrr�_new_iddsr/F)�include�excluderr�
  46  display_id�raw�clearcOsddlm}	|	��st|�dS|duri}|duri}|r)|dur%t�}||d<|�d�r6d|vr6td��|r<||d<|sE|rEig}d}|sM|	��jj	}
  47  |rTt
  48  dd	�|D],}|retd||d
  49  �|��qV|
  50  |||d�\}}
  51  |sqqV|rxt|
  52  |�td||
  53  d
  54  �|��qV|r�t
  55  |�SdS)
  56  a*Display a Python object in all frontends.
  57  
  58      By default all representations will be computed and sent to the frontends.
  59      Frontends can decide which representation is used and how.
  60  
  61      In terminal IPython this will be similar to using :func:`print`, for use in richer
  62      frontends see Jupyter notebook examples with rich display logic.
  63  
  64      Parameters
  65      ----------
  66      *objs : object
  67          The Python objects to display.
  68      raw : bool, optional
  69          Are the objects to be displayed already mimetype-keyed dicts of raw display data,
  70          or Python objects that need to be formatted before display? [default: False]
  71      include : list, tuple or set, optional
  72          A list of format type strings (MIME types) to include in the
  73          format data dict. If this is set *only* the format types included
  74          in this list will be computed.
  75      exclude : list, tuple or set, optional
  76          A list of format type strings (MIME types) to exclude in the format
  77          data dict. If this is set all format types will be computed,
  78          except for those included in this argument.
  79      metadata : dict, optional
  80          A dictionary of metadata to associate with the output.
  81          mime-type keys in this dictionary will be associated with the individual
  82          representation formats, if they exist.
  83      transient : dict, optional
  84          A dictionary of transient data to associate with the output.
  85          Data in this dict should not be persisted to files (e.g. notebooks).
  86      display_id : str, bool optional
  87          Set an id for the display.
  88          This id can be used for updating this display area later via update_display.
  89          If given as `True`, generate a new `display_id`
  90      clear : bool, optional
  91          Should the output area be cleared before displaying anything? If True,
  92          this will wait for additional output before clearing. [default: False]
  93      **kwargs : additional keyword-args, optional
  94          Additional keyword-arguments are passed through to the display publisher.
  95  
  96      Returns
  97      -------
  98      handle: DisplayHandle
  99          Returns a handle on updatable displays for use with :func:`update_display`,
 100          if `display_id` is given. Returns :any:`None` if no `display_id` is given
 101          (default).
 102  
 103      Examples
 104      --------
 105      >>> class Json(object):
 106      ...     def __init__(self, json):
 107      ...         self.json = json
 108      ...     def _repr_pretty_(self, pp, cycle):
 109      ...         import json
 110      ...         pp.text(json.dumps(self.json, indent=2))
 111      ...     def __repr__(self):
 112      ...         return str(self.json)
 113      ...
 114  
 115      >>> d = Json({1:2, 3: {4:5}})
 116  
 117      >>> print(d)
 118      {1: 2, 3: {4: 5}}
 119  
 120      >>> display(d)
 121      {
 122        "1": 2,
 123        "3": {
 124          "4": 5
 125        }
 126      }
 127  
 128      >>> def int_formatter(integer, pp, cycle):
 129      ...     pp.text('I'*integer)
 130  
 131      >>> plain = get_ipython().display_formatter.formatters['text/plain']
 132      >>> plain.for_type(int, int_formatter)
 133      <function _repr_pprint at 0x...>
 134      >>> display(7-5)
 135      II
 136  
 137      >>> del plain.type_printers[int]
 138      >>> display(7-5)
 139      2
 140  
 141      See Also
 142      --------
 143      :func:`update_display`
 144  
 145      Notes
 146      -----
 147      In Python, objects can declare their textual representation using the
 148      `__repr__` method. IPython expands on this idea and allows objects to declare
 149      other, rich representations including:
 150  
 151        - HTML
 152        - JSON
 153        - PNG
 154        - JPEG
 155        - SVG
 156        - LaTeX
 157  
 158      A single object can declare some or all of these representations; all are
 159      handled by IPython's display system.
 160  
 161      The main idea of the first approach is that you have to implement special
 162      display methods when you define your class, one for each representation you
 163      want to use. Here is a list of the names of the special methods and the
 164      values they must return:
 165  
 166        - `_repr_html_`: return raw HTML as a string, or a tuple (see below).
 167        - `_repr_json_`: return a JSONable dict, or a tuple (see below).
 168        - `_repr_jpeg_`: return raw JPEG data, or a tuple (see below).
 169        - `_repr_png_`: return raw PNG data, or a tuple (see below).
 170        - `_repr_svg_`: return raw SVG data as a string, or a tuple (see below).
 171        - `_repr_latex_`: return LaTeX commands in a string surrounded by "$",
 172                          or a tuple (see below).
 173        - `_repr_mimebundle_`: return a full mimebundle containing the mapping
 174                               from all mimetypes to data.
 175                               Use this for any mime-type not listed above.
 176  
 177      The above functions may also return the object's metadata alonside the
 178      data.  If the metadata is available, the functions will return a tuple
 179      containing the data and metadata, in that order.  If there is no metadata
 180      available, then the functions will return the data only.
 181  
 182      When you are directly writing your own classes, you can adapt them for
 183      display in IPython by following the above approach. But in practice, you
 184      often need to work with existing classes that you can't easily modify.
 185  
 186      You can refer to the documentation on integrating with the display system in
 187      order to register custom formatters for already existing types
 188      (:ref:`integrating_rich_display`).
 189  
 190      .. versionadded:: 5.4 display available without import
 191      .. versionadded:: 6.1 display available without import
 192  
 193      Since IPython 5.4 and 6.1 :func:`display` is automatically made available to
 194      the user without import. If you are using display in a document that might
 195      be used in a pure python context or with older version of IPython, use the
 196      following import at the top of your file::
 197  
 198          from IPython.display import display
 199  
 200      rrNTr2�updatez&display_id required for update_displayr)�waitr)r0r1r)r r�initialized�printr/r�	TypeErrorr%�display_formatter�formatrrrr)r0r1rrr2r3r4Zobjsr)rr;�objZformat_dictZmd_dictrrrrisH
 201  
 202  �rcKs d|d<t|fd|i|��dS)z�Update an existing display by id
 203  
 204      Parameters
 205      ----------
 206      obj
 207          The object with which to update the display
 208      display_id : keyword-only
 209          The id of the display to update
 210  
 211      See Also
 212      --------
 213      :func:`display`
 214      Tr5r2N)r)r<r2r)rrrr7src@s2eZdZdZddd�Zdd�Zdd�Zd	d
 215  �ZdS)raA handle on an updatable display
 216  
 217      Call `.update(obj)` to display a new object.
 218  
 219      Call `.display(obj`) to add a new instance of this display,
 220      and update existing instances.
 221  
 222      See Also
 223      --------
 224  
 225          :func:`display`, :func:`update_display`
 226  
 227      NcCs|durt�}||_dS�N)r/r2)rr2rrr�__init__Xs
 228  zDisplayHandle.__init__cCsd|jj|jfS)Nz<%s display_id=%s>)�	__class__rr2rrrrr]szDisplayHandle.__repr__cK�t|fd|ji|��dS)z�Make a new display with my id, updating existing instances.
 229  
 230          Parameters
 231          ----------
 232          obj
 233              object to display
 234          **kwargs
 235              additional keyword arguments passed to display
 236          r2N)rr2�rr<r)rrrr`�
 237  zDisplayHandle.displaycKr@)z�Update existing displays with my id
 238  
 239          Parameters
 240          ----------
 241          obj
 242              object to display
 243          **kwargs
 244              additional keyword arguments passed to update_display
 245          r2N)rr2rArrrr5lrBzDisplayHandle.updater=)rrr�__doc__r>rrr5rrrrrIs
 246  rcCsXddlm}|��r|��j�|�dStddd�tj�	�tddd�tj
 247  �	�dS)z�Clear the output of the current cell receiving output.
 248  
 249      Parameters
 250      ----------
 251      wait : bool [default: false]
 252          Wait to clear the output until new output is available to replace it.rrz
 253  �)�endN)r rr7r%r&rr8�sys�stdout�flush�stderr)r6rrrrrys
 254  r)F)rC�binasciirr,rFr"�__all__rrr!rr/rr�objectrrrrrr�<module>s4��7�O0