
    f                    d   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jD                  de#d       g dZ$eZ%eZ&e	jN                  Z( G d de)      Z*d Z+d Z,d Z-d Z.d Z/d Z0de%fdZde%fdZ1ddZ2ddZ3y)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                      e Zd ZdZy)r   z&An error raised for an nbformat error.N)__name__
__module____qualname____doc__     K/var/www/cvtools/html/venv/lib/python3.12/site-packages/nbformat/current.pyr   r   S   s    0r,   r   c                 2    t        j                  dd       y )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-   _warn_formatr1   W   s    MM	7r,   c                    t         }t        }d}t        j                  ||       }|J|j	                  d      j                  d      }t        |d         }t        |      dkD  rt        |d         }||| fS )z/Parse a string into a (nbformat, string) tuple.z0# <nbformat>(?P<nbformat>\d+[\.\d+]*)</nbformat>r   .r   r   )current_nbformatcurrent_nbformat_minorresearchgroupsplitintlen)skwargsnbfnbmpatternmdigitss          r-   r   r   _   sp    
C
 CAG
		'1A}$**3/&)nv;?fQi.CQ;r,   c                P    t        j                  dt        d       t        |       S )zDEPRECATED, use readsz6reads_json is deprecated since nbformat 3.0, use readsr   r   )r/   r0   DeprecationWarningr   )nbjsonr=   s     r-   r   r   o   s#    MM@
 =r,   c                R    t        j                  dt        d       t        | fi |S )zDEPRECATED, use writesz8writes_json is deprecated since nbformat 3.0, use writesr   r   )r/   r0   rD   r#   nbr=   s     r-   r    r    y   s)    MMB
 "r,   c                    t                t        | fi |\  }}} |dv rt        |   j                  | fi |}|S t	        d|z        )DEPRECATED: use nbconvert)r      z#Unsupported PY nbformat version: %i)r1   r   r   to_notebook_pyr   )r<   r=   r>   r?   rH   s        r-   r!   r!      sV    N1''KCa
f}c]))!6v6 I ACGHHr,   c                H    t                t        d   j                  | fi |S )rJ   rK   )r1   r   r"   rG   s     r-   r"   r"      s!    NA;  .v..r,   
DEPRECATEDc                Z   |dvr
t                t        | fi |}t        ||      }	 t        j                         5  t        j
                  dt               t        |d       ddd       |S # 1 sw Y   |S xY w# t        $ r%}t               j                  d|       Y d}~|S d}~ww xY 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.
    >   jsonrN   ignorecategoryFrepair_duplicate_cell_idsNNotebook JSON is invalid: %s)r1   reader_readsr   r/   catch_warningsfilterwarningsrD   r   r   r   error)r<   formatversionr=   rH   es         r-   r   r      s      ++	a	"6	"B	W	B>$$& 	:##H7IJR59	:
 I	:
 I  >91==I>s4   A< )A/%A< /A94A< 9A< <	B*B%%B*c                l   |dvr
t                t        | |      } 	 t        j                         5  t        j                  dt
               t        | d       ddd       t        |   j                  | fi |S # 1 sw Y   "xY w# t        $ r$}t               j                  d|       Y d}~Md}~ww xY w)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.
    >   rP   rN   rQ   rR   FrT   NrV   )r1   r   r/   rX   rY   rD   r   r   r   rZ   r   r    )rH   r[   r\   r=   r]   s        r-   r#   r#      s    $ ++	W	B>$$& 	:##H7IJR59	:
 G((6v66	: 	:  >91==>s.   B )A:B :B?B 	B3B..B3c                6    t        | j                         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$   )fpr[   r=   s      r-   r$   r$      s      %f%%r,   c                ~    t        | fi |}t        |t              r|j                  d      }|j	                  |      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%   )rH   r`   r[   r=   r<   s        r-   r%   r%      s9     	rVA!UHHV88A;r,   )rN   )4r*   
__future__r   r6   r/   traitlets.logr   r   r   	_v_latestnbformat.v3r   r   r	   r
   r   r   r   r   r   r   r   r   r    r   	converterr   readerr   rW   	validatorr   r   r0   rD   __all__r4   r5   r'   current_nbformat_module
ValueErrorr   r1   r   r   r    r!   r"   r#   r$   r%   r+   r,   r-   <module>rq      s    # 	  $ $   "   ) 0 
 :  ' #,, 1J 1  / !*: : #,< 7<&&r,   