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 )zDRead and write notebooks in JSON format.

Authors:

* Brian Granger
é    Né   )Ú	from_dict)ÚNotebookReaderÚNotebookWriterÚrejoin_linesÚrestore_bytesÚsplit_linesc                   @   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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/v2/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   s(   t j|fi |¤Ž}| j|fi |¤Ž}|S ©zConvert a string to a notebook.)r   ÚloadsÚto_notebook)r   ÚsÚkwargsÚnbr   r   r   Úreads+   s    zJSONReader.readsc                 K   s   t tt|ƒƒƒS r   )r   r   r   )r   Údr   r   r   r   r   1   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   sD   t |d< d|d< d|d< | dd¡r2tt |¡ƒ}tj|fi |¤ŽS )z&Convert a notebook object to a string.Úclsr   ÚindentTÚ	sort_keysr   )r	   Úpopr   ÚcopyÚdeepcopyr   Údumps)r   r   r   r   r   r   Úwrites9   s    zJSONWriter.writesN)r   r   r   r   r*   r   r   r   r   r"   6   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   
