Format: application/x-python-code
⬇ Download File (39.4 KB)
   1  o
   2  
   3  ��hT��@sddZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
   4  mZddlm
   5  Z
   6  ddlmZmZddlmZddlmZd	d
   7  lmZgd�Zgd�ZeeZdd
   8  l	mZdd�Zdd�Zd\dd�Zdd�Zdd�Zdd�Zdd�Z dd�Z!dd �Z"d!d"�Z#d#d$�Z$d%d&�Z%d'd(�Z&d)d*�Z'Gd+d,�d,e(�Z)Gd-d.�d.e)�Z*Gd/d0�d0e*�Z+Gd1d2�d2e*�Z,Gd3d4�d4e*�Z-Gd5d6�d6e*�Z.Gd7d8�d8e*�Z/Gd9d:�d:e)�Z0Gd;d<�d<e)�Z1Gd=d>�d>e)�Z2d?Z3d@Z4dAZ5GdBdC�dCe2�Z6GdDdE�dEe*�Z7dFZ8dGZ9dHZ:dIZ;dJZ<dKdL�Z=dMdN�Z>dOdP�Z?dQdR�Z@GdSdT�dTe)�ZAGdUdV�dVe)�ZBedWdX��ZCed]dZd[��ZDdS)^zGTop-level display functions for displaying object in different formats.�)�
   9  b2a_base64�hexlifyN)�deepcopy)�splitext)�Path�PurePath)�Optional)�skip_doctest�)�display_functions)�display_pretty�display_html�display_markdown�display_svg�display_png�display_jpeg�display_webp�
  10  display_latex�display_json�display_javascript�display_pdf�
  11  DisplayObject�TextDisplayObject�Pretty�HTML�Markdown�Math�Latex�SVG�ProgressBar�JSON�GeoJSON�
  12  Javascript�Image�set_matplotlib_formats�set_matplotlib_close�Video)�display�clear_outputZpublish_display_dataZupdate_displayZ
  13  DisplayHandle)�warncCsT|tvrtd|�d�tdd�tt|�S|t���vr t�|Stdt�d|����)Nz
  14  Importing z_ from IPython.core.display is deprecated since IPython 7.14, please import from IPython.display���
  15  stacklevelzmodule z has no attribute )	�_deprecated_namesr)�DeprecationWarning�getattrr�globals�keys�AttributeError�__name__)�name�r5�Jc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/display.py�__getattr__As
  16  �
  17  
  18  r7cCs$ztj�|�WStyYdSw)z*Check path, but don't let exceptions raiseF)�os�path�exists�	Exception)r9r5r5r6�_safe_existsTs
  19  �r<Fcs<|r�|i}|r�fdd�|D�}tj|||�gd��dS)a�internal implementation of all display_foo methods
  20  
  21      Parameters
  22      ----------
  23      mimetype : str
  24          The mimetype to be published (e.g. 'image/png')
  25      *objs : object
  26          The Python objects to display, or if raw=True raw text data to
  27          display.
  28      raw : bool
  29          Are the data objects raw data or Python objects that need to be
  30          formatted before display? [default: False]
  31      metadata : dict (optional)
  32          Metadata to be associated with the specific mimetype output.
  33      csg|]}�|i�qSr5r5)�.0�obj��mimetyper5r6�
  34  <listcomp>psz%_display_mimetype.<locals>.<listcomp>)�raw�metadata�includeN)rr')r@�objsrBrCr5r?r6�_display_mimetype\s
  35  rFcO�td|fi|��dS)a�Display the pretty (default) representation of an object.
  36  
  37      Parameters
  38      ----------
  39      *objs : object
  40          The Python objects to display, or if raw=True raw text data to
  41          display.
  42      raw : bool
  43          Are the data objects raw data or Python objects that need to be
  44          formatted before display? [default: False]
  45      metadata : dict (optional)
  46          Metadata to be associated with the specific mimetype output.
  47      �
  48  text/plainN�rF�rE�kwargsr5r5r6rx�rcOrG)aDisplay the HTML representation of an object.
  49  
  50      Note: If raw=False and the object does not have a HTML
  51      representation, no HTML will be shown.
  52  
  53      Parameters
  54      ----------
  55      *objs : object
  56          The Python objects to display, or if raw=True raw HTML data to
  57          display.
  58      raw : bool
  59          Are the data objects raw data or Python objects that need to be
  60          formatted before display? [default: False]
  61      metadata : dict (optional)
  62          Metadata to be associated with the specific mimetype output.
  63      �	text/htmlNrIrJr5r5r6r
  64  �sr
  65  cOrG)a�Displays the Markdown representation of an object.
  66  
  67      Parameters
  68      ----------
  69      *objs : object
  70          The Python objects to display, or if raw=True raw markdown data to
  71          display.
  72      raw : bool
  73          Are the data objects raw data or Python objects that need to be
  74          formatted before display? [default: False]
  75      metadata : dict (optional)
  76          Metadata to be associated with the specific mimetype output.
  77      z
  78  text/markdownNrIrJr5r5r6r�srcOrG)a�Display the SVG representation of an object.
  79  
  80      Parameters
  81      ----------
  82      *objs : object
  83          The Python objects to display, or if raw=True raw svg data to
  84          display.
  85      raw : bool
  86          Are the data objects raw data or Python objects that need to be
  87          formatted before display? [default: False]
  88      metadata : dict (optional)
  89          Metadata to be associated with the specific mimetype output.
  90      z
  91  image/svg+xmlNrIrJr5r5r6r�rLrcOrG)a�Display the PNG representation of an object.
  92  
  93      Parameters
  94      ----------
  95      *objs : object
  96          The Python objects to display, or if raw=True raw png data to
  97          display.
  98      raw : bool
  99          Are the data objects raw data or Python objects that need to be
 100          formatted before display? [default: False]
 101      metadata : dict (optional)
 102          Metadata to be associated with the specific mimetype output.
 103      �	image/pngNrIrJr5r5r6r�rLrcOrG)a�Display the JPEG representation of an object.
 104  
 105      Parameters
 106      ----------
 107      *objs : object
 108          The Python objects to display, or if raw=True raw JPEG data to
 109          display.
 110      raw : bool
 111          Are the data objects raw data or Python objects that need to be
 112          formatted before display? [default: False]
 113      metadata : dict (optional)
 114          Metadata to be associated with the specific mimetype output.
 115      �
 116  image/jpegNrIrJr5r5r6r�rLrcOrG)a�Display the WEBP representation of an object.
 117  
 118      Parameters
 119      ----------
 120      *objs : object
 121          The Python objects to display, or if raw=True raw JPEG data to
 122          display.
 123      raw : bool
 124          Are the data objects raw data or Python objects that need to be
 125          formatted before display? [default: False]
 126      metadata : dict (optional)
 127          Metadata to be associated with the specific mimetype output.
 128      �
 129  image/webpNrIrJr5r5r6r�rLrcOrG)a�Display the LaTeX representation of an object.
 130  
 131      Parameters
 132      ----------
 133      *objs : object
 134          The Python objects to display, or if raw=True raw latex data to
 135          display.
 136      raw : bool
 137          Are the data objects raw data or Python objects that need to be
 138          formatted before display? [default: False]
 139      metadata : dict (optional)
 140          Metadata to be associated with the specific mimetype output.
 141      z
 142  text/latexNrIrJr5r5r6r�rLrcOrG)a�Display the JSON representation of an object.
 143  
 144      Note that not many frontends support displaying JSON.
 145  
 146      Parameters
 147      ----------
 148      *objs : object
 149          The Python objects to display, or if raw=True raw json data to
 150          display.
 151      raw : bool
 152          Are the data objects raw data or Python objects that need to be
 153          formatted before display? [default: False]
 154      metadata : dict (optional)
 155          Metadata to be associated with the specific mimetype output.
 156      zapplication/jsonNrIrJr5r5r6rsrcOrG)a�Display the Javascript representation of an object.
 157  
 158      Parameters
 159      ----------
 160      *objs : object
 161          The Python objects to display, or if raw=True raw javascript data to
 162          display.
 163      raw : bool
 164          Are the data objects raw data or Python objects that need to be
 165          formatted before display? [default: False]
 166      metadata : dict (optional)
 167          Metadata to be associated with the specific mimetype output.
 168      zapplication/javascriptNrIrJr5r5r6rrLrcOrG)a�Display the PDF representation of an object.
 169  
 170      Parameters
 171      ----------
 172      *objs : object
 173          The Python objects to display, or if raw=True raw javascript data to
 174          display.
 175      raw : bool
 176          Are the data objects raw data or Python objects that need to be
 177          formatted before display? [default: False]
 178      metadata : dict (optional)
 179          Metadata to be associated with the specific mimetype output.
 180      zapplication/pdfNrIrJr5r5r6r(rLrcsNeZdZdZdZdZdZddd�Z�fdd�Zd	d
 181  �Z	dd�Z
 182  d
 183  d�Z�ZS)rz*An object that wraps data to be displayed.�rFNcCs�t|ttf�rt|�}|dur2t|t�r2|�d�r$|dur$|}d}d}nt|�r2|dur2d}|}d}||_||_||_|durC||_	n|j	durKi|_	|�
 184  �|��dS)a1Create a display object given raw data.
 185  
 186          When this object is returned by an expression or passed to the
 187          display function, it will result in the data being displayed
 188          in the frontend. The MIME type of the data should match the
 189          subclasses used, so the Png subclass should be used for 'image/png'
 190          data. If the data is a URL, the data will first be downloaded
 191          and then displayed.
 192  
 193          Parameters
 194          ----------
 195          data : unicode, str or bytes
 196              The raw data or a URL or file to load the data from
 197          url : unicode
 198              A URL to download the data from.
 199          filename : unicode
 200              Path to a local file to load the data from.
 201          metadata : dict
 202              Dict of metadata associated to be the object when displayed
 203          N�http)�
 204  isinstancerr�str�
 205  startswithr<�url�filename�datarC�reload�_check_data)�selfrXrVrWrCr5r5r6�__init__Es(
 206  zDisplayObject.__init__cs2|js|j}d|j|jf}|Stt|���}|S)Nz<%s.%s object>)�_show_mem_addr�	__class__�
 207  __module__r3�superr�__repr__)r[�clsrQ�r^r5r6ravs�zDisplayObject.__repr__cCsdS)z5Override in subclasses if there's something to check.Nr5�r[r5r5r6rZ~�zDisplayObject._check_datacCs|jr|jt|j�fS|jS)�Bshortcut for returning metadata with shape information, if defined)rCrXrrdr5r5r6�_data_and_metadata�sz DisplayObject._data_and_metadatac
 208  Csf|jdur/d|jvrdnd}t|j|j|d��}|��|_Wd�dS1s(wYdS|jdur�ddlm}||j�}|��}d}d|jvri|jd�	d�D]}|�
 209  �}|�d	�rh|�	d
 210  �d�
 211  �}nqRd|jvr�d
 212  |jdvr�ddl}ddl
 213  m}|j||�d|p�dd��}	d}|	��}Wd�n1s�wY|r�|�|d�|_dS||_dSdS)�%Reload the raw data from file or URL.N�bzutf-8)�encodingr)�urlopenzcontent-type�;�charset�=�����zcontent-encoding�gzip)�BytesIO�rt�replace)rW�_read_flags�open�readrXrV�urllib.requestrk�headers�split�striprUrp�iorq�decode)
 214  r[rj�frk�responserX�subrprq�fpr5r5r6rY�s@
 215  "�
 216  
 217  
 218  
 219  �
 220  �
 221  �
 222  
 223  �zDisplayObject.reload�NNNN)
 224  r3r_�__qualname__�__doc__rtr]rCr\rarZrgrY�
 225  __classcell__r5r5rcr6r>s
 226  1rc@seZdZdZdd�ZdS)ra�Create a text display object given raw data.
 227  
 228      Parameters
 229      ----------
 230      data : str or unicode
 231          The raw data or a URL or file to load the data from.
 232      url : unicode
 233          A URL to download the data from.
 234      filename : unicode
 235          Path to a local file to load the data from.
 236      metadata : dict
 237          Dict of metadata associated to be the object when displayed
 238      cCs4|jdurt|jt�std|jj|jf��dSdS)Nz%s expects text, not %r)rXrSrT�	TypeErrorr^r3rdr5r5r6rZ�s�zTextDisplayObject._check_dataN)r3r_r�r�rZr5r5r5r6r�s
 239  rc@�eZdZdd�ZdS)rcCs|�|j�S�N)�textrX)r[�pp�cycler5r5r6�
 240  _repr_pretty_��zPretty._repr_pretty_N)r3r_r�r�r5r5r5r6r��rcs.eZdZd�fdd�	Zdd�Zdd�Z�ZS)	rNcs8�fdd�}|�rt�d�tt|�j�|||d�dS)Ncs<�sdS�dd���}�dd���}|�d�o|�d�S)NF�
 241  i����z<iframe z	</iframe>)�lowerrU�endswith)�prefix�suffix�rXr5r6r)�s
 242  zHTML.__init__.<locals>.warnz-Consider using IPython.display.IFrame instead�rXrVrWrC)�warningsr)r`rr\)r[rXrVrWrCr)rcr�r6r\�s
 243  z
 244  HTML.__init__cC�|��Sr��rgrdr5r5r6�_repr_html_��zHTML._repr_html_cCr�)z�
 245          This method exists to inform other HTML-using modules (e.g. Markupsafe,
 246          htmltag, etc) that this object is HTML and does not need things like
 247          special characters (<>&) escaped.
 248          )r�rdr5r5r6�__html__�sz
 249  HTML.__html__r�)r3r_r�r\r�r�r�r5r5rcr6r�src@r�)rcCr�r�r�rdr5r5r6�_repr_markdown_�r�zMarkdown._repr_markdown_N)r3r_r�r�r5r5r5r6r�r�rc@r�)rcCs(d|j�d�}|jr|t|j�fS|S)Nz$\displaystyle %s$�$)rXrzrCr)r[�sr5r5r6�_repr_latex_�szMath._repr_latex_N�r3r_r�r�r5r5r5r6r�r�rc@r�)rcCr�r�r�rdr5r5r6r��r�zLatex._repr_latex_Nr�r5r5r5r6r�r�rc@sHeZdZUdZdZdZeeed<e	dd��Z
 250  e
 251  jdd��Z
 252  dd	�ZdS)
 253  rz�Embed an SVG into the display.
 254  
 255      Note if you just want to view a svg image via a URL use `:class:Image` with
 256      a url=URL keyword argument.
 257      �rbN�_datacC�|jSr��r�rdr5r5r6rX�zSVG.datacCsl|dur	d|_dSddlm}|�|�}|�d�}|r"|d��}n	t|t�r1|jdd�|_dS||_dS)Nr)�minidom�svgrs)�errors)	r�Zxml.domr��parseStringZgetElementsByTagNameZtoxmlrS�bytesr|)r[r�r��xZ	found_svgr5r5r6rXs
 258  
 259  
 260  
 261  cCr�r�r�rdr5r5r6�
 262  _repr_svg_%r�zSVG._repr_svg_)
 263  r3r_r�r�rtr�rrT�__annotations__�propertyrX�setterr�r5r5r5r6rs
 264  
 265  
 266  rc@sbeZdZdZdd�Zdd�Zdd�Zdd	�Zd
 267  d�Ze	dd
 268  ��Z
 269  e
 270  jdd
 271  ��Z
 272  dd�Zdd�Z
 273  dS)rz?Progressbar supports displaying a progressbar like element
 274      cCs2||_d|_d|_d|_tt�d���d�|_dS)z�Creates a new progressbar
 275  
 276          Parameters
 277          ----------
 278          total : int
 279              maximum size of the progressbar
 280          rZ60ex�<��asciiN)	�total�	_progress�
 281  html_width�
 282  text_widthrr8�urandomr|�_display_id)r[r�r5r5r6r\+s
 283  zProgressBar.__init__cCsD|j|j}dt||j�}d|jt|�}d�|||j|j�S)Nrn� z[{}{}] {}/{})�progressr��intr��len�format)r[�fractionZfilled�restr5r5r6ra9s�zProgressBar.__repr__cCsd�|j|j|j�S)Nz:<progress style='width:{}' max='{}' value='{}'></progress>)r�r�r�r�rdr5r5r6r�Bs�zProgressBar._repr_html_cCstj||jd�dS)N)�
 284  display_id�rr'r�rdr5r5r6r'FszProgressBar.displaycCstj||jdd�dS)NT)r��updater�rdr5r5r6r�IszProgressBar.updatecCr�r�)r�rdr5r5r6r�Lr�zProgressBar.progresscCs||_|��dSr�)r�r�)r[�valuer5r5r6r�PscCs|��d|_|S)Nro)r'r�rdr5r5r6�__iter__UszProgressBar.__iter__cCs&|jd7_|j|jkr|jSt��)z4Returns current value and increments display by one.r
 285  )r�r��
 286  StopIterationrdr5r5r6�__next__ZszProgressBar.__next__N)r3r_r�r�r\rar�r'r�r�r�r�r�r�r5r5r5r6r(s	
 287  
 288  rcsXeZdZdZdZd�fdd�	Zdd�Zed	d
 289  ��Zej	dd
 290  ��Zdd
 291  �Z
 292  dd�Z�ZS)r z�JSON expects a JSON-able dict or list
 293  
 294      not an already-serialized JSON string.
 295  
 296      Scalar types (None, number, string) are not allowed, only dict or list containers.
 297      NF�rootcsF||d�|_|r|j�|�|r|j�|�tt|�j|||d�dS)a�Create a JSON display object given raw data.
 298  
 299          Parameters
 300          ----------
 301          data : dict or list
 302              JSON data to display. Not an already-serialized JSON string.
 303              Scalar types (None, number, string) are not allowed, only dict
 304              or list containers.
 305          url : unicode
 306              A URL to download the data from.
 307          filename : unicode
 308              Path to a local file to load the data from.
 309          expanded : boolean
 310              Metadata to control whether a JSON display component is expanded.
 311          metadata : dict
 312              Specify extra metadata to attach to the json display object.
 313          root : str
 314              The name of the root element of the JSON tree
 315          )�expandedr��rXrVrWN)rCr�r`r r\)r[rXrVrWr�rCr�rKrcr5r6r\ks�z
 316  JSON.__init__cCs8|jdurt|jttf�std|jj|jf��dSdS)Nz(%s expects JSONable dict or list, not %r)rXrS�dict�listr�r^r3rdr5r5r6rZ�s�zJSON._check_datacCr�r�r�rdr5r5r6rX�r�z	JSON.datacCsRt|ttf�rt|�}t|t�r$|jdur|jdurt�d�t�	|�}||_
 317  dS)Nz4JSON expects JSONable dict or list, not JSON strings)rSrrrTrWrVr�r)�json�loadsr�)r[rXr5r5r6rX�s
 318  
 319  
 320  
 321  cCs|j|jfSr�)rXrCrdr5r5r6rg�r�zJSON._data_and_metadatacCr�r�r�rdr5r5r6�_repr_json_�r�zJSON._repr_json_)NNNFNr�)
 322  r3r_r�r�r�r\rZr�rXr�rgr�r�r5r5rcr6r bs
 323  
 324  
 325  r z�var link = document.createElement("link");
 326  	link.rel = "stylesheet";
 327  	link.type = "text/css";
 328  	link.href = "%s";
 329  	document.head.appendChild(link);
 330  z�new Promise(function(resolve, reject) {
 331  	var script = document.createElement("script");
 332  	script.onload = resolve;
 333  	script.onerror = reject;
 334  	script.src = "%s";
 335  	document.head.appendChild(script);
 336  }).then(() => {
 337  z
 338  });cs(eZdZdZ�fdd�Zdd�Z�ZS)r!z�GeoJSON expects JSON-able dict
 339  
 340      not an already-serialized JSON string.
 341  
 342      Scalar types (None, number, string) are not allowed, only dict containers.
 343      cstt|�j|i|��dS)a�Create a GeoJSON display object given raw data.
 344  
 345          Parameters
 346          ----------
 347          data : dict or list
 348              VegaLite data. Not an already-serialized JSON string.
 349              Scalar types (None, number, string) are not allowed, only dict
 350              or list containers.
 351          url_template : string
 352              Leaflet TileLayer URL template: http://leafletjs.com/reference.html#url-template
 353          layer_options : dict
 354              Leaflet TileLayer options: http://leafletjs.com/reference.html#tilelayer-options
 355          url : unicode
 356              A URL to download the data from.
 357          filename : unicode
 358              Path to a local file to load the data from.
 359          metadata : dict
 360              Specify extra metadata to attach to the json display object.
 361  
 362          Examples
 363          --------
 364          The following will display an interactive map of Mars with a point of
 365          interest on frontend that do support GeoJSON display.
 366  
 367              >>> from IPython.display import GeoJSON
 368  
 369              >>> GeoJSON(data={
 370              ...     "type": "Feature",
 371              ...     "geometry": {
 372              ...         "type": "Point",
 373              ...         "coordinates": [-81.327, 296.038]
 374              ...     }
 375              ... },
 376              ... url_template="http://s3-eu-west-1.amazonaws.com/whereonmars.cartodb.net/{basemap_id}/{z}/{x}/{y}.png",
 377              ... layer_options={
 378              ...     "basemap_id": "celestia_mars-shaded-16k_global",
 379              ...     "attribution" : "Celestia/praesepe",
 380              ...     "minZoom" : 0,
 381              ...     "maxZoom" : 18,
 382              ... })
 383              <IPython.core.display.GeoJSON object>
 384  
 385          In the terminal IPython, you will only see the text representation of
 386          the GeoJSON object.
 387  
 388          N)r`r!r\)r[�argsrKrcr5r6r\�s0zGeoJSON.__init__cCs*|jdd�}d|ji}tj||dd�dS)Nz <IPython.display.GeoJSON object>)�application/geo+jsonrHr�T)rCrB)rXrCrr')r[ZbundlerCr5r5r6�_ipython_display_�s��zGeoJSON._ipython_display_)r3r_r�r�r\r�r�r5r5rcr6r!�s3r!cs&eZdZd�fdd�	Zdd�Z�ZS)r"Ncs�t|t�r	|g}n|durg}t|t�r|g}n|durg}t|ttf�s+td|��t|ttf�s8td|��||_||_tt|�j	|||d�dS)aCreate a Javascript display object given raw data.
 389  
 390          When this object is returned by an expression or passed to the
 391          display function, it will result in the data being displayed
 392          in the frontend. If the data is a URL, the data will first be
 393          downloaded and then displayed.
 394  
 395          In the Notebook, the containing element will be available as `element`,
 396          and jQuery will be available.  Content appended to `element` will be
 397          visible in the output area.
 398  
 399          Parameters
 400          ----------
 401          data : unicode, str or bytes
 402              The Javascript source code or a URL to download it from.
 403          url : unicode
 404              A URL to download the data from.
 405          filename : unicode
 406              Path to a local file to load the data from.
 407          lib : list or str
 408              A sequence of Javascript library URLs to load asynchronously before
 409              running the source code. The full URLs of the libraries should
 410              be given. A single Javascript library URL can also be given as a
 411              string.
 412          css : list or str
 413              A sequence of css files to load before running the source code.
 414              The full URLs of the css files should be given. A single css URL
 415              can also be given as a string.
 416          Nzexpected sequence, got: %rr�)
 417  rSrTr��tupler��lib�cssr`r"r\)r[rXrVrWr�r�rcr5r6r\�s
 418  
 419  zJavascript.__init__cCsTd}|jD]}|t|7}q|jD]}|t|7}q||j7}|tt|j�7}|S)N�)r��_css_tr��_lib_t1rX�_lib_t2r�)r[rQ�c�lr5r5r6�_repr_javascript_+s
 420  
 421  
 422  zJavascript._repr_javascript_)NNNNN)r3r_r�r\r�r�r5r5rcr6r"�s.r"s�PNG
 423  
 424  s��sGIF87asGIF89asWEBPcCs&|�d�}t�d||d|d��S)z*read the (width, height) from a PNG headersIHDRz>ii��)�index�struct�unpack)rXZihdrr5r5r6�_pngxy>s
 425  r�cCsvd}	t�d|||d��d}||}|||d�dkr"|}n|d7}qt�d||d|d	��\}}||fS)
 426  z+read the (width, height) from a JPEG headerr�Tz>Hr*rs��z>HH��	�r�r�)rX�idx�
 427  block_sizeZiSOF�h�wr5r5r6�_jpegxyEs� r�cCst�d|dd��S)z*read the (width, height) from a GIF header�<HH�r�r�r�r5r5r6�_gifxyYsr�cCs�|dd�dkr t�d|dd��\}}|d@}|d@}||fS|dd�dkr\t�d	|d
 428  d��d}d
 429  |d@d>|d?B}d
 430  |d?d@d>|d?d@d>B|d?d@B}||fStd��)z+read the (width, height) from a WEBP headerr��sVP8 r���i�?sVP8Lz<I��rr
 431  �?r��r��i�r*��zNot a valid WEBP header)r�r��
 432  ValueError)rX�width�heightZ	size_infor5r5r6�_webpxy^s"�
 433  ��r�cs�eZdZdZdZdZdZdZeeeegZedededed	iZ		
 434  	
 435  	
 436  	
 437  	
 438  	
 439  	
 440  			
 441  	
 442  d�fdd
 443  �	Z
 444  dd�Z�fdd�Zdd�Z
 445  ddd�Zd dd�Zdd�Zdd�Zdd�Z�ZS)!r#r��jpeg�png�gif�webprNrOz	image/gifrPNFc
 446  s�t|ttf�rt|�}|dur|�|�}n(|dur|�|�}n|dur'td��t|t�r;|�d�s5t|�r;|�|�}nd}|dur�|durn|dksM|dkrQ|j}nY|dkrY|j	}nQ|dkra|j
 447  }nI|dkri|j}nA|��}n<t|t
 448  �r�|dd	�tkr|j}n+|dd
 449  �tkr�|j	}n|d
 450  d�tkr�|j}n|dd�tks�|dd�tkr�|j
 451  }|dur�|j	}|��dkr�|j}|��|_|dur�|n|du|_|jr�|j|jvr�td
 452  |j��|jr�|j�|j�|_||_||_||_|	|_||_tt|�j ||||
 453  d�|jdu�r|j!�di��r|
 454  d|_|jdu�r&|j!�di��r&|
 455  d|_|jdu�r9|j!�di��r9|
 456  d|_|�rB|�"�dSdS)a5Create a PNG/JPEG/GIF/WEBP image object given raw data.
 457  
 458          When this object is returned by an input cell or passed to the
 459          display function, it will result in the image being displayed
 460          in the frontend.
 461  
 462          Parameters
 463          ----------
 464          data : unicode, str or bytes
 465              The raw image data or a URL or filename to load the data from.
 466              This always results in embedded image data.
 467  
 468          url : unicode
 469              A URL to download the data from. If you specify `url=`,
 470              the image data will not be embedded unless you also specify `embed=True`.
 471  
 472          filename : unicode
 473              Path to a local file to load the data from.
 474              Images from a file are always embedded.
 475  
 476          format : unicode
 477              The format of the image data (png/jpeg/jpg/gif/webp). If a filename or URL is given
 478              for format will be inferred from the filename extension.
 479  
 480          embed : bool
 481              Should the image data be embedded using a data URI (True) or be
 482              loaded using an <img> tag. Set this to True if you want the image
 483              to be viewable later with no internet connection in the notebook.
 484  
 485              Default is `True`, unless the keyword argument `url` is set, then
 486              default value is `False`.
 487  
 488              Note that QtConsole is not able to display images if `embed` is set to `False`
 489  
 490          width : int
 491              Width in pixels to which to constrain the image in html
 492  
 493          height : int
 494              Height in pixels to which to constrain the image in html
 495  
 496          retina : bool
 497              Automatically set the width and height to half of the measured
 498              width and height.
 499              This only works for embedded images because it reads the width/height
 500              from image data.
 501              For non-embedded images, you can just set the desired display width
 502              and height directly.
 503  
 504          unconfined : bool
 505              Set unconfined=True to disable max-width confinement of the image.
 506  
 507          metadata : dict
 508              Specify extra metadata to attach to the image.
 509  
 510          alt : unicode
 511              Alternative text for the image, for use by screen readers.
 512  
 513          Examples
 514          --------
 515          embedded image data, works in qtconsole and notebook
 516          when passed positionally, the first arg can be any of raw image data,
 517          a URL, or a filename from which to load image data.
 518          The result is always embedding image data for inline images.
 519  
 520          >>> Image('https://www.google.fr/images/srpr/logo3w.png') # doctest: +SKIP
 521          <IPython.core.display.Image object>
 522  
 523          >>> Image('/path/to/image.jpg')
 524          <IPython.core.display.Image object>
 525  
 526          >>> Image(b'RAW_PNG_DATA...')
 527          <IPython.core.display.Image object>
 528  
 529          Specifying Image(url=...) does not embed the image data,
 530          it only generates ``<img>`` tag with a link to the source.
 531          This will not work in the qtconsole or offline.
 532  
 533          >>> Image(url='https://www.google.fr/images/srpr/logo3w.png')
 534          <IPython.core.display.Image object>
 535  
 536          Nz6No image data found. Expecting filename, url, or data.rRZjpgr�r�r�r�r*r�r�r�z"Cannot embed the '%s' image formatr�r�r��alt)#rSrrrT�	_find_extr�rUr<�	_FMT_JPEG�_FMT_PNG�_FMT_GIF�	_FMT_WEBPr�r��_JPEG�_PNG�_WEBP�_GIF1�_GIF2r��embed�_ACCEPTABLE_EMBEDDINGS�
 537  _MIMETYPES�get�	_mimetyper�r��retina�
 538  unconfinedr�r`r#r\rC�
 539  _retina_shape)
 540  r[rXrVrWr�r	r�r�rrrCr��extrcr5r6r\�s|_
 541  ��
 542  
 543   
 544  �
 545  
 546  
 547  �zImage.__init__cCsz|jsdS|j|jkrt|j�\}}n|j|jkr!t|j�\}}n|j|jkr/t|j�\}}ndS|d|_	|d|_
 548  dS)z3load pixel-doubled width and height from image dataNr*)r	r�rr�rXrr�rr�r�r�)r[r�r�r5r5r6r-s
 549  zImage._retina_shapecs.|jrtt|���|jr|��dSdSdS)rhN)r	r`r#rYrrrdrcr5r6rY=s�zImage.reloadcCsp|js6d}}}}|jrd|j}|jrd|j}|jr d}|jr+dt�|j�}dj|j||||d�SdS)Nr�� width="%d"� height="%d"z class="unconfined"z	 alt="%s"z-<img src="{url}"{width}{height}{klass}{alt}/>)rVr�r��klassr�)	r	r�r�rr��html�escaper�rV)r[r�r�rr�r5r5r6r�Ds$
 550  
 551  ��zImage._repr_html_cCs@|jr|j}|jdd�\}}|r||i}||i|fSd|��iS)zgReturn the image as a mimebundle
 552  
 553          Any new mimetype support should be implemented here.
 554          T)�always_bothrM)r	r
 555  rgr�)r[rD�excluder@rXrCr5r5r6�_repr_mimebundle_WszImage._repr_mimebundle_c
 556  Cs�zt|jdd��d�}Wnty }ztd|j�|�d}~wwi}|jr,|�|j�|jr4|j|d<|jr<|j|d<|j	rD|j	|d<|j
 557  rL|j
 558  |d	<|sP|rT||fS|S)
 559  rfF��newliner�zNo such file or directory: '%s'Nr�r�rr�)rrXr|r��FileNotFoundErrorrCr�r�r�rr�)r[rZb64_data�e�mdr5r5r6rges0����
 560  
 561  
 562  
 563  zImage._data_and_metadatacC�"|jr
 564  |j|jkr|��SdSdSr�)r	r�rrgrdr5r5r6�
 565  _repr_png_|��zImage._repr_png_cCrr�)r	r�rrgrdr5r5r6�_repr_jpeg_�r!zImage._repr_jpeg_cCs$t|�\}}|s
 566  |S|dd���S)Nr
 567  )rr�)r[r��baserr5r5r6r��szImage._find_ext)NNNNNNNFFNN)NN)F)r3r_r�rtrrrrr
 568  rr\rrYr�rrgr r"r�r�r5r5rcr6r#rsB�	�-
 569  
 570  r#cs2eZdZ		d
 571  �fdd�	Zdd�Zdd	�Z�ZS)r&NF�controlsc	
 572  s�t|ttf�rt|�}|durt|t�r|�d�r|}d}n|dur,tj�|�r,|}d}|r;|s;d�gd��}	t	|	��||_
 573  ||_||_||_
 574  ||_tt|�j|||d�dS)a�Create a video object given raw data or an URL.
 575  
 576          When this object is returned by an input cell or passed to the
 577          display function, it will result in the video being displayed
 578          in the frontend.
 579  
 580          Parameters
 581          ----------
 582          data : unicode, str or bytes
 583              The raw video data or a URL or filename to load the data from.
 584              Raw data will require passing ``embed=True``.
 585  
 586          url : unicode
 587              A URL for the video. If you specify ``url=``,
 588              the image data will not be embedded.
 589  
 590          filename : unicode
 591              Path to a local file containing the video.
 592              Will be interpreted as a local URL unless ``embed=True``.
 593  
 594          embed : bool
 595              Should the video be embedded using a data URI (True) or be
 596              loaded using a <video> tag (False).
 597  
 598              Since videos are large, embedding them should be avoided, if possible.
 599              You must confirm embedding as your intention by passing ``embed=True``.
 600  
 601              Local files can be displayed with URLs without embedding the content, via::
 602  
 603                  Video('./video.mp4')
 604  
 605          mimetype : unicode
 606              Specify the mimetype for embedded videos.
 607              Default will be guessed from file extension, if available.
 608  
 609          width : int
 610              Width in pixels to which to constrain the video in HTML.
 611              If not supplied, defaults to the width of the video.
 612  
 613          height : int
 614              Height in pixels to which to constrain the video in html.
 615              If not supplied, defaults to the height of the video.
 616  
 617          html_attributes : str
 618              Attributes for the HTML ``<video>`` block.
 619              Default: ``"controls"`` to get video controls.
 620              Other examples: ``"controls muted"`` for muted video with controls,
 621              ``"loop autoplay"`` for looping autoplaying video without controls.
 622  
 623          Examples
 624          --------
 625          ::
 626  
 627              Video('https://archive.org/download/Sita_Sings_the_Blues/Sita_Sings_the_Blues_small.mp4')
 628              Video('path/to/video.mp4')
 629              Video('path/to/video.mp4', embed=True)
 630              Video('path/to/video.mp4', embed=True, html_attributes="controls muted autoplay")
 631              Video(b'raw-videodata', embed=True)
 632          N)zhttp:zhttps:r�)z*To embed videos, you must pass embed=True z)(this may make your notebook files huge)
 633  z!Consider passing Video(url='...')r�)rSrrrTrUr8r9r:�joinr�r@r	r�r��html_attributesr`r&r\)
 634  r[rXrVrWr	r@r�r�r&�msgrcr5r6r\�s"=zVideo.__init__c
 635  Cs�d}}|jrd|j}|jrd|j}|js-|jdur|jn|j}d�||j||�}|S|j}|jdurZ|s?t�	|j�\}}t
 636  |jd��}|��}Wd�n1sTwYn|j}t
 637  |t�re|}	nt|dd��d���}	d	�|j||||	�}|S)
 638  Nr�rrzn<video src="{0}" {1} {2} {3}>
 639        Your browser does not support the <code>video</code> element.
 640      </video>r�Frr�zz<video {0} {1} {2}>
 641   <source src="data:{3};base64,{4}" type="{3}">
 642   Your browser does not support the video tag.
 643   </video>)r�r�r	rVrWr�r&r@�	mimetypes�
 644  guess_typerurvrXrSrTrr|�rstrip)
 645  r[r�r�rV�outputr@�_r}ZvideoZ	b64_videor5r5r6r��s6
 646  
 647  �
 648  
 649  ��
 650  �zVideo._repr_html_cCsdSr�r5rdr5r5r6rYrezVideo.reload)NNNFNNNr$)r3r_r�r\r�rYr�r5r5rcr6r&�s�V&r&cOs.tjdtdd�ddlm}||i|��dS)a�
 651      .. deprecated:: 7.23
 652  
 653         use `matplotlib_inline.backend_inline.set_matplotlib_formats()`
 654  
 655      Select figure formats for the inline backend. Optionally pass quality for JPEG.
 656  
 657      For example, this enables PNG and JPEG output with a JPEG quality of 90%::
 658  
 659          In [1]: set_matplotlib_formats('png', 'jpeg', quality=90)
 660  
 661      To set this in your config files use the following::
 662  
 663          c.InlineBackend.figure_formats = {'png', 'jpeg'}
 664          c.InlineBackend.print_figure_kwargs.update({'quality' : 90})
 665  
 666      Parameters
 667      ----------
 668      *formats : strs
 669          One or more figure formats to enable: 'png', 'retina', 'jpeg', 'svg', 'pdf'.
 670      **kwargs
 671          Keyword args will be relayed to ``figure.canvas.print_figure``.
 672      z�`set_matplotlib_formats` is deprecated since IPython 7.23, directly use `matplotlib_inline.backend_inline.set_matplotlib_formats()`r*r+r)r$N)r�r)r.� matplotlib_inline.backend_inliner$)�formatsrKZset_matplotlib_formats_origr5r5r6r$s�r$TcCs(tjdtdd�ddlm}||�dS)a
 673      .. deprecated:: 7.23
 674  
 675          use `matplotlib_inline.backend_inline.set_matplotlib_close()`
 676  
 677      Set whether the inline backend closes all figures automatically or not.
 678  
 679      By default, the inline backend used in the IPython Notebook will close all
 680      matplotlib figures automatically after each cell is run. This means that
 681      plots in different cells won't interfere. Sometimes, you may want to make
 682      a plot in one cell and then refine it in later cells. This can be accomplished
 683      by::
 684  
 685          In [1]: set_matplotlib_close(False)
 686  
 687      To set this in your config files use the following::
 688  
 689          c.InlineBackend.close_figures = False
 690  
 691      Parameters
 692      ----------
 693      close : bool
 694          Should all matplotlib figures be automatically closed after each cell is
 695          run?
 696      z`set_matplotlib_close` is deprecated since IPython 7.23, directly use `matplotlib_inline.backend_inline.set_matplotlib_close()`r*r+r)r%N)r�r)r.r-r%)�closeZset_matplotlib_close_origr5r5r6r%7s�r%)FN)T)Er��binasciirrrr�r(r8r�r��copyrZos.pathr�pathlibrr�typingrZIPython.testing.skipdoctestr	r�r�__all__r-r)r7r<rFrr
 697  rrrrrrrrr�objectrrrrrrrrrr r�r�r�r!r"rrrrrr�r�r�r�r#r&r$r%r5r5r5r6�<module>s�
 698  u
 699  (:A	E<
 700  %