
&9_[c           @  su  d  Z  d d l m Z y d d l m Z Wn! e k
 rM d d l m Z n Xd 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 m Z m Z m Z d d l m Z d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% g Z d&   Z d'   Z e d d(  Z d d d)  Z d*   Z d+   Z  d,   Z! d% e" f d-     YZ# d.   Z$ d/   Z% d0   Z& d1   Z' d2   Z( d3   Z) d4   Z* d5   Z+ d6   Z, d7   Z- d e" f d8     YZ. d e. f d9     YZ/ d e/ f d:     YZ0 d e/ f d;     YZ1 d e/ f d<     YZ2 d e/ f d=     YZ3 d e/ f d>     YZ4 d e. f d?     YZ5 d e. f d@     YZ6 d e. f dA     YZ7 dB Z8 dC Z9 dD Z: d e/ f dE     YZ; dF Z< dG Z= dH   Z> dI   Z? d e. f dJ     YZ@ dK e. f dL     YZA e dM  ZB e dN    ZC e eD dO   ZE d S(P   sG   Top-level display functions for displaying object in different formats.i(   t   print_function(   t   encodebytes(   t   encodestring(   t   b2a_hext   hexlifyN(   t   string_typest   cast_bytes_py2t   cast_unicodet   unicode_type(   t   skip_doctestt   displayt   display_prettyt   display_htmlt   display_markdownt   display_svgt   display_pngt   display_jpegt   display_latext   display_jsont   display_javascriptt   display_pdft   DisplayObjectt   TextDisplayObjectt   Prettyt   HTMLt   Markdownt   Matht   Latext   SVGt   ProgressBart   JSONt
   Javascriptt   Imaget   clear_outputt   set_matplotlib_formatst   set_matplotlib_closet   publish_display_datat   update_displayt   DisplayHandlec         C  s-   y t  j j |   SWn t k
 r( t SXd S(   s*   Check path, but don't let exceptions raiseN(   t   ost   patht   existst	   Exceptiont   False(   R(   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _safe_exists%   s    c         C  sa   t  | t  s  t  |  t  r$ | Sx6 | j   D]( \ } } t |  j |  |  |  | <q1 W|  S(   sg   Like update, but merges sub-dicts instead of clobbering at the top level.

    Updates d1 in-place
    (   t
   isinstancet   dictt   itemst   _merget   get(   t   d1t   d2t   keyt   value(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR0   ,   s
      c         C  sb   | r i | |  6} n  | r? g  | D] } i | |  6^ q# } n  t  d | d | d |  g |  d S(   s  internal implementation of all display_foo methods

    Parameters
    ----------
    mimetype : str
        The mimetype to be published (e.g. 'image/png')
    objs : tuple of objects
        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.
    t   rawt   metadatat   includeN(   R
   (   t   mimetypet   objsR6   R7   t   obj(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _display_mimetype8   s
    #c         K  s<   d d l  m } | j   j } | j d |  d | |  d S(   s,  Publish data and metadata to all frontends.

    See the ``display_data`` message in the messaging documentation for
    more details about this message type.

    The following MIME types are currently implemented:

    * text/plain
    * text/html
    * text/markdown
    * text/latex
    * application/json
    * application/javascript
    * image/png
    * image/jpeg
    * image/svg+xml

    Parameters
    ----------
    data : dict
        A dictionary having keys that are valid MIME types (like
        'text/plain' or 'image/svg+xml') and values that are the data for
        that MIME type. The data itself must be a JSON'able data
        structure. Minimally all data should have the 'text/plain' data,
        which can be displayed by all frontends. If more than the plain
        text is given, it is up to the frontend to decide which
        representation to use.
    metadata : dict
        A dictionary for metadata related to the data. This can contain
        arbitrary key, value pairs that frontends can use to interpret
        the data. mime-type keys matching those in data can be used
        to specify metadata about particular representations.
    source : str, deprecated
        Unused.
    transient : dict, keyword-only
        A dictionary of transient data, such as display_id.
        i(   t   InteractiveShellt   dataR7   N(   t   IPython.core.interactiveshellR=   t   instancet   display_pubt   publish(   R>   R7   t   sourcet   kwargsR=   RA   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR$   S   s    &	c           C  s   t  t j d   j d  S(   s*   Generate a new random text id with urandomi   t   ascii(   R   R'   t   urandomt   decode(    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _new_id   s    c          O  s  d d l  m } | j   s* t |    d S| j d t  } | j d d  } | j d d  } | j d d  } | j d d  } | j d	 d  } | d k r i  } n  | r | t k r t   } n  | | d	 <n  | j	 d
  r d	 | k r t
 d   n  | r| | d <n  | s.| j   j j }	 n  x |  D]{ }
 | rZt d |
 d | |  q5|	 |
 d | d | \ } } | sq5n  | rt | |  n  t d | d | |  q5W| rt |  Sd S(   s  Display a Python object in all frontends.

    By default all representations will be computed and sent to the frontends.
    Frontends can decide which representation is used and how.

    In terminal IPython this will be similar to using :func:`print`, for use in richer
    frontends see Jupyter notebook examples with rich display logic.

    Parameters
    ----------
    objs : tuple of objects
        The Python objects to display.
    raw : bool, optional
        Are the objects to be displayed already mimetype-keyed dicts of raw display data,
        or Python objects that need to be formatted before display? [default: False]
    include : list, tuple or set, optional
        A list of format type strings (MIME types) to include in the
        format data dict. If this is set *only* the format types included
        in this list will be computed.
    exclude : list, tuple or set, optional
        A list of format type strings (MIME types) to exclude in the format
        data dict. If this is set all format types will be computed,
        except for those included in this argument.
    metadata : dict, optional
        A dictionary of metadata to associate with the output.
        mime-type keys in this dictionary will be associated with the individual
        representation formats, if they exist.
    transient : dict, optional
        A dictionary of transient data to associate with the output.
        Data in this dict should not be persisted to files (e.g. notebooks).
    display_id : str, bool optional
        Set an id for the display.
        This id can be used for updating this display area later via update_display.
        If given as `True`, generate a new `display_id`
    kwargs: additional keyword-args, optional
        Additional keyword-arguments are passed through to the display publisher.

    Returns
    -------

    handle: DisplayHandle
        Returns a handle on updatable displays for use with :func:`update_display`,
        if `display_id` is given. Returns :any:`None` if no `display_id` is given
        (default).

    Examples
    --------

    >>> class Json(object):
    ...     def __init__(self, json):
    ...         self.json = json
    ...     def _repr_pretty_(self, pp, cycle):
    ...         import json
    ...         pp.text(json.dumps(self.json, indent=2))
    ...     def __repr__(self):
    ...         return str(self.json)
    ...

    >>> d = Json({1:2, 3: {4:5}})

    >>> print(d)
    {1: 2, 3: {4: 5}}

    >>> display(d)
    {
      "1": 2,
      "3": {
        "4": 5
      }
    }

    >>> def int_formatter(integer, pp, cycle):
    ...     pp.text('I'*integer)

    >>> plain = get_ipython().display_formatter.formatters['text/plain']
    >>> plain.for_type(int, int_formatter)
    <function _repr_pprint at 0x...>
    >>> display(7-5)
    II

    >>> del plain.type_printers[int]
    >>> display(7-5)
    2

    See Also
    --------

    :func:`update_display`

    Notes
    -----

    In Python, objects can declare their textual representation using the
    `__repr__` method. IPython expands on this idea and allows objects to declare
    other, rich representations including:

      - HTML
      - JSON
      - PNG
      - JPEG
      - SVG
      - LaTeX

    A single object can declare some or all of these representations; all are
    handled by IPython's display system.

    The main idea of the first approach is that you have to implement special
    display methods when you define your class, one for each representation you
    want to use. Here is a list of the names of the special methods and the
    values they must return:

      - `_repr_html_`: return raw HTML as a string
      - `_repr_json_`: return a JSONable dict
      - `_repr_jpeg_`: return raw JPEG data
      - `_repr_png_`: return raw PNG data
      - `_repr_svg_`: return raw SVG data as a string
      - `_repr_latex_`: return LaTeX commands in a string surrounded by "$".
      - `_repr_mimebundle_`: return a full mimebundle containing the mapping
      from all mimetypes to data

    When you are directly writing your own classes, you can adapt them for
    display in IPython by following the above approach. But in practice, you
    often need to work with existing classes that you can't easily modify.

    You can refer to the documentation on IPython display formatters in order to
    register custom formatters for already existing types.

    .. versionadded:: 5.4 display available without import
    .. versionadded:: 6.1 display available without import

    Since IPython 5.4 and 6.1 :func:`display` is automatically made available to
    the user without import. If you are using display in a document that might
    be used in a pure python context or with older version of IPython, use the
    following import at the top of your file::

        from IPython.display import display

    i(   R=   NR6   R8   t   excludeR7   t	   transientt
   display_idt   updates&   display_id required for update_displayR>   (   R?   R=   t   initializedt   printt   popR+   t   Nonet   TrueRH   R1   t	   TypeErrorR@   t   display_formattert   formatR$   R0   R&   (   R:   RD   R=   R6   R8   RI   R7   RJ   RK   RT   R;   t   format_dictt   md_dict(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR
      sB    
	c         K  sW   t    } | j d |  } | | k r6 t d   n  t | d <t |  d | | d S(   s   Update an existing display by id

    Parameters
    ----------

    obj:
        The object with which to update the display
    display_id: keyword-only
        The id of the display to update

    See Also
    --------

    :func:`display`
    RK   sG   update_display() missing 1 required keyword-only argument: 'display_id'RL   N(   t   objectRO   RR   RQ   R
   (   R;   RD   t   sentinelRK   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR%   D  s    	
c           B  s5   e  Z d  Z d d  Z d   Z d   Z d   Z RS(   s  A handle on an updatable display

    Call `.update(obj)` to display a new object.

    Call `.display(obj`) to add a new instance of this display,
    and update existing instances.

    See Also
    --------

        :func:`display`, :func:`update_display`

    c         C  s%   | d  k r t   } n  | |  _ d  S(   N(   RP   RH   RK   (   t   selfRK   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   __init__k  s    c         C  s   d |  j  j |  j f S(   Ns   <%s display_id=%s>(   t	   __class__t   __name__RK   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   __repr__p  s    c         K  s   t  | d |  j | d S(   s   Make a new display with my id, updating existing instances.
        
        Parameters
        ----------
        
        obj:
            object to display
        **kwargs:
            additional keyword arguments passed to display
        RK   N(   R
   RK   (   RY   R;   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR
   s  s    c         K  s   t  | d |  j | d S(   s   Update existing displays with my id
        
        Parameters
        ----------
        
        obj:
            object to display
        **kwargs:
            additional keyword arguments passed to update_display
        RK   N(   R%   RK   (   RY   R;   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRL     s    N(   R\   t
   __module__t   __doc__RP   RZ   R]   R
   RL   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR&   \  s
   		c          O  s   t  d |  |  d S(   s  Display the pretty (default) representation of an object.

    Parameters
    ----------
    objs : tuple of objects
        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.
    s
   text/plainN(   R<   (   R:   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c          O  s   t  d |  |  d S(   s  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 : tuple of objects
        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.
    s	   text/htmlN(   R<   (   R:   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c          O  s   t  d |  |  d S(   s  Displays the Markdown representation of an object.

    Parameters
    ----------
    objs : tuple of objects
        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.
    s   text/markdownN(   R<   (   R:   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c          O  s   t  d |  |  d S(   s  Display the SVG representation of an object.

    Parameters
    ----------
    objs : tuple of objects
        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.
    s   image/svg+xmlN(   R<   (   R:   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c          O  s   t  d |  |  d S(   s  Display the PNG representation of an object.

    Parameters
    ----------
    objs : tuple of objects
        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.
    s	   image/pngN(   R<   (   R:   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c          O  s   t  d |  |  d S(   s  Display the JPEG representation of an object.

    Parameters
    ----------
    objs : tuple of objects
        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.
    s
   image/jpegN(   R<   (   R:   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c          O  s   t  d |  |  d S(   s  Display the LaTeX representation of an object.

    Parameters
    ----------
    objs : tuple of objects
        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.
    s
   text/latexN(   R<   (   R:   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c          O  s   t  d |  |  d S(   s  Display the JSON representation of an object.

    Note that not many frontends support displaying JSON.

    Parameters
    ----------
    objs : tuple of objects
        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.
    s   application/jsonN(   R<   (   R:   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR   	  s    c          O  s   t  d |  |  d S(   s  Display the Javascript representation of an object.

    Parameters
    ----------
    objs : tuple of objects
        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.
    s   application/javascriptN(   R<   (   R:   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c          O  s   t  d |  |  d S(   s  Display the PDF representation of an object.

    Parameters
    ----------
    objs : tuple of objects
        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.
    s   application/pdfN(   R<   (   R:   RD   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR   -  s    c           B  sG   e  Z d  Z d Z e Z d d d d  Z d   Z d   Z	 d   Z
 RS(   s*   An object that wraps data to be displayed.t   rc         C  s   | d k	 r{ t | t  r{ | j d  rK | d k rK | } d } d } q{ t |  r{ | d k r{ d } | } d } q{ n  | |  _ | |  _ | d k r d n	 t |  |  _ |  j	   |  j
   d S(   s  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. If

        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.
        t   httpN(   RP   R-   R   t
   startswithR,   R>   t   urlR   t   filenamet   reloadt   _check_data(   RY   R>   Rc   Rd   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRZ   I  s    			!
c         C  sD   |  j  s+ |  j } d | j | j f } n t t |   j   } | S(   Ns   <%s.%s object>(   t   _show_mem_addrR[   R^   R\   t   superR   R]   (   RY   t   clsR`   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR]   m  s
    		c         C  s   d S(   s5   Override in subclasses if there's something to check.N(    (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRf   u  s    c         C  sB  |  j  d k	 r? t |  j  |  j   } | j   |  _ Wd QXn |  j d k	 r>y y d d l m } Wn! t	 k
 r d d l
 m } n X| |  j  } | j   |  _ d } xV | j d j d  D]> } | j   } | j d  r | j d  d j   } Pq q W| r'|  j j | d  |  _ n  Wq>d |  _ q>Xn  d S(	   s%   Reload the raw data from file or URL.Ni(   t   urlopens   content-typet   ;t   charsett   =t   replace(   Rd   RP   t   opent   _read_flagst   readR>   Rc   t   urllib.requestRj   t   ImportErrort   urllib2t   headerst   splitt   stripRb   RG   (   RY   t   fRj   t   responset   encodingt   sub(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRe   y  s*    N(   R\   R^   R_   Rp   R+   Rg   RP   RZ   R]   Rf   Re   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR   C  s   $		c           B  s   e  Z d  Z d   Z RS(   s"   Validate that display data is textc         C  sH   |  j  d  k	 rD t |  j  t  rD t d |  j j |  j  f   n  d  S(   Ns   %s expects text, not %r(   R>   RP   R-   R   RR   R[   R\   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRf     s    "(   R\   R^   R_   Rf   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s   c           B  s   e  Z d    Z RS(   c         C  s   | j  |  j  S(   N(   t   textR>   (   RY   t   ppt   cycle(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _repr_pretty_  s    (   R\   R^   R   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s   c           B  s   e  Z d    Z d   Z RS(   c         C  s   |  j  S(   N(   R>   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _repr_html_  s    c         C  s
   |  j    S(   s   
        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   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   __html__  s    (   R\   R^   R   R   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s   	c           B  s   e  Z d    Z RS(   c         C  s   |  j  S(   N(   R>   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _repr_markdown_  s    (   R\   R^   R   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s   c           B  s   e  Z d    Z RS(   c         C  s   |  j  j d  } d | S(   Nt   $s   $$%s$$(   R>   Rw   (   RY   t   s(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _repr_latex_  s    (   R\   R^   R   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s   c           B  s   e  Z d    Z RS(   c         C  s   |  j  S(   N(   R>   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    (   R\   R^   R   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s   c           B  s>   e  Z d  Z d Z e d    Z e j d    Z d   Z RS(   t   rbc         C  s   |  j  S(   N(   t   _data(   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR>     s    c         C  s   | d  k r d  |  _ d  Sd d l m } t |  } | j |  } | j d  } | rl | d j   } n  t |  } | |  _ d  S(   Ni(   t   minidomt   svgi    (	   RP   R   t   xml.domR   R   t   parseStringt   getElementsByTagNamet   toxmlR   (   RY   R   R   t   xt	   found_svg(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR>     s    	c         C  s   |  j  S(   N(   R>   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt
   _repr_svg_  s    N(	   R\   R^   Rp   RP   R   t   propertyR>   t   setterR   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s
   c           B  sw   e  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
   Z RS(   s@   Progressbar supports displaying a progressbar like element 
    c         C  sI   | |  _  d |  _ d |  _ d |  _ t t j d   j d  |  _ d S(   s   Creates a new progressbar
        
        Parameters
        ----------
        total : int
            maximum size of the progressbar
        i    t   60exi<   i   RE   N(	   t   totalt	   _progresst
   html_widtht
   text_widthR   R'   RF   RG   t   _display_id(   RY   R   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRZ     s
    				c         C  sZ   |  j  |  j } d t | |  j  } d |  j t |  } d j | | |  j  |  j  S(   NRm   t    s   [{}{}] {}/{}(   t   progressR   t   intR   t   lenRT   (   RY   t   fractiont   filledt   rest(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR]     s    c         C  s   d j  |  j |  j |  j  S(   Ns:   <progress style='width:{}' max='{}' value='{}'></progress>(   RT   R   R   R   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c         C  s   t  |  d |  j d  S(   NRK   (   R
   R   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR
      s    c         C  s   t  |  d |  j d t d  S(   NRK   RL   (   R
   R   RQ   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRL     s    c         C  s   |  j  S(   N(   R   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c         C  s   | |  _  |  j   d  S(   N(   R   RL   (   RY   R5   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR   
  s    	c         C  s   |  j    d |  _ |  S(   Ni(   R
   R   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   __iter__  s    
	c         C  s5   |  j  d 7_  |  j  |  j k  r( |  j  St    d S(   s4   Returns current value and increments display by one.i   N(   R   R   t   StopIteration(   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   __next__  s    c         C  s
   |  j    S(   s   Python 2 compatibility(   R   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   next  s    (   R\   R^   R_   RZ   R]   R   R
   RL   R   R   R   R   R   R   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s   								c           B  sG   e  Z d  Z d Z d   Z e d    Z e j d    Z d   Z	 RS(   s   JSON 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.
    c         C  sN   |  j  d  k	 rJ t |  j  t t f  rJ t d |  j j |  j  f   n  d  S(   Ns(   %s expects JSONable dict or list, not %r(   R>   RP   R-   R.   t   listRR   R[   R\   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRf   )  s    (c         C  s   |  j  S(   N(   R   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR>   -  s    c         C  s;   t  | t  r. t j d  t j |  } n  | |  _ d  S(   Ns4   JSON expects JSONable dict or list, not JSON strings(   R-   R   t   warningst   warnt   jsont   loadsR   (   RY   R>   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR>   1  s    c         C  s   |  j  S(   N(   R>   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _repr_json_8  s    N(
   R\   R^   R_   RP   R   Rf   R   R>   R   R   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR      s   	sa   $("head").append($("<link/>").attr({
  rel:  "stylesheet",
  type: "text/css",
  href: "%s"
}));
s    $.getScript("%s", function () {
s   });
c           B  s)   e  Z d d d d d d   Z d   Z RS(   c         C  s   t  | t  r | g } n | d k r0 g  } n  t  | t  rK | g } n | d k r` g  } n  t  | t t f  s t d |   n  t  | t t f  s t d |   n  | |  _ | |  _ t t	 |   j
 d | d | d |  d S(   s  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.
        s   expected sequence, got: %rR>   Rc   Rd   N(   R-   R   RP   R   t   tupleRR   t   libt   cssRh   R   RZ   (   RY   R>   Rc   Rd   R   R   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRZ   I  s    				c         C  sr   d } x |  j  D] } | t | 7} q Wx |  j D] } | t | 7} q2 W| |  j 7} | t t |  j  7} | S(   Nt    (   R   t   css_tR   t   lib_t1R>   t   lib_t2R   (   RY   R`   t   ct   l(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _repr_javascript_w  s    N(   R\   R^   RP   RZ   R   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR   G  s   .s   PNG

s   c         C  s4   |  j  d  } |  | d | d !} t j d |  S(   s*   read the (width, height) from a PNG headert   IHDRi   i   s   >ii(   t   indext   structt   unpack(   R>   t   ihdrt   w4h4(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _pngxy  s    c         C  s   d } x` t  rh t j d |  | | d ! d } | | } |  | | d !d k r[ | } Pq	 | d 7} q	 Wt j d |  | d | d ! \ } } | | f S(	   s+   read the (width, height) from a JPEG headeri   s   >Hi   i    s   s   >HHi   i	   (   RQ   R   R   (   R>   t   idxt
   block_sizet   iSOFt   ht   w(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _jpegxy  s    	!
'c           B  s   e  Z d  Z d Z d Z e e g Z d d d d d d d e e d d 
 Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z d
   Z RS(   R   u   jpegu   pngc         C  s0  | d k	 r |  j |  } n{ | d k	 r< |  j |  } n] | d k rW t d   nB t | t  r | j d  s t |  r |  j |  } n d } | d k r-| d k	 r | d k s | d k r |  j } q*| d k r |  j } q*| j	   } q-t | t
  r-| d  t k r*|  j } q*q-n  | d k rBd } n  | j	   d k r`|  j } n  t |  j	   |  _ | d k	 r| n	 | d k |  _ |  j r|  j |  j k rt d	 |  j   n  | |  _ | |  _ | |  _ |	 |  _ |
 |  _ t t |   j d
 | d | d |  | r,|  j   n  d S(   s
  Create a PNG/JPEG 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). 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.

        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('http://www.google.fr/images/srpr/logo3w.png')
        Image('/path/to/image.jpg')
        Image(b'RAW_PNG_DATA...')

        # 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='http://www.google.fr/images/srpr/logo3w.png')

        s6   No image data found. Expecting filename, url, or data.Ra   u   jpgu   jpegu   pngi   t   pngt   jpgs"   Cannot embed the '%s' image formatR>   Rc   Rd   N(   RP   t	   _find_extt
   ValueErrorR-   R   Rb   R,   t	   _FMT_JPEGt   _FMT_PNGt   lowert   bytest   _JPEGR   RT   t   embedt   _ACCEPTABLE_EMBEDDINGSt   widtht   heightt   retinat
   unconfinedR7   Rh   R    RZ   t   _retina_shape(   RY   R>   Rc   Rd   RT   R   R   R   R   R   R7   t   ext(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRZ     sH    @	!					%c         C  s}   |  j  s d S|  j d k r4 t |  j  \ } } n+ |  j d k r[ t |  j  \ } } n d S| d |  _ | d |  _ d S(   s3   load pixel-doubled width and height from image dataNR   t   jpegi   (   R   RT   R   R>   R   R   R   (   RY   R   R   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    	c         C  s9   |  j  r5 t t |   j   |  j r5 |  j   q5 n  d S(   s%   Reload the raw data from file or URL.N(   R   Rh   R    Re   R   R   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRe   &  s    		c      	   C  s   |  j  s d } } } |  j r0 d |  j } n  |  j rI d |  j } n  |  j r[ d } n  d j d |  j d | d | d	 |  Sd  S(
   NR   s    width="%d"s    height="%d"s    class="unconfined"u(   <img src="{url}"{width}{height}{klass}/>Rc   R   R   t   klass(   R   R   R   R   RT   Rc   (   RY   R   R   R   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR   -  s    							c         C  s   i  } |  j  r |  j  | d <n  |  j r8 |  j | d <n  |  j rQ |  j | d <n  |  j rm | j |  j  n  | r |  j | f S|  j Sd S(   sB   shortcut for returning metadata with shape information, if definedR   R   R   N(   R   R   R   R7   RL   R>   (   RY   t   md(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _data_and_metadata=  s    				c         C  s&   |  j  r" |  j d k r" |  j   Sd  S(   Nu   png(   R   RT   R   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt
   _repr_png_M  s    c         C  s5   |  j  r1 |  j d k s' |  j d k r1 |  j   Sd  S(   Nu   jpegu   jpg(   R   RT   R   (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   _repr_jpeg_Q  s    'c         C  s   t  | j d  d j    S(   Nt   .i(   R   Rv   R   (   RY   R   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR   U  s    N(   R\   R^   Rp   R   R   R   RP   R+   RZ   R   Re   R   R   R   R   R   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR      s   p						t   Videoc           B  sD   e  Z d d d e d d   Z d   Z d   Z d   Z d   Z RS(   c         C  s   | d
 k r9 t | t  r9 | j d  r9 | } d
 } n! t j j |  rZ | } d
 } n  | r | r d j d d d g  } t |   n  | |  _	 | |  _
 t t |   j d | d | d	 |  d
 S(   s  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.

        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(b'raw-videodata', embed=True)
        s   http:s   https:R   s*   To embed videos, you must pass embed=True s)   (this may make your notebook files huge)
s!   Consider passing Video(url='...')R>   Rc   Rd   N(   s   http:s   https:(   RP   R-   R   Rb   R'   R(   R)   t   joinR   R9   R   Rh   R   RZ   (   RY   R>   Rc   Rd   R   R9   t   msg(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRZ   Z  s    )*				c         C  s   |  j  s= |  j d  k	 r! |  j n |  j } d j |  } | S|  j } |  j d  k	 r | sv t j |  j  \ } } n  t |  j d   } | j	   } Wd  QXn	 |  j
 } t | t  r | } n t |  j d  j   } d j | |  } | S(   Nsk   <video src="{0}" controls>
      Your browser does not support the <code>video</code> element.
    </video>R   RE   sw   <video controls>
 <source src="data:{0};base64,{1}" type="{0}">
 Your browser does not support the video tag.
 </video>(   R   Rc   RP   Rd   RT   R9   t	   mimetypest
   guess_typeRo   Rq   R>   R-   R   t   base64_encodeRG   t   rstrip(   RY   Rc   t   outputR9   t   _Rx   t   videot	   b64_video(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s     	!			c         C  s   d  S(   N(    (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyRe     s    c         C  s   d  S(   N(    (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    c         C  s   d  S(   N(    (   RY   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR     s    N(	   R\   R^   RP   R+   RZ   R   Re   R   R   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR   X  s
   <	 		c         C  ss   d d l  m } | j   r5 | j   j j |   n: t d d d t j j	   t d d d t j
 j	   d S(   s   Clear the output of the current cell receiving output.

    Parameters
    ----------
    wait : bool [default: false]
        Wait to clear the output until new output is available to replace it.i(   R=   s   [2Kt   endR   N(   R?   R=   RM   R@   RA   R!   RN   t   syst   stdoutt   flusht   stderr(   t   waitR=   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR!     s    c          O  s   d d l  m } d d l m } i  } d d l m } | j   } | j | j  | j |   | j   } | | |  |  d S(   s  Select figure formats for the inline backend. Optionally pass quality for JPEG.

    For example, this enables PNG and JPEG output with a JPEG quality of 90%::

        In [1]: set_matplotlib_formats('png', 'jpeg', quality=90)

    To set this in your config files use the following::
    
        c.InlineBackend.figure_formats = {'png', 'jpeg'}
        c.InlineBackend.print_figure_kwargs.update({'quality' : 90})

    Parameters
    ----------
    *formats : strs
        One or more figure formats to enable: 'png', 'retina', 'jpeg', 'svg', 'pdf'.
    **kwargs :
        Keyword args will be relayed to ``figure.canvas.print_figure``.
    i(   R=   (   t   select_figure_formats(   t   InlineBackendN(	   R?   R=   t   IPython.core.pylabtoolsR   t   ipykernel.pylab.configR   R@   RL   t   print_figure_kwargs(   t   formatsRD   R=   R   t   kwR   t   cfgt   shell(    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR"     s    c         C  s)   d d l  m } | j   } |  | _ d S(   s  Set whether the inline backend closes all figures automatically or not.
    
    By default, the inline backend used in the IPython Notebook will close all
    matplotlib figures automatically after each cell is run. This means that
    plots in different cells won't interfere. Sometimes, you may want to make
    a plot in one cell and then refine it in later cells. This can be accomplished
    by::
    
        In [1]: set_matplotlib_close(False)
    
    To set this in your config files use the following::
    
        c.InlineBackend.close_figures = False
    
    Parameters
    ----------
    close : bool
        Should all matplotlib figures be automatically closed after each cell is
        run?
    i(   R   N(   R   R   R@   t   close_figures(   t   closeR   R   (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyR#     s    (F   R_   t
   __future__R    t   base64R   R   Rs   R   t   binasciiR   R   R   R   R'   R   R   R   t   IPython.utils.py3compatR   R   R   R   t   IPython.testing.skipdoctestR	   t   __all__R,   R0   R+   RP   R<   R$   RH   R
   R%   RW   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   t   _PNGR   R   R   R    R   R!   R"   RQ   R#   (    (    (    s3   lib/python2.7/site-packages/IPython/core/display.pyt   <module>   s|   "		5			2										P"> ;		i