
    Ud                     X   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       g dZ"eZ#e
Z$ejJ                  Z& G d de'      Z(d Z)d Z*d Z+d Z,d Z-d Z.de#fdZde#fdZ/ddZ0ddZ1y)zDeprecated 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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__     2/usr/lib/python3/dist-packages/nbformat/current.pyr   r   S   s    0r+   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_formatr0   Y   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   a   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.   r/   DeprecationWarningr   )nbjsonr<   s     r,   r   r   q   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.   r/   rC   r"   nbr<   s     r,   r   r   {   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)r0   r   r   to_notebook_pyr   )r;   r<   r=   r>   rG   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 )rI   rJ   )r0   r   r!   rF   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.
       jsonrM   ignorecategoryFrepair_duplicate_cell_idsNNotebook JSON is invalid: %s)r0   reader_readsr   r.   catch_warningsfilterwarningsrC   r   r   r   error)r;   formatversionr<   rG   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.
    rO   rQ   rR   FrT   NrV   )r0   r   r.   rX   rY   rC   r   r   r   rZ   r   r   )rG   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$   )rG   r`   r[   r<   r;   s        r,   r$   r$      s9     	rVA!UHHV88A;r+   )rM   )2r)   r5   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   r/   rC   __all__r3   r4   r&   current_nbformat_module
ValueErrorr   r0   r   r   r   r    r!   r"   r#   r$   r*   r+   r,   <module>rp      s    
  $ $   "   ) 0 
 :  ' #,, 	J 	  / !*: : #,< 7<&&r+   