Format: application/x-python-code
⬇ Download File (5.1 KB)
   1  o
   2  
   3  ��h��@s\dZddlZddlmZddlmZddlmZddlZ	Gdd�de�Z
   4  Gd	d
   5  �d
   6  e
   7  �ZdS)a�An interface for publishing rich data to frontends.
   8  
   9  There are two components of the display system:
  10  
  11  * Display formatters, which take a Python object and compute the
  12    representation of the object in various formats (text, HTML, SVG, etc.).
  13  * The display publisher that is used to send the representation data to the
  14    various frontends.
  15  
  16  This module defines the logic display publishing. The display publisher uses
  17  the ``display_data`` message type that is defined in the IPython messaging
  18  spec.
  19  �N)�Configurable)�List�)�publish_display_datacsJeZdZdZd�fdd�	Zddd�Zdddd�dd
  20  d�Zddd
  21  �Z�ZS)�DisplayPublisherz�A traited class that publishes display data to frontends.
  22  
  23      Instances of this class are created by the main IPython object and should
  24      be accessed there.
  25      Ncs||_t�j|i|��dS�N)�shell�super�__init__)�selfr�args�kwargs��	__class__��Mc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/displaypub.pyr
  26  )szDisplayPublisher.__init__cCs<t|t�std|��|durt|t�std|��dSdS)z�Validate the display data.
  27  
  28          Parameters
  29          ----------
  30          data : dict
  31              The formata data dictionary.
  32          metadata : dict
  33              Any metadata for the data.
  34          zdata must be a dict, got: %rNz metadata must be a dict, got: %r)�
  35  isinstance�dict�	TypeError)r�data�metadatarrr�_validate_data-s
  36  
  37  �zDisplayPublisher._validate_dataF��	transient�update�returnc
  38  Ksni}|jdurt|jdi�}|��D]\}}	||vr(|	|||�|d��dSqd|vr5t|d�dSdS)a�Publish data and metadata to all frontends.
  39  
  40          See the ``display_data`` message in the messaging documentation for
  41          more details about this message type.
  42  
  43          The following MIME types are currently implemented:
  44  
  45          * text/plain
  46          * text/html
  47          * text/markdown
  48          * text/latex
  49          * application/json
  50          * application/javascript
  51          * image/png
  52          * image/jpeg
  53          * image/svg+xml
  54  
  55          Parameters
  56          ----------
  57          data : dict
  58              A dictionary having keys that are valid MIME types (like
  59              'text/plain' or 'image/svg+xml') and values that are the data for
  60              that MIME type. The data itself must be a JSON'able data
  61              structure. Minimally all data should have the 'text/plain' data,
  62              which can be displayed by all frontends. If more than the plain
  63              text is given, it is up to the frontend to decide which
  64              representation to use.
  65          metadata : dict
  66              A dictionary for metadata related to the data. This can contain
  67              arbitrary key, value pairs that frontends can use to interpret
  68              the data.  Metadata specific to each mime-type can be specified
  69              in the metadata dict with the same mime-type keys as
  70              the data itself.
  71          source : str, deprecated
  72              Unused.
  73          transient : dict, keyword-only
  74              A dictionary for transient data.
  75              Data in this dictionary should not be persisted as part of saving this output.
  76              Examples include 'display_id'.
  77          update : bool, keyword-only, default: False
  78              If True, only update existing outputs with the same display_id,
  79              rather than creating a new output.
  80          NZmime_renderersz
  81  text/plain)r�getattr�items�get�print)
  82  rrr�sourcerrr
  83  �handlers�mime�handlerrrr�publish?s-
  84  ��zDisplayPublisher.publishcCs0tddd�tj��tddd�tj��dS)z.Clear the output of the cell receiving output.z
  85  �)�endN)r�sys�stdout�flush�stderr�r�waitrrr�clear_outputxs
  86  zDisplayPublisher.clear_outputr�NN)rN�F)	�__name__�
  87  __module__�__qualname__�__doc__r
  88  rr$r-�
  89  __classcell__rrrrr"s
  90  9rcsFeZdZUdZe�Zeed<	d
  91  ddd�dd�Zd�fdd	�	Z�Z	S)�CapturingDisplayPublisherzA DisplayPublisher that stores�outputsNFrcCs|j�||||d��dS)N)rrrr)r6�append)rrrr rrrrrr$�s��z!CapturingDisplayPublisher.publishcstt|��|�|j��dSr)r	r5r-r6�clearr+rrrr-�sz&CapturingDisplayPublisher.clear_outputr.r/)
  92  r0r1r2r3rr6�__annotations__r$r-r4rrrrr5�s
  93  ��r5)r3r'Ztraitlets.config.configurablerZ	traitletsrZdisplay_functionsr�typing�trr5rrrr�<module>s^