
    Mh
                    ^    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dS )z/API for reading notebooks of different versions    )annotationsN   )ValidationErrorc                      e Zd ZdZdS )NotJSONErrorz1An error raised when an object is not valid JSON.N)__name__
__module____qualname____doc__     O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbformat/reader.pyr   r      s        ;;;;r   r   c                    	 t          j        | fi |}nG# t          $ r:}d| }t          |          dk    r|dd         dz   }t	          |          |d}~ww xY w|S )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      s    +*Q))&)) + + +?!??w<<"crclU*G7##*+ Ns    
A5AAc                b    |                      dd          }|                      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#       s5     FF:q!!EFF#Q''E5>r   c                    ddl m}m} t          | fi |}t	          |          \  }}||v rE	 ||                             ||          S # t          $ r}d| }t          |          dd}~ww xY w |d|z            )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I 	1 	1 	1PQPPC!#&&D0	1 m=EFFFs   A
 

A.A))A.c                @    t          |                                 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      s    5 5 # " " " " "  & & & & & &< < < < <: < < <
 
 
   "#G #G #GL& & & & &r   