
    Mh                        d Z ddlmZmZ ddlZddl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mZ ddlmZ ddlmZ d	d
lmZ g dZd ZdBdZd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$ G d 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%          Z, G d* d+e%          Z- G d, d-e%          Z.d.Z/d/Z0d0Z1 G d1 d2e.          Z2 G d3 d4e&          Z3d5Z4d6Z5d7Z6d8Z7d9Z8d: Z9d; Z:d< Z;d= Z< G d> d?e%          Z= G d@ dAe%          Z>dS )CzGTop-level display functions for displaying object in different formats.    )
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display_latexdisplay_jsondisplay_javascriptdisplay_pdfDisplayObjectTextDisplayObjectPrettyHTMLMarkdownMathLatexSVGProgressBarJSONGeoJSON
JavascriptImageVideoc                 d    	 t           j                            |           S # t          $ r Y dS w xY w)z*Check path, but don't let exceptions raiseF)ospathexists	Exception)r(   s    T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/core/display.py_safe_existsr,   8   s=    w~~d###   uus   ! 
//Fc                 \     |r |i}|r fd|D             }t          j        ||| gd dS )a  internal implementation of all display_foo methods

    Parameters
    ----------
    mimetype : str
        The mimetype to be published (e.g. 'image/png')
    *objs : object
        The Python objects to display, or if raw=True raw text data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    c                     g | ]}|iS  r/   ).0objmimetypes     r+   
