a
    ø£BeŽ  ã                   @   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                   @   s   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   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/nbformat/v3/nbjson.pyr      s    

zBytesEncoder.defaultN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r	      s   r	   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
JSONReaderzA JSON notebook reader.c                 K   s0   t j|fi |¤Ž}| j|fi |¤Ž}t|ƒ}|S )zConvert a string to a notebook.)r   ÚloadsÚto_notebookr   )r   ÚsÚkwargsÚnbr   r   r   Úreads   s    zJSONReader.readsc                 K   s   t t|ƒƒS )zConvert a dict to a notebook.)r   r   )r   Údr   r   r   r   r   !   s    zJSONReader.to_notebookN)r   r   r   r   r   r   r   r   r   r   r      s   r   c                   @   s   e Zd ZdZdd„ ZdS )Ú
JSONWriterzA JSON notebook writer.c                 K   sX   t |d< d|d< d|d< d|d< t |¡}t|ƒ}| dd¡rFt|ƒ}tj|fi |¤ŽS )	zConvert a notebook to a string.Úclsr   ÚindentTÚ	sort_keys)ú,z: Ú
separatorsr   )r	   ÚcopyÚdeepcopyr   Úpopr   r   Údumps)r   r   r   r   r   r   Úwrites)   s    
zJSONWriter.writesN)r   r   r   r   r+   r   r   r   r   r!   &   s   r!   )r   r'   r   Znbbaser   Zrwbaser   r   r   r   r   r   r	   r   r!   Ú_readerZ_writerr   Úreadr   Úwriter+   r   r   r   r   Ú<module>   s   
