
    Mh                    &   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZ ddlmZmZ ddlmZ g d	Zee	e
ed
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mZ  G d de           Z! ede"d          Z#ddZ$e#dfdZ%ddZ&e#dfdZ'dS )znThe Jupyter notebook format

Use this module to read or write notebook files as particular nbformat versions.
    )annotations)Path)
get_logger   )v1v2v3v4)__version__version_info)Sentinel)versionsvalidateValidationErrorconvert	from_dictNotebookNodecurrent_nbformatcurrent_nbformat_minorNBFormatError
NO_CONVERTreadsreadwriteswriter   r   r   )r            )reader)r   )r   r   )nbformat)nbformat_minor)r   r   c                      e Zd ZdS )r   N)__name__
__module____qualname__     Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbformat/__init__.pyr   r   5   s        Dr'   r   r   zKValue to prevent nbformat to convert notebooks to most recent version.
    Nc                $   t          j        | fi |}|t          urt          ||          }	 t	          |           nS# t
          $ rF}t                                          d|           t          |t                    r||d<   Y d}~nd}~ww xY w|S )a9  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.
    capture_validation_error : dict, optional
        If provided, a key of "ValidationError" with a
        value of the ValidationError instance will be added
        to the dictionary.

    Returns
    -------
    nb : NotebookNode
        The notebook that was read.
    Notebook JSON is invalid: %sr   N)
r   r   r   r   r   r   r   error
isinstancedict)s
as_versioncapture_validation_errorkwargsnbes         r(   r   r   B   s    4 
a	"	"6	"	"B##R$$< < < <91===.55 	<:;$%67< Is   = 
B<BBc                \   |t           urt          | |          } nt          j        |           \  }}	 t	          |            nS# t
          $ rF}t                                          d|           t          |t                    r||d<   Y d}~nd}~ww xY wt          |         j        | fi |S )a  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.
    capture_validation_error : dict, optional
        If provided, a key of "ValidationError" with a
        value of the ValidationError instance will be added
        to the dictionary.

    Returns
    -------
    s : unicode
        The notebook as a JSON string.
    r*   r   N)r   r   r   get_versionr   r   r   r+   r,   r-   r   writes_json)r2   versionr0   r1   _r3   s         r(   r   r   h   s    . j  R!!'++
< < < <91===.55 	<:;$%67< G(66v666s   A 
B<BBc                   	 |                                  }n\# t          $ rO t          | d          5 }t          |                                 ||fi |cddd           cY S # 1 swxY w Y   Y nw xY wt          |||fi |S )ar  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.
    capture_validation_error : dict, optional
        If provided, a key of "ValidationError" with a
        value of the ValidationError instance will be added
        to the dictionary.

    Returns
    -------
    nb : NotebookNode
        The notebook that was read.
    utf8encodingN)r   AttributeErroropenr   )fpr/   r0   r1   buffs         r(   r   r      s   8Sggii S S S"v&&& 	S!:/GRR6RR	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	SS j":EEfEEEs2    A0!A"A0"A&	&A0)A&	*A0/A0c                   t          | ||fi |}t          |t                    r|                    d          }	 |                    |           |                    d          s|                    d           dS dS # t          $ r t          |                              dd          5 }|                    |           |                    d          s|                    d           ddd           Y dS # 1 swxY w Y   Y dS w xY w)a  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.
    capture_validation_error : dict, optional
        If provided, a key of "ValidationError" with a
        value of the ValidationError instance will be added
        to the dictionary.
    r:   
wr;   N)	r   r,   bytesdecoder   endswithr=   r   r>   )r2   r?   r7   r0   r1   r.   rA   s          r(   r   r      sZ   , 	r74????A!U HHV
zz$ 	HHTNNNNN	 	   "XX]]3]00 	AGGAJJJ::d## 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s6   ?A> >.D	,A C:,D	:C>	>D	C>	D	D	)N)(__doc__
__future__r   pathlibr   traitlets.logr    r   r   r	   r
   _versionr   r   sentinelr   __all__r   r   	converterr   notebooknoder   r   r    r   r!   r   	validatorr   r   
ValueErrorr   r#   r   r   r   r   r   r&   r'   r(   <module>rT      s    # " " " " "       $ $ $ $ $ $             / / / / / / / /        * 
				              1 1 1 1 1 1 1 1 , , , , , , 8 8 8 8 8 8 0 0 0 0 0 0 0 0	 	 	 	 	J 	 	 	
 X 
# # # #L "D !7 !7 !7 !7H"F "F "F "FJ %t " " " " " "r'   