<listcomp>z%_display_mimetype.<locals>.<listcomp>T   s    222S(C222    )rawmetadataincludeN)r   display)r2   objsr5   r6   s   `   r+   _display_mimetyper:   @   sZ       (h'
 32222D222tx(TTTTTTr4   c                  "    t          d| fi | dS )a  Display the pretty (default) representation of an object.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw text data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    
text/plainNr:   r9   kwargss     r+   r   r   \   "     lD33F33333r4   c                  "    t          d| fi | dS )a  Display the HTML representation of an object.

    Note: If raw=False and the object does not have a HTML
    representation, no HTML will be shown.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw HTML data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    	text/htmlNr=   r>   s     r+   r   r   m   s"    " k422622222r4   c                  "    t          d| fi | dS )a  Displays the Markdown representation of an object.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw markdown data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    ztext/markdownNr=   r>   s     r+   r   r      s"     ot66v66666r4   c                  "    t          d| fi | dS )a  Display the SVG representation of an object.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw svg data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    zimage/svg+xmlNr=   r>   s     r+   r   r      s"     ot66v66666r4   c                  "    t          d| fi | dS )a  Display the PNG representation of an object.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw png data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    	image/pngNr=   r>   s     r+   r   r      s"     k422622222r4   c                  "    t          d| fi | dS )a  Display the JPEG representation of an object.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw JPEG data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    
image/jpegNr=   r>   s     r+   r   r      r@   r4   c                  "    t          d| fi | dS )a  Display the WEBP representation of an object.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw JPEG data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    
image/webpNr=   r>   s     r+   r   r      r@   r4   c                  "    t          d| fi | dS )a  Display the LaTeX representation of an object.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw latex data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    z
text/latexNr=   r>   s     r+   r   r      r@   r4   c                  "    t          d| fi | dS )a  Display the JSON representation of an object.

    Note that not many frontends support displaying JSON.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw json data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    zapplication/jsonNr=   r>   s     r+   r   r      s#      ($99&99999r4   c                  "    t          d| fi | dS )a  Display the Javascript representation of an object.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw javascript data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    zapplication/javascriptNr=   r>   s     r+   r   r      s#     .???????r4   c                  "    t          d| fi | dS )a  Display the PDF representation of an object.

    Parameters
    ----------
    *objs : object
        The Python objects to display, or if raw=True raw javascript data to
        display.
    raw : bool
        Are the data objects raw data or Python objects that need to be
        formatted before display? [default: False]
    metadata : dict (optional)
        Metadata to be associated with the specific mimetype output.
    zapplication/pdfNr=   r>   s     r+   r   r     s#     '8888888r4   c                   H     e Zd ZdZdZdZdZd
dZ fdZd Z	d Z
d	 Z xZS )r   z*An object that wraps data to be displayed.rFNc                    t          |t          t          f          rt          |          }|Jt          |t                    r5|                    d          r	||}d}d}nt          |          r|d}|}d}|| _        || _        || _        ||| _	        n| j	        i | _	        | 
                                 |                                  dS )a1  Create a display object given raw data.

        When this object is returned by an expression or passed to the
        display function, it will result in the data being displayed
        in the frontend. The MIME type of the data should match the
        subclasses used, so the Png subclass should be used for 'image/png'
        data. If the data is a URL, the data will first be downloaded
        and then displayed.

        Parameters
        ----------
        data : unicode, str or bytes
            The raw data or a URL or file to load the data from
        url : unicode
            A URL to download the data from.
        filename : unicode
            Path to a local file to load the data from.
        metadata : dict
            Dict of metadata associated to be the object when displayed
        Nhttp)
isinstancer   r   str
startswithr,   urlfilenamedatar6   reload_check_data)selfrX   rV   rW   r6   s        r+   __init__zDisplayObject.__init__)  s    * dT8,-- 	t99D
4 5 5v&& 3;d## (8  	$DMM]"DMr4   c                     | j         s| j        }d|j        d|j        d}n't	          t
          |                                           }|S )N<.z object>)_show_mem_addr	__class__
__module____name__superr   __repr__)r[   clsrP   ra   s      r+   re   zDisplayObject.__repr__Z  sO    " 	6.CC$'NNNCLLLAAAmT**3355Ar4   c                     dS )z5Override in subclasses if there's something to check.Nr/   r[   s    r+   rZ   zDisplayObject._check_datab      r4   c                 T    | j         r| j        t          | j                   fS | j        S )Bshortcut for returning metadata with shape information, if defined)r6   rX   r   rh   s    r+   _data_and_metadataz DisplayObject._data_and_metadataf  s+    = 	9ht}55559r4   c                 t   | j         ]d| j        v rdnd}t          | j         | j        |          5 }|                                | _        ddd           dS # 1 swxY w Y   dS | j        Kddlm}  || j                  }|                                }d}d|j        v r{|j        d         	                    d          D ]Z}|
                                }|                    d	          r/|	                    d
          d         
                                } n[d|j        v rjd|j        d         v r[ddl}ddlm} |                     ||          d|pd          5 }	d}|	                                }ddd           n# 1 swxY w Y   |r|                    |d          | _        dS || _        dS dS )%Reload the raw data from file or URL.Nbzutf-8)encodingr   )urlopenzcontent-type;charset=zcontent-encodinggzip)BytesIOrtreplace)rW   _read_flagsopenreadrX   rV   urllib.requestrq   headerssplitstriprU   rv   iorw   decode)
r[   rp   frq   responserX   subrv   rw   fps
             r+   rY   zDisplayObject.reloadm  so   =$"d&666ttGHdmT%5III %QFFHH	% % % % % % % % % % % % % % % % % %X!......wtx((H==??DH!111#+N;AA#FF  C))++C~~i00 #&99S>>"#5#;#;#=#= "X%555X-.@AAAKKK****** th6I' #   )#'!wwyy	) ) ) ) ) ) ) ) ) ) ) ) ) ) )  ! KK)<<			 			C "!s#   AAA"FF	F	NNNN)rc   rb   __qualname____doc__rz   r`   r6   r\   re   rZ   rl   rY   __classcell__ra   s   @r+   r   r   "  s        44KNH/ / / /b        '! '! '! '! '! '! '!r4   r   c                       e Zd ZdZd ZdS )r   a  Create a text display object given raw data.

    Parameters
    ----------
    data : str or unicode
        The raw data or a URL or file to load the data from.
    url : unicode
        A URL to download the data from.
    filename : unicode
        Path to a local file to load the data from.
    metadata : dict
        Dict of metadata associated to be the object when displayed
    c                     | j         =t          | j         t                    s%t          | j        j        d| j                   d S d S )Nz expects text, not )rX   rS   rT   	TypeErrorra   rc   rh   s    r+   rZ   zTextDisplayObject._check_data  sN    9 DIs)C)C 9P9P9PRVR[R[\]]] !   r4   N)rc   rb   r   r   rZ   r/   r4   r+   r   r     s2         ^ ^ ^ ^ ^r4   r   c                       e Zd Zd ZdS )r   c                 6    |                     | j                  S N)textrX   )r[   ppcycles      r+   _repr_pretty_zPretty._repr_pretty_  s    wwty!!!r4   N)rc   rb   r   r   r/   r4   r+   r   r     s#        " " " " "r4   r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )r   Nc                     fd} |            rt          j        d           t          t          |                               |||           d S )Nc                      sdS d d                                          } dd                                           }|                     d          o|                    d          S )NF
   iz<iframe z	</iframe>)lowerrU   endswith)prefixsuffixrX   s     r+   warnzHTML.__init__.<locals>.warn  sg     u #2#Y__&&F#$$Z%%''F$$Z00QV__[5Q5QQr4   z-Consider using IPython.display.IFrame insteadrX   rV   rW   r6   )warningsr   rd   r   r\   )r[   rX   rV   rW   r6   r   ra   s    `    r+   r\   zHTML.__init__  sr    
	R 
	R 
	R 
	R 
	R 466 	KMIJJJdD""#S["\\\\\r4   c                 *    |                                  S r   rl   rh   s    r+   _repr_html_zHTML._repr_html_      &&(((r4   c                 *    |                                  S )z
        This method exists to inform other HTML-using modules (e.g. Markupsafe,
        htmltag, etc) that this object is HTML and does not need things like
        special characters (<>&) escaped.
        )r   rh   s    r+   __html__zHTML.__html__  s     !!!r4   r   )rc   rb   r   r\   r   r   r   r   s   @r+   r   r     sa        ] ] ] ] ] ]") ) )" " " " " " "r4   r   c                       e Zd Zd ZdS )r   c                 *    |                                  S r   r   rh   s    r+   _repr_markdown_zMarkdown._repr_markdown_  r   r4   N)rc   rb   r   r   r/   r4   r+   r   r     #        ) ) ) ) )r4   r   c                       e Zd Zd ZdS )r   c                 z    d| j                             d          z  }| j        r|t          | j                  fS |S )Nz$\displaystyle %s$$)rX   r   r6   r   )r[   ss     r+   _repr_latex_zMath._repr_latex_  s>    !DIOOC$8$88= 	ht}----Hr4   Nrc   rb   r   r   r/   r4   r+   r   r     s#            r4   r   c                       e Zd Zd ZdS )r   c                 *    |                                  S r   r   rh   s    r+   r   zLatex._repr_latex_  r   r4   Nr   r/   r4   r+   r   r     r   r4   r   c                   n    e Zd ZU dZdZdZee         ed<   e	d             Z
