a
    ø£Be  ã                   @   s:  d 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„ Z.de#fdd„Zde#fd d!„Z/d&d"d#„Z0d'd$d%„Z1dS )(zŸDeprecated API for working with notebooks

- use nbformat for read/write/validate public API
- use nbformat.vX directly for Python API for composing notebooks
é    N)Ú
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Úvalidatez¶nbformat.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(   úS/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/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_formatY   s    ýr,   c                 K   s^   t }t}d}t || ¡}|durT| d¡ d¡}t|d ƒ}t|ƒdkrTt|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   a   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nbjsonr7   r(   r(   r)   r   q   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!   ©Únbr7   r(   r(   r)   r   {   s    ýr   c                 K   sL   t ƒ  t| fi |¤Ž\}}} |dv r<t| j| fi |¤Ž}ntd| ƒ‚|S )úDEPRECATED: use nbconvert)r   é   z#Unsupported PY nbformat version: %i)r,   r   r   Zto_notebook_pyr   )r6   r7   r8   r9   r?   r(   r(   r)   r   …   s    r   c                 K   s   t ƒ  td j| fi |¤ŽS )r@   rA   )r,   r   r    r>   r(   r(   r)   r    �   s    r    Ú
DEPRECATEDc              
   K   s¦   |dvrt ƒ  t| fi |¤Ž}t||ƒ}zFt ¡ �* tjdtd� t|dd� W d  ƒ n1 sb0    Y  W n2 ty  } zt	ƒ  
d|¡ W Y d}~n
d}~0 0 |S )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.
    >   rB   ÚjsonÚignore©ÚcategoryF©Zrepair_duplicate_cell_idsNúNotebook JSON is invalid: %s)r,   Úreader_readsr   r*   Úcatch_warningsÚfilterwarningsr=   r   r   r   Úerror)r6   ÚformatÚversionr7   r?   Úer(   r(   r)   r   ™   s    

.$r   c              
   K   s¨   |dvrt ƒ  t| |ƒ} zFt ¡ �* tjdtd� t| dd� W d  ƒ n1 sR0    Y  W n2 ty� } ztƒ  	d|¡ W Y d}~n
d}~0 0 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.
    >   rB   rC   rD   rE   FrG   NrH   )r,   r   r*   rJ   rK   r=   r   r   r   rL   r   r   )r?   rM   rN   r7   rO   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"   )ÚfprM   r7   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?   rP   rM   r7   r6   r(   r(   r)   r#   ç   s    

r#   )rB   )rB   )2r'   r0   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   rI   Ú	validatorr   r   r+   r=   Ú__all__r.   r/   r$   Zcurrent_nbformat_moduleÚ
ValueErrorr   r,   r   r   r   r   r    r!   r"   r#   r(   r(   r(   r)   Ú<module>   s:   
@ù


	
