ó
‹'=[c           @   s¨  d  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 d d
 l	 m Z d d l m Z d d d d d d d d d d d d d d d d g Z i e
 d 6e d 6e d 6e d 6Z d d l m Z m Z d d  l m Z d d! l	 m Z d d" l m Z m Z d d# l m Z m Z d e f d$ „  ƒ  YZ  e d e! d% ƒ Z" d& „  Z# e" d' „ Z$ d( „  Z% e" d) „ Z& d S(*   sn   The Jupyter notebook format

Use this module to read or write notebook files as particular nbformat versions.
iÿÿÿÿN(   t	   py3compat(   t
   get_loggeri   (   t   version_infot   __version__(   t   v1(   t   v2(   t   v3(   t   v4(   t   Sentinelt   versionst   validatet   ValidationErrort   convertt	   from_dictt   NotebookNodet   current_nbformatt   current_nbformat_minort   NBFormatErrort
   NO_CONVERTt   readst   readt   writest   writeR   R   i   i   i   (   R
   R   (   R   (   t   reader(   R   R   (   t   nbformatt   nbformat_minorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s0   lib/python2.7/site-packages/nbformat/__init__.pyR   +   s   sK   Value to prevent nbformat to convert notebooks to most recent version.
    c         K   sk   t  j |  |  } | t k	 r0 t | | ƒ } n  y t | ƒ Wn& t k
 rf } t ƒ  j d | ƒ n X| S(   s  Read a notebook from a string and return the NotebookNode object as the given version.
    
    The string can contain a notebook of any version.
    The notebook will be returned `as_version`, converting, if necessary.

    Notebook format errors will be logged.

    Parameters
    ----------
    s : unicode
        The raw unicode string to read the notebook from.
    as_version : int
        The version of the notebook format to return.
        The notebook will be converted, if necessary.
        Pass nbformat.NO_CONVERT to prevent conversion.

    Returns
    -------
    nb : NotebookNode
        The notebook that was read.
    s   Notebook JSON is invalid: %s(   R   R   R   R   R
   R   R   t   error(   t   st
   as_versiont   kwargst   nbt   e(    (    s0   lib/python2.7/site-packages/nbformat/__init__.pyR   4   s    c         K   s~   | t  k	 r t |  | ƒ }  n t j |  ƒ \ } } y t |  ƒ Wn& t k
 ri } t ƒ  j d | ƒ n Xt | j	 |  |  S(   só  Write a notebook to a string in a given format in the given nbformat version.

    Any notebook format errors will be logged.

    Parameters
    ----------
    nb : NotebookNode
        The notebook to write.
    version : int, optional
        The nbformat version to write.
        If unspecified, or specified as nbformat.NO_CONVERT,
        the notebook's own version will be used and no conversion performed.

    Returns
    -------
    s : unicode
        The notebook as a JSON string.
    s   Notebook JSON is invalid: %s(
   R   R   R   t   get_versionR
   R   R   R   R	   t   writes_json(   R    t   versionR   t   _R!   (    (    s0   lib/python2.7/site-packages/nbformat/__init__.pyR   T   s    c         K   s_   t  |  t j t f ƒ rI t j |  d d ƒ } t | | |  SWd QXn  t |  j ƒ  | |  S(   sµ  Read a notebook from a file as a NotebookNode of the given version.

    The string can contain a notebook of any version.
    The notebook will be returned `as_version`, converting, if necessary.

    Notebook format errors will be logged.

    Parameters
    ----------
    fp : file or str
        A file-like object with a read method that returns unicode (use
        ``io.open()`` in Python 2), or a path to a file.
    as_version: int
        The version of the notebook format to return.
        The notebook will be converted, if necessary.
        Pass nbformat.NO_CONVERT to prevent conversion.

    Returns
    -------
    nb : NotebookNode
        The notebook that was read.
    t   encodings   utf-8N(   t
   isinstanceR    t   unicode_typet   bytest   iot   openR   R   (   t   fpR   R   t   f(    (    s0   lib/python2.7/site-packages/nbformat/__init__.pyR   r   s    c      
   K   sµ   t  | t j t f ƒ rR t j | d d d ƒ } t |  | d | | SWd QXn  t |  | |  } t  | t ƒ r… | j d ƒ } n  | j | ƒ | j	 d ƒ s± | j d ƒ n  d S(   sR  Write a notebook to a file in a given nbformat version.
    
    The file-like object must accept unicode input.
    
    Parameters
    ----------
    nb : NotebookNode
        The notebook to write.
    fp : file or str
        Any file-like object with a write method that accepts unicode, or
        a path to write a file.
    version : int, optional
        The nbformat version to write.
        If nb is not this version, it will be converted.
        If unspecified, or specified as nbformat.NO_CONVERT,
        the notebook's own version will be used and no conversion performed.
    t   wR&   s   utf-8R$   Nt   utf8u   
(
   R'   R    R(   R)   R*   R+   R   R   t   decodet   endswith(   R    R,   R$   R   R-   R   (    (    s0   lib/python2.7/site-packages/nbformat/__init__.pyR      s    ('   t   __doc__R*   t   ipython_genutilsR    t   traitlets.logR   t   _versionR   R   t    R   R   R   R   t   sentinelR   t   __all__R	   t	   validatorR
   R   t	   converterR   R   t   notebooknodeR   R   R   R   R   R   t
   ValueErrorR   R   R   R   R   R   R   (    (    (    s0   lib/python2.7/site-packages/nbformat/__init__.pyt   <module>   s<   	
			 	