e
j        d             Z
d ZdS )r   zEmbed an SVG into the display.

    Note if you just want to view a svg image via a URL use `:class:Image` with
    a url=URL keyword argument.
    rbN_datac                     | j         S r   r   rh   s    r+   rX   zSVG.data  
    zr4   c                 *   |	d | _         d S ddlm} |                    |          }|                    d          }|r|d                                         }n	 t          |t                    r|                    d          | _         d S || _         d S )Nr   )minidomsvgry   )errors)	r   xml.domr   parseStringgetElementsByTagNametoxmlrS   bytesr   )r[   r   r   x	found_svgs        r+   rX   zSVG.data  s    ;DJF######$$**511	 	A,$$&&CC c5!! 	955DJJJDJJJr4   c                 *    |                                  S r   r   rh   s    r+   
_repr_svg_zSVG._repr_svg_	  r   r4   )rc   rb   r   r   rz   r   r	   rT   __annotations__propertyrX   setterr   r/   r4   r+   r   r     s           K  E8C=  X 
[  [() ) ) ) )r4   r   c                   r    e Zd ZdZd Zd Zd Zd Zd Ze	d             Z
e
j        d             Z
d	 Zd
 ZdS )r    z?Progressbar supports displaying a progressbar like element
    c                     || _         d| _        d| _        d| _        t	          t          j        d                                        d          | _        dS )zCreates a new progressbar

        Parameters
        ----------
        total : int
            maximum size of the progressbar
        r   60ex<      asciiN)	total	_progress
html_width
text_widthr   r'   urandomr   _display_id)r[   r   s     r+   r\   zProgressBar.__init__  sL     
 "2:a==1188AAr4   c                     | j         | j        z  }dt          || j        z            z  }d| j        t	          |          z
  z  }d                    ||| j         | j                  S )Nrt    z[{}{}] {}/{})progressr   intr   lenformat)r[   fractionfilledrests       r+   re   zProgressBar.__repr__  sf    =4:-s8do5666doF34$$DM4:
 
 	
r4   c                 N    d                     | j        | j        | j                  S )Nz:<progress style='width:{}' max='{}' value='{}'></progress>)r   r   r   r   rh   s    r+   r   zProgressBar._repr_html_&  s'    KRROTZ8 8 	8r4   c                 <    t          j        | | j                   d S )N)
display_idr   r8   r   rh   s    r+   r8   zProgressBar.display*  s!    !$43CDDDDDDr4   c                 >    t          j        | | j        d           d S )NT)r   updater   rh   s    r+   r   zProgressBar.update-  s#    !$43CDQQQQQQr4   c                     | j         S r   )r   rh   s    r+   r   zProgressBar.progress0  s
    ~r4   c                 <    || _         |                                  d S r   )r   r   )r[   values     r+   r   zProgressBar.progress4  s    r4   c                 <    |                                   d| _        | S )Nru   )r8   r   rh   s    r+   __iter__zProgressBar.__iter__9  s    r4   c                 l    | xj         dz  c_         | j         | j        k     r| j         S t                      )z4Returns current value and increments display by one.r   )r   r   StopIterationrh   s    r+   __next__zProgressBar.__next__>  s3    =4:%%= //!r4   N)rc   rb   r   r   r\   re   r   r8   r   r   r   r   r   r   r/   r4   r+   r    r      s         B B B
 
 
