B
    £'=[  ã               @   s@   d Z ddlZG dd„ deƒZdd„ Zdd„ Zd	d
„ Zdd„ ZdS )z/API for reading notebooks of different versionsé    Nc               @   s   e Zd ZdS )ÚNotJSONErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú.lib/python3.7/site-packages/nbformat/reader.pyr      s   r   c             K   sD   yt j| f|Ž}W n, tk
r>   td|  dd… d ƒ‚Y nX |S )z Parse a JSON string into a dict.z'Notebook does not appear to be JSON: %rNéM   z...)ÚjsonÚloadsÚ
ValueErrorr   )ÚsÚkwargsÚnb_dictr   r   r   Ú
parse_json   s
    r   c             C   s    |   dd¡}|   dd¡}||fS )záGet the version of a notebook.

    Parameters
    ----------
    nb : dict
        NotebookNode or dict containing notebook data.

    Returns
    -------
    Tuple containing major (int) and minor (int) version numbers
    Znbformaté   Znbformat_minorr   )Úget)ZnbÚmajorÚminorr   r   r   Úget_version   s    r   c             K   sR   ddl m}m} t| f|Ž}t|ƒ\}}||krB|| j||dS |d| ƒ‚dS )ar  Read a notebook from a json string and return the 
    NotebookNode object.

    This function properly reads notebooks of any version.  No version 
    conversion is performed.

    Parameters
    ----------
    s : unicode
        The raw unicode string to read the notebook from.

    Returns
    -------
    nb : NotebookNode
        The notebook that was read.
    r   )ÚversionsÚNBFormatError)r   zUnsupported nbformat version %sN)Ú r   r   r   r   Zto_notebook_json)r   r   r   r   r   r   r   r   r   r   Úreads'   s    r   c             K   s   t |  ¡ f|ŽS )a[  Read a notebook from a file and return the NotebookNode object.

    This function properly reads notebooks of any version.  No version 
    conversion is performed.

    Parameters
    ----------
    fp : file
        Any file-like object with a read method.

    Returns
    -------
    nb : NotebookNode
        The notebook that was read.
    )r   Úread)Úfpr   r   r   r   r   B   s    r   )Ú__doc__r	   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   