
    f
                    V    d Z ddlmZ ddlZddlmZ  G d de      Zd Zd	 Z	d
 Z
d Zy)z/API for reading notebooks of different versions    )annotationsN   )ValidationErrorc                      e Zd ZdZy)NotJSONErrorz1An error raised when an object is not valid JSON.N)__name__
__module____qualname____doc__     J/var/www/cvtools/html/venv/lib/python3.12/site-packages/nbformat/reader.pyr   r      s    ;r   r   c                    	 t        j                  | fi |}|S # t        $ r,}d| }t        |      dkD  r|dd dz   }t	        |      |d}~ww xY w)z Parse a JSON string into a dict.z%Notebook does not appear to be JSON: P   NM   z...)jsonloads
ValueErrorlenr   )skwargsnb_dictemessages        r   
parse_jsonr      sh    +**Q)&) N  +9!?w<"crlU*G7#*+s    	A'A

Ac                R    | j                  dd      }| j                  dd      }||fS )zGet the version of a notebook.

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

    Returns
    -------
    Tuple containing major (int) and minor (int) version numbers
    nbformatr   nbformat_minorr   )get)nbmajorminors      r   get_versionr#       s/     FF:q!EFF#Q'E5>r   c                    ddl m}m} t        | fi |}t	        |      \  }}||v r	 ||   j                  ||      S  |d|z        # t        $ r}d| }t        |      dd}~ww xY w)aQ  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 | bytes
        The raw string or bytes object to read the notebook from.

    Returns
    -------
    nb : NotebookNode
        The notebook that was read.

    Raises
    ------
    ValidationError
        Notebook JSON for a given version is missing an expected key and cannot be read.
    NBFormatError
        Specified major version is invalid or unsupported.
    r   )NBFormatErrorversions)r"   z8The notebook is invalid and is missing an expected key: NzUnsupported nbformat version %s) r%   r&   r   r#   to_notebook_jsonAttributeErrorr   )	r   r   r%   r&   r   r!   r"   r   msgs	            r   readsr+   1   s    0 *%f%G )NUE	1E?33G53II
 =EFF	  	1LQCPC!#&D0	1s   A	 		A(A##A(c                6    t        | j                         fi |S )aZ  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   s     r   r-   r-   W   s      %f%%r   )r   
__future__r   r   	validatorr   r   r   r   r#   r+   r-   r   r   r   <module>r1      s5    5 #  &<: <
 "#GL&r   