8 8 8E E ER R R   X _  _  
" " " " "r4   r    c                   p     e Zd ZdZdZd fd	Zd Zed             Zej	        d             Zd	 Z
d
 Z xZS )r!   zJSON expects a JSON-able dict or list

    not an already-serialized JSON string.

    Scalar types (None, number, string) are not allowed, only dict or list containers.
    NFrootc                     ||d| _         |r| j                             |           |r| j                             |           t          t          |                               |||           dS )a  Create a JSON display object given raw data.

        Parameters
        ----------
        data : dict or list
            JSON data to display. Not an already-serialized JSON string.
            Scalar types (None, number, string) are not allowed, only dict
            or list containers.
        url : unicode
            A URL to download the data from.
        filename : unicode
            Path to a local file to load the data from.
        expanded : boolean
            Metadata to control whether a JSON display component is expanded.
        metadata : dict
            Specify extra metadata to attach to the json display object.
        root : str
            The name of the root element of the JSON tree
        )expandedr   rX   rV   rW   N)r6   r   rd   r!   r\   )	r[   rX   rV   rW   r   r6   r   r?   ra   s	           r+   r\   zJSON.__init__O  s    * !
 
  	+M  *** 	)M  (((dD""#"IIIIIr4   c                     | j         Dt          | j         t          t          f          s%t	          | j        j        d| j                   d S d S )Nz$ expects JSONable dict or list, not )rX   rS   dictlistr   ra   rc   rh   s    r+   rZ   zJSON._check_datam  sR    9 DId|)L)L $.JaJaJacgclclmnnn !   r4   c                     | j         S r   r   rh   s    r+   rX   z	JSON.dataq  r   r4   c                     t          |t          t          f          rt          |          }t          |t                    r6| j        | j        t          j        d           t          j	        |          }|| _
        d S )Nz4JSON expects JSONable dict or list, not JSON strings)rS   r   r   rT   rW   rV   r   r   jsonloadsr   )r[   rX   s     r+   rX   z	JSON.datau  sp    dT8,-- 	t99DdC   	$}$)9TUUU:d##D


r4   c                     | j         | j        fS r   )rX   r6   rh   s    r+   rl   zJSON._data_and_metadata  s    y$-''r4   c                 *    |                                  S r   r   rh   s    r+   _repr_json_zJSON._repr_json_  r   r4   )NNNFNr   )rc   rb   r   r   r   r\   rZ   r   rX   r   rl   r   r   r   s   @r+   r!   r!   F  s          EJ J J J J J<o o o   X 
[  [( ( () ) ) ) ) ) )r4   r!   zvar link = document.createElement("link");
	link.rel = "stylesheet";
	link.type = "text/css";
	link.href = "%s";
	document.head.appendChild(link);
znew Promise(function(resolve, reject) {
	var script = document.createElement("script");
	script.onload = resolve;
	script.onerror = reject;
	script.src = "%s";
	document.head.appendChild(script);
}).then(() => {
z
});c                   (     e Zd ZdZ fdZd Z xZS )r"   zGeoJSON expects JSON-able dict

    not an already-serialized JSON string.

    Scalar types (None, number, string) are not allowed, only dict containers.
    c                 H     t          t          |           j        |i | dS )a  Create a GeoJSON display object given raw data.

        Parameters
        ----------
        data : dict or list
            VegaLite data. Not an already-serialized JSON string.
            Scalar types (None, number, string) are not allowed, only dict
            or list containers.
        url_template : string
            Leaflet TileLayer URL template: http://leafletjs.com/reference.html#url-template
        layer_options : dict
            Leaflet TileLayer options: http://leafletjs.com/reference.html#tilelayer-options
        url : unicode
            A URL to download the data from.
        filename : unicode
            Path to a local file to load the data from.
        metadata : dict
            Specify extra metadata to attach to the json display object.

        Examples
        --------
        The following will display an interactive map of Mars with a point of
        interest on frontend that do support GeoJSON display.

            >>> from IPython.display import GeoJSON

            >>> GeoJSON(data={
            ...     "type": "Feature",
            ...     "geometry": {
            ...         "type": "Point",
            ...         "coordinates": [-81.327, 296.038]
            ...     }
            ... },
            ... url_template="http://s3-eu-west-1.amazonaws.com/whereonmars.cartodb.net/{basemap_id}/{z}/{x}/{y}.png",
            ... layer_options={
            ...     "basemap_id": "celestia_mars-shaded-16k_global",
            ...     "attribution" : "Celestia/praesepe",
            ...     "minZoom" : 0,
            ...     "maxZoom" : 18,
            ... })
            <IPython.core.display.GeoJSON object>

        In the terminal IPython, you will only see the text representation of
        the GeoJSON object.

        N)rd   r"   r\   )r[   argsr?   ra   s      r+   r\   zGeoJSON.__init__  s.    ` 	&gt%t6v66666r4   c                 Z    | j         dd}d| j        i}t          j        ||d           d S )Nz <IPython.display.GeoJSON object>)application/geo+jsonr<   r   T)r6   r5   )rX   r6   r   r8   )r[   bundler6   s      r+   _ipython_display_zGeoJSON._ipython_display_  sF    $(I<
 

 #DM
 	!&8FFFFFFr4   )rc   rb   r   r   r\   r  r   r   s   @r+   r"   r"     sY         07 07 07 07 07fG G G G G G Gr4   r"   c                   &     e Zd Zd fd	Zd Z xZS )r#   Nc                    t          |t                    r|g}n|g }t          |t                    r|g}n|g }t          |t          t          f          st	          d|z            t          |t          t          f          st	          d|z            || _        || _        t          t          |           	                    |||           dS )a  Create a Javascript display object given raw data.

        When this object is returned by an expression or passed to the
        display function, it will result in the data being displayed
        in the frontend. If the data is a URL, the data will first be
        downloaded and then displayed.

        In the Notebook, the containing element will be available as `element`,
        and jQuery will be available.  Content appended to `element` will be
        visible in the output area.

        Parameters
        ----------
        data : unicode, str or bytes
            The Javascript source code or a URL to download it from.
        url : unicode
            A URL to download the data from.
        filename : unicode
            Path to a local file to load the data from.
        lib : list or str
            A sequence of Javascript library URLs to load asynchronously before
            running the source code. The full URLs of the libraries should
            be given. A single Javascript library URL can also be given as a
            string.
        css : list or str
            A sequence of css files to load before running the source code.
            The full URLs of the css files should be given. A single css URL
            can also be given as a string.
        Nzexpected sequence, got: %rr   )
rS   rT   r   tupler   libcssrd   r#   r\   )r[   rX   rV   rW   r  r  ra   s         r+   r\   zJavascript.__init__  s    < c3 	%CC[Cc3 	%CC[C#U|,, 	@83>???#U|,, 	@83>???j$((dh(OOOOOr4   c                     d}| j         D ]}|t          |z  z  }| j        D ]}|t          |z  z  }|| j        z  }|t
          t          | j                  z  z  }|S )N )r  _css_tr  _lib_t1rX   _lib_t2r   )r[   rP   cls       r+   _repr_javascript_zJavascript._repr_javascript_  so     	 	A!OAA 	 	A1AA	TY	WS]]""r4   )NNNNN)rc   rb   r   r\   r  r   r   s   @r+   r#   r#     sS        ,P ,P ,P ,P ,P ,P\      r4   r#   s   PNG

s   s   GIF87as   GIF89as   WEBPc                 r    |                      d          }t          j        d| |dz   |dz                      S )z*read the (width, height) from a PNG headers   IHDRz>ii      )indexstructunpack)rX   ihdrs     r+   _pngxyr  "  s6    ::gD=T!VDG^ 4555r4   c                     d}	 t          j        d| ||dz                      d         }||z   }| ||dz            dk    r|}n|dz  }Et          j        d| |dz   |d	z                      \  }}||fS )
z+read the (width, height) from a JPEG headerr  Tz>H   r   s   z>HH   	   r  r  )rX   idx
block_sizeiSOFhws         r+   _jpegxyr!  )  s     C	]4c#a%i99!<
JCE	?k))D 1HC	 =T!VDF] 344DAqa4Kr4   c                 <    t          j        d| dd                   S )z*read the (width, height) from a GIF header<HH   r   r  )rX   s    r+   _gifxyr%  =  s    =QrT
+++r4   c                 j   | dd         dk    r.t          j        d| dd                   \  }}|dz  }|dz  }||fS | dd         dk    r[t          j        d	| d
d                   d         }d|dz  dz  z   |dz	  z  }d|dz	  dz  dz  |dz	  dz  dz  z  |dz	  dz  z  z   }||fS t          d          )z+read the (width, height) from a WEBP headerr     s   VP8 r#        i?  s   VP8Lz<I      r   r   ?   r      r      i  r        zNot a valid WEBP header)r  r  
ValueError)rX   widthheight	size_infos       r+   _webpxyr5  B  s    BrE{geT"R%[99v&v	be		M$RU44Q7	i$&1,-bAA~$+bE)a/1R3&(

 v2333r4   c                        e Zd ZdZdZdZdZdZeeeegZedededed	iZ		 	 	 	 	 	 	 	 	 	 	 d fd	Z
d Z fdZd ZddZddZd Zd Zd Z xZS )r$   r   jpegpnggifwebprF   rH   z	image/gifrJ   NFc                    t          |t          t          f          rt          |          }||                     |          }nz||                     |          }nb|t          d          t          |t                    r:|                    d          st          |          r|                     |          }nd}||S|dk    s|dk    r| j        }n|dk    r| j	        }n|dk    r| j
        }n|dk    r| j        }n|                                }nt          |t                    r~|dd	         t          k    r| j        }nc|dd
         t          k    r| j	        }nH|d
d         t           k    r| j        }n-|dd         t"          k    s|dd         t$          k    r| j
        }|| j	        }|                                dk    r| j        }|                                | _        ||n|du | _        | j        r%| j        | j        vrt          d| j        z            | j        r$| j                            | j                  | _        || _        || _        || _        |	| _        || _        t=          t>          |                                ||||
           | j        (| j!                            di           r|
d         | _        | j        (| j!                            di           r|
d         | _        | j        (| j!                            di           r|
d         | _        |r| "                                 dS dS )a5  Create a PNG/JPEG/GIF/WEBP image object given raw data.

        When this object is returned by an input cell or passed to the
        display function, it will result in the image being displayed
        in the frontend.

        Parameters
        ----------
        data : unicode, str or bytes
            The raw image data or a URL or filename to load the data from.
            This always results in embedded image data.

        url : unicode
            A URL to download the data from. If you specify `url=`,
            the image data will not be embedded unless you also specify `embed=True`.

        filename : unicode
            Path to a local file to load the data from.
            Images from a file are always embedded.

        format : unicode
            The format of the image data (png/jpeg/jpg/gif/webp). If a filename or URL is given
            for format will be inferred from the filename extension.

        embed : bool
            Should the image data be embedded using a data URI (True) or be
            loaded using an <img> tag. Set this to True if you want the image
            to be viewable later with no internet connection in the notebook.

            Default is `True`, unless the keyword argument `url` is set, then
            default value is `False`.

            Note that QtConsole is not able to display images if `embed` is set to `False`

        width : int
            Width in pixels to which to constrain the image in html

        height : int
            Height in pixels to which to constrain the image in html

        retina : bool
            Automatically set the width and height to half of the measured
            width and height.
            This only works for embedded images because it reads the width/height
            from image data.
            For non-embedded images, you can just set the desired display width
            and height directly.

        unconfined : bool
            Set unconfined=True to disable max-width confinement of the image.

        metadata : dict
            Specify extra metadata to attach to the image.

        alt : unicode
            Alternative text for the image, for use by screen readers.

        Examples
        --------
        embedded image data, works in qtconsole and notebook
        when passed positionally, the first arg can be any of raw image data,
        a URL, or a filename from which to load image data.
        The result is always embedding image data for inline images.

        >>> Image('https://www.google.fr/images/srpr/logo3w.png') # doctest: +SKIP
        <IPython.core.display.Image object>

        >>> Image('/path/to/image.jpg')
        <IPython.core.display.Image object>

        >>> Image(b'RAW_PNG_DATA...')
        <IPython.core.display.Image object>

        Specifying Image(url=...) does not embed the image data,
        it only generates ``<img>`` tag with a link to the source.
        This will not work in the qtconsole or offline.

        >>> Image(url='https://www.google.fr/images/srpr/logo3w.png')
        <IPython.core.display.Image object>

        Nz6No image data found. Expecting filename, url, or data.rR   jpgr7  r8  r9  r:  r  r   r  r$  z"Cannot embed the '%s' image formatr   r2  r3  alt)#rS   r   r   rT   	_find_extr1  rU   r,   	_FMT_JPEG_FMT_PNG_FMT_GIF	_FMT_WEBPr   r   _JPEG_PNG_WEBP_GIF1_GIF2r   embed_ACCEPTABLE_EMBEDDINGS
_MIMETYPESget	_mimetyper2  r3  retina
unconfinedr=  rd   r$   r\   r6   _retina_shape)r[   rX   rV   rW   r   rH  r2  r3  rM  rN  r6   r=  extra   s                r+   r\   zImage.__init__e  sW   ~ dT8,-- 	t99D..**CC_..%%CC\UVVVc"" 	OOF##	'3D'9'9	 ..&&CCC>&==C7NN!^FFF]]!]FFF]]!]FFF]]!^FF YY[[FFD%(( 
+ 8u$$!^FF"1"X%%!]FF!B$Z5((!^FF"1"X&&$rr(e*;*;!]F >]F<<>>U""^Fllnn#/UUcTk
: 	S$+T-HHHAT[QRRR: 	>!_00==DN
$eT##3! 	$ 	# 	# 	# :$-"3"3GR"@"@!'*DJ;4=#4#4Xr#B#B"8,DK8 1 1% < <DH 	!     	! 	!r4   c                 4   | j         sdS | j        | j        k    rt          | j                  \  }}nR| j        | j        k    rt          | j                  \  }}n*| j        | j        k    rt          | j                  \  }}ndS |dz  | _	        |dz  | _
        dS )z3load pixel-doubled width and height from image dataNr  )rH  r   r@  r  rX   r?  r!  rA  r%  r2  r3  )r[   r   r  s      r+   rO  zImage._retina_shape  s    z 	F;$-''$)$$DAqq[DN**49%%DAqq[DM))$)$$DAqq F!V
