o
    ¹i£  ã                   @   sœ   d Z ddlZddlZddlmZ ddlmZmZmZm	Z	m
Z
 G dd„ dejƒZG d	d
„ d
eƒZG dd„ deƒZeƒ Zeƒ ZejZejZejZejZejZdS )z(Read and write notebooks in JSON format.é    Né   )Ú	from_dicté   )ÚNotebookReaderÚNotebookWriterÚrejoin_linesÚsplit_linesÚstrip_transientc                   @   ó   e Zd ZdZdd„ ZdS )ÚBytesEncoderz@A JSON encoder that accepts b64 (and other *ascii*) bytestrings.c                 C   s"   t |tƒr
| d¡S tj | |¡S )z#Get the default value of an object.Úascii)Ú
isinstanceÚbytesÚdecodeÚjsonÚJSONEncoderÚdefault)ÚselfÚobj© r   úM/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/nbformat/v4/nbjson.pyr      s   

zBytesEncoder.defaultN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      ó    r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
JSONReaderzA JSON notebook reader.c                 K   s(   t j|fi |¤Ž}| j|fi |¤Ž}|S )z)Read a JSON string into a Notebook object)r   ÚloadsÚto_notebook)r   ÚsÚkwargsÚnbr   r   r   Úreads   s   zJSONReader.readsc                 K   s   t |ƒ}t|ƒ}t|ƒ}|S )z™Convert a disk-format notebook dict to in-memory NotebookNode

        handles multi-line values as strings, scrubbing of transient values, etc.
        )r   r   r	   )r   Údr    r!   r   r   r   r       s   zJSONReader.to_notebookN)r   r   r   r   r"   r   r   r   r   r   r      s    r   c                   @   r
   )Ú
JSONWriterzA JSON notebook writer.c                 K   sd   t |d< d|d< d|d< d|d< | dd	¡ t |¡}| d
d¡r%t|ƒ}t|ƒ}tj|fi |¤ŽS )z0Serialize a NotebookNode object as a JSON stringÚclsr   ÚindentTÚ	sort_keys)ú,z: Ú
separatorsÚensure_asciiFr   )	r   Ú
setdefaultÚcopyÚdeepcopyÚpopr   r	   r   Údumps)r   r!   r    r   r   r   Úwrites.   s   
zJSONWriter.writesN)r   r   r   r   r0   r   r   r   r   r$   +   r   r$   )r   r,   r   Únotebooknoder   Úrwbaser   r   r   r   r	   r   r   r   r$   Ú_readerÚ_writerr"   Úreadr   Úwriter0   r   r   r   r   Ú<module>   s    

