o
    tf                     @  sF  d Z ddlmZ ddlZddlZddlmZ ddlmZ	 ddl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlm Z m!Z! ej"de#dd g dZ$eZ%eZ&e	j'Z(G dd de)Z*dd Z+dd Z,dd Z-dd Z.dd Z/dd Z0de%fdd Zde%fd!d"Z1d'd#d$Z2d'd%d&Z3dS )(zDeprecated API for working with notebooks

- use nbformat for read/write/validate public API
- use nbformat.vX directly for Python API for composing notebooks
    )annotationsN)
get_logger)v3)NotebookNodenbformatnbformat_minornbformat_schema
new_authornew_code_cellnew_heading_cellnew_metadatanew_notebook
new_outputnew_text_cellnew_worksheetparse_filenameto_notebook_json   )versions)convert)reads)ValidationErrorvalidateznbformat.current is deprecated since before nbformat 3.0

- use nbformat for read/write/validate public API
- use nbformat.vX directly to composing notebooks of a particular version
   
stacklevel)r   r
   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   NBFormatErrorparse_py
reads_jsonwrites_jsonreads_py	writes_pyr   writesreadwritec                   @  s   e Zd ZdZdS )r   z&An error raised for an nbformat error.N)__name__
__module____qualname____doc__ r)   r)   Y/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/nbformat/current.pyr   S   s    r   c                   C  s   t jddd d S )NzwNon-JSON file support in nbformat is deprecated since nbformat 1.0.
    Use nbconvert to create files of other formats.r   r   )warningswarnr)   r)   r)   r*   _warn_formatW   s   
r-   c                 K  s^   t }t}d}t|| }|dur*|dd}t|d }t|dkr*t|d }||| fS )z/Parse a string into a (nbformat, string) tuple.z0# <nbformat>(?P<nbformat>\d+[\.\d+]*)</nbformat>Nr   .r   r   )current_nbformatcurrent_nbformat_minorresearchgroupsplitintlen)skwargsnbfnbmpatternmdigitsr)   r)   r*   r   _   s   
r   c                 K  s   t jdtdd t| S )zDEPRECATED, use readsz6reads_json is deprecated since nbformat 3.0, use readsr   r   )r+   r,   DeprecationWarningr   )Znbjsonr8   r)   r)   r*   r   o   s   r   c                 K  s    t jdtdd t| fi |S )zDEPRECATED, use writesz8writes_json is deprecated since nbformat 3.0, use writesr   r   )r+   r,   r>   r"   nbr8   r)   r)   r*   r   y   s   r   c                 K  sJ   t   t| fi |\}}} |dv rt| j| fi |}|S td| )DEPRECATED: use nbconvert)r      z#Unsupported PY nbformat version: %i)r-   r   r   Zto_notebook_pyr   )r7   r8   r9   r:   r@   r)   r)   r*   r       s   r    c                 K  s   t   td j| fi |S )rA   rB   )r-   r   r!   r?   r)   r)   r*   r!      s   r!   
DEPRECATEDc              
   K  s   |dvrt   t| fi |}t||}z&t  tjdtd t|dd W d   W |S 1 s3w   Y  W |S  tyT } zt	 
d| W Y d}~|S d}~ww )a  Read a notebook from a string and return the NotebookNode object.

    This function properly handles notebooks of any version. The notebook
    returned will always be in the current version's format.

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

    Returns
    -------
    nb : NotebookNode
        The notebook that was read.
    >   jsonrC   ignorecategoryFZrepair_duplicate_cell_idsNNotebook JSON is invalid: %s)r-   reader_readsr   r+   catch_warningsfilterwarningsr>   r   r   r   error)r7   formatversionr8   r@   er)   r)   r*   r      s"   

r   c              
   K  s   |dvrt   t| |} z#t  tjdtd t| dd W d   n1 s)w   Y  W n tyH } zt 	d| W Y d}~nd}~ww t
| j| fi |S )a  Write a notebook to a string in a given format in the current nbformat version.

    This function always writes the notebook in the current nbformat version.

    Parameters
    ----------
    nb : NotebookNode
        The notebook to write.
    version : int
        The nbformat version to write.
        Used for downgrading notebooks.

    Returns
    -------
    s : unicode
        The notebook string.
    >   rD   rC   rE   rF   FrH   NrI   )r-   r   r+   rK   rL   r>   r   r   r   rM   r   r   )r@   rN   rO   r8   rP   r)   r)   r*   r"      s   

r"   c                 K  s   t |  fi |S )a}  Read a notebook from a file and return the NotebookNode object.

    This function properly handles notebooks of any version. The notebook
    returned will always be in the current version's format.

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

    Returns
    -------
    nb : NotebookNode
        The notebook that was read.
    )r   r#   )fprN   r8   r)   r)   r*   r#      s   r#   c                 K  s.   t | fi |}t|tr|d}||S )a5  Write a notebook to a file in a given format in the current nbformat version.

    This function always writes the notebook in the current nbformat version.

    Parameters
    ----------
    nb : NotebookNode
        The notebook to write.
    fp : file
        Any file-like object with a write method.
    utf8)r"   
isinstancebytesdecoder$   )r@   rQ   rN   r8   r7   r)   r)   r*   r$      s   


r$   )rC   )4r(   
__future__r   r1   r+   Ztraitlets.logr   r   r   Z	_v_latestZnbformat.v3r   r   r   r	   r
   r   r   r   r   r   r   r   r    r   	converterr   readerr   rJ   	validatorr   r   r,   r>   __all__r/   r0   r%   Zcurrent_nbformat_module
ValueErrorr   r-   r   r   r   r    r!   r"   r#   r$   r)   r)   r)   r*   <module>   s>    @


	