1fr4   c                     | j         rDt          t          |                                            | j        r|                                  dS dS dS )rn   N)rH  rd   r$   rY   rM  rO  )r[   ra   s    r+   rY   zImage.reload!  s_    : 	%%$$&&&{ %""$$$$$	% 	%% %r4   c                     | j         sudx}x}x}}| j        r
d| j        z  }| j        r
d| j        z  }| j        rd}| j        rdt          j        | j                  z  }d                    | j        ||||          S d S )Nr   width="%d" height="%d"z class="unconfined"z	 alt="%s"z-<img src="{url}"{width}{height}{klass}{alt}/>)rV   r2  r3  klassr=  )	rH  r2  r3  rN  r=  htmlescaper   rV   )r[   r2  r3  rV  r=  s        r+   r   zImage._repr_html_(  s    z 	+--E-F-USz 3%
2{ 6'$+5 .-x :!DK$9$99BIIH J   	 	r4   c                     | j         r,| j        }|                     d          \  }}|r||i}||i|fS d|                                 iS )zgReturn the image as a mimebundle

        Any new mimetype support should be implemented here.
        T)always_bothrB   )rH  rL  rl   r   )r[   r7   excluder2   rX   r6   s         r+   _repr_mimebundle_zImage._repr_mimebundle_;  sh    
 : 	5~H!444FFND( 0$h/d#X--!1!1!3!344r4   c                    	 t          | j        d                              d          }n*# t          $ r}t	          d| j        z            |d}~ww xY wi }| j        r|                    | j                   | j        r
| j        |d<   | j        r
| j        |d<   | j	        r
| j	        |d<   | j
        r
| j
        |d	<   |s|r||fS |S )
rk   Fnewliner   zNo such file or directory: '%s'Nr2  r3  rN  r=  )r   rX   r   r   FileNotFoundErrorr6   r   r2  r3  rN  r=  )r[   rZ  b64_dataemds        r+   rl   zImage._data_and_metadataI  s	   	H!$)U;;;BB7KKHH 	H 	H 	H#1TY?A AFGH	H = 	%IIdm$$$: 	%*BwK; 	';BxL? 	/#B|8 	!BuI 	 	R<Os   ), 
AAAc                 `    | j         r$| j        | j        k    r|                                 S d S d S r   )rH  r   r@  rl   rh   s    r+   
_repr_png_zImage._repr_png_`  s<    : 	-$+66**,,,	- 	-66r4   c                 `    | j         r$| j        | j        k    r|                                 S d S d S r   )rH  r   r?  rl   rh   s    r+   _repr_jpeg_zImage._repr_jpeg_d  s<    : 	-$+77**,,,	- 	-77r4   c                 f    t          |          \  }}|s|S |dd                                          S )Nr   )r   r   )r[   r   baserP  s       r+   r>  zImage._find_exth  s6    QKK	c 	K 122w}}r4   )NNNNNNNFFNN)NN)F)rc   rb   r   rz   r?  r@  rA  rB  rI  rJ  r\   rO  rY   r   r\  rl   re  rg  r>  r   r   s   @r+   r$   r$   V  s6       KIHHI'8YG+<+<	J i! i! i! i! i! i!X   % % % % %  &5 5 5 5   .- - -- - -      r4   r$   c                   0     e Zd Z	 	 d fd	Zd Zd Z xZS )r%   NFcontrolsc	                    t          |t          t          f          rt          |          }|/t          |t                    r|                    d          r|}d}n%|#t
          j                            |          r|}d}|r(|s&d                    g d          }	t          |	          || _
        || _        || _        || _        || _        t          t           |                               |||           dS )a  Create a video object given raw data or an URL.

        When this object is returned by an input cell or passed to the
        display function, it will result in the video being displayed
        in the frontend.

        Parameters
        ----------
        data : unicode, str or bytes
            The raw video data or a URL or filename to load the data from.
            Raw data will require passing ``embed=True``.

        url : unicode
            A URL for the video. If you specify ``url=``,
            the image data will not be embedded.

        filename : unicode
            Path to a local file containing the video.
            Will be interpreted as a local URL unless ``embed=True``.

        embed : bool
            Should the video be embedded using a data URI (True) or be
            loaded using a <video> tag (False).

            Since videos are large, embedding them should be avoided, if possible.
            You must confirm embedding as your intention by passing ``embed=True``.

            Local files can be displayed with URLs without embedding the content, via::

                Video('./video.mp4')

        mimetype : unicode
            Specify the mimetype for embedded videos.
            Default will be guessed from file extension, if available.

        width : int
            Width in pixels to which to constrain the video in HTML.
            If not supplied, defaults to the width of the video.

        height : int
            Height in pixels to which to constrain the video in html.
            If not supplied, defaults to the height of the video.

        html_attributes : str
            Attributes for the HTML ``<video>`` block.
            Default: ``"controls"`` to get video controls.
            Other examples: ``"controls muted"`` for muted video with controls,
            ``"loop autoplay"`` for looping autoplaying video without controls.

        Examples
        --------
        ::

            Video('https://archive.org/download/Sita_Sings_the_Blues/Sita_Sings_the_Blues_small.mp4')
            Video('path/to/video.mp4')
            Video('path/to/video.mp4', embed=True)
            Video('path/to/video.mp4', embed=True, html_attributes="controls muted autoplay")
            Video(b'raw-videodata', embed=True)
        N)zhttp:zhttps:r  )z*To embed videos, you must pass embed=True z)(this may make your notebook files huge)
z!Consider passing Video(url='...')r   )rS   r   r   rT   rU   r'   r(   r)   joinr1  r2   rH  r2  r3  html_attributesrd   r%   r\   )r[   rX   rV   rW   rH  r2   r2  r3  rn  msgra   s             r+   r\   zVideo.__init__t  s	   z dT8,-- 	t99D;:dC00;T__EX5Y5Y;CDD"'.."6"6HD 	" 	"''     C
 S//! 

.eT##3#JJJJJr4   c                    dx}}| j         r
d| j         z  }| j        r
d| j        z  }| j        s4| j        | j        n| j        }d                    || j        ||          }|S | j        }| j        `|st          j	        | j                  \  }}t          | j        d          5 }|                                }d d d            n# 1 swxY w Y   n| j        }t          |t                    r|}	n6t          |d                              d                                          }	d	                    | j        ||||	          }|S )
Nr  rT  rU  zn<video src="{0}" {1} {2} {3}>
      Your browser does not support the <code>video</code> element.
    </video>r   Fr^  r   zz<video {0} {1} {2}>
 <source src="data:{3};base64,{4}" type="{3}">
 Your browser does not support the video tag.
 </video>)r2  r3  rH  rV   rW   r   rn  r2   	mimetypes
guess_typer{   r|   rX   rS   rT   r   r   rstrip)
r[   r2  r3  rV   outputr2   _r   video	b64_videos
             r+   r   zVideo._repr_html_  s   : 	/!DJ.E; 	2#dk1F z 	"h2$((CsD0%@@  M ==$ B'24=AA!dmT** !a! ! ! ! ! ! ! ! ! ! ! ! ! ! ! IEeS!! 	RII"5%888??HHOOQQI VD(%9MM 	 s   #CCCc                     d S r   r/   rh   s    r+   rY   zVideo.reload  ri   r4   )NNNFNNNrk  )rc   rb   r   r\   r   rY   r   r   s   @r+   r%   r%   r  so        AFISTK TK TK TK TK TKl$ $ $L      r4   r%   )FN)?r   binasciir   r   rW  r   rq  r'   r  r   copyr   os.pathr   pathlibr   r   typingr	   IPython.testing.skipdoctestr
   r  r   __all__r,   r:   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r	  r
  r  r"   r#   rD  rC  rF  rG  rE  r  r!  r%  r5  r$   r%   r/   r4   r+   <module>r     s   M M ) ( ( ( ( ( ( (       				               " " " " " " " "       4 4 4 4 4 4        @  U U U U84 4 4"3 3 3(7 7 7$7 7 7"3 3 3"4 4 4"4 4 4"4 4 4": : :&@ @ @"9 9 9,r! r! r! r! r! r! r! r!j^ ^ ^ ^ ^ ^ ^ ^$" " " " " " " "" " " " " " " ">) ) ) ) )  ) ) )       ) ) ) ) ) ) ) )&) &) &) &) &)- &) &) &)P8" 8" 8" 8" 8"- 8" 8" 8"t>) >) >) >) >)= >) >) >)B
CG CG CG CG CGd CG CG CGJ8 8 8 8 8" 8 8 8x 6 6 6  (, , ,
4 4 4(Y Y Y Y YM Y Y Yx@ @ @ @ @M @ @ @ @ @r4   