
    ^h                        S r SSKJr  SSKJr  SSKJr  SSKJrJ	r	J
r
Jr  SSKJrJr  SSKJr  / S	Qr\\	\
\S
.rSSKJr  SSKJr  SSKJrJr  SSKJr  SSKJr  SSKJrJr   " S S\ 5      r!\" S\"S5      r#SS jr$\#S4S jr%SS jr&\#S4S jr'g)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                      \ rS rSrSrg)r   5    N)__name__
__module____qualname____firstlineno____static_attributes__r$       K/home/james-whalen/.local/lib/python3.13/site-packages/nbformat/__init__.pyr   r   5   s    r*   r   r   zKValue to prevent nbformat to convert notebooks to most recent version.
    Nc                
   [         R                  " U 40 UD6nU[        La  [        XA5      n [	        U5        U$ ! [
         a>  n[        5       R                  SU5        [        U[        5      (       a  XRS'    SnAU$ SnAff = f)a  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$<
 I	  <91=.55:;%67I	<s   : 
B3A==Bc                <   U[         La  [        X5      n O[        R                  " U 5      u  p [	        U 5        [        U   R                  " U 40 UD6$ ! [
         a=  n[        5       R                  SU5        [        U[        5      (       a  XRS'    SnAN\SnAff = f)ag  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/   r0   r   writes_json)r5   versionr3   r4   _r6   s         r+   r   r   h   s    . j R!''+
<
 G((6v66	  <91=.55:;%67<s   A 
B3BBc                     U R                  5       n[        WX40 UD6$ ! [         aD    [        U SS9 n[        UR                  5       X40 UD6sSSS5        s $ ! , (       d  f        NW= ff = f)a  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   )fpr2   r3   r4   buffs         r+   r   r      sj    8Sggi
 jEfEE	  S"v&!:R6R '&&&Ss&    A-A
A-
A)	$A-)A-c                   [        XU40 UD6n[        U[        5      (       a  UR                  S5      n UR	                  U5        UR                  S5      (       d  UR	                  S5        gg! [         ao    [        U5      R                  SSS9 nUR	                  U5        UR                  S5      (       d  UR	                  S5        SSS5         g! , (       d  f        g= ff = f)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   rA   )r5   rB   r:   r3   r4   r1   rD   s          r+   r   r      s    , 	r4??A!UHHV
zz$HHTN   "X]]3]0AGGAJ::d## 1000s)   8A/ /#C(9CC(
C$	C($C()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>rW      s    #  $   / * 
				   1 , 8 0	J 	
 
#L "D !7H"FJ %t "r*   