B
    £'=[ú  ã               @   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
mZ ddl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Úrestore_bytesÚrejoin_linesÚsplit_linesÚstrip_transient)Ú	py3compatc               @   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 )NÚascii)Ú
isinstanceÚbytesÚdecodeÚjsonÚJSONEncoderÚdefault)ÚselfÚobj© r   ú1lib/python3.7/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d„ Zdd„ ZdS )Ú
JSONReaderc             K   s(   t j|f|Ž}| j|f|Ž}t|ƒ}|S )N)r   ÚloadsÚto_notebookr	   )r   ÚsÚkwargsÚnbr   r   r   Úreads   s    zJSONReader.readsc             K   s   t t|ƒƒS )N)r   r   )r   Údr   r   r   r   r   "   s    zJSONReader.to_notebookN)r   r   r   r!   r   r   r   r   r   r      s   r   c               @   s   e Zd Zdd„ ZdS )Ú
JSONWriterc             K   s\   t |d< d|d< d|d< d|d< t |¡}t|ƒ}| dd¡rFt|ƒ}t tj	|f|Žd	¡S )
NÚclsr   ÚindentTZ	sort_keys)ú,z: Z
separatorsr   zutf-8)
r   ÚcopyÚdeepcopyr	   Úpopr   r
   Zstr_to_unicoder   Údumps)r   r    r   r   r   r   Úwrites(   s    
zJSONWriter.writesN)r   r   r   r+   r   r   r   r   r#   &   s   r#   )r   r'   r   Znbbaser   Zrwbaser   r   r   r   r   r	   Zipython_genutilsr
   r   r   r   r#   Z_readerZ_writerr!   Úreadr   Úwriter+   r   r   r   r   Ú<module>   s    