a
    ø£BeÓ  ã                   @   s¤   d Z ddlZddlmZ dZdZddiZG dd„ deƒZd	d
„ Zdd„ Z	dd„ Z
d"dd„Zd#dd„Zd$dd„Zd%dd„Zd&dd„Zd'dd„Zd(dd„Zd)d d!„ZdS )*zõThe basic dict based notebook format.

The Python representation of a notebook is a nested structure of
dictionary subclasses that support attribute access.
The functions in this module are merely
helpers to build the structs in the right form.
é    N)ÚStructé   )r   r   znbformat.v3.schema.jsonc                   @   s   e Zd ZdZdS )ÚNotebookNodezA notebook node object.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r	   r	   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/nbformat/v3/nbbase.pyr      s   r   c                 C   sV   t | tƒr2tƒ }|  ¡ D ]\}}t|ƒ||< q|S t | ttfƒrNdd„ | D ƒS | S dS )z'Create notebook node(s) from an object.c                 S   s   g | ]}t |ƒ‘qS r	   )Ú	from_dict)Ú.0Úir	   r	   r
   Ú
<listcomp>(   ó    zfrom_dict.<locals>.<listcomp>N)Ú
isinstanceÚdictr   Úitemsr   ÚtupleÚlist)ÚdZnewdÚkÚvr	   r	   r
   r       s    
r   c                 C   s   t | tƒst‚| S )zY
    Used to be cast_unicode, add this temporarily to make sure no further breakage.
    )r   ÚstrÚAssertionError©Úobjr	   r	   r
   Ústr_passthrough-   s    
r   c                 C   s<   t | tƒr&tjdtdd� |  dd¡S t | tƒs4t‚| S dS )zCast an object as a string.zbA notebook got bytes instead of likely base64 encoded values.The content will likely be corrupted.r   )Ú
stacklevelÚasciiÚreplaceN)r   ÚbytesÚwarningsÚwarnÚUserWarningÚdecoder   r   r   r	   r	   r
   Úcast_str6   s    
ü
r%   c                 C   sh  t ƒ }t| ƒ|_|du ri }t|tƒs2d}t|ƒ‚| dv r@||_| dkrØ|durZt|ƒ|_|durlt	|ƒ|_
|dur~t	|ƒ|_|dur�t|ƒ|_|dur¢t|ƒ|_|dur´t|ƒ|_|durÆt|ƒ|_|durØt|ƒ|_| dkrò|	duròt|	ƒ|_| dk�rB|
du�rt|
ƒ|_|du�r$t|ƒ|_|du�rBdd„ t|ƒD ƒ|_| dk�rd|du �rZd	nt|ƒ|_|S )
zGCreate a new output, to go in the ``cell.outputs`` list of a code cell.Nzmetadata must be dict>   Zdisplay_dataÚpyoutZpyerrr&   c                 S   s   g | ]}t |ƒ‘qS r	   )r   )r   Úframer	   r	   r
   r   �   r   znew_output.<locals>.<listcomp>ÚstreamÚstdout)r   r   Úoutput_typer   r   Ú	TypeErrorÚmetadatar   Útextr%   ZpngZjpegÚhtmlÚsvgÚlatexÚjsonÚ
javascriptÚintÚprompt_numberÚenameÚevaluer   Ú	tracebackr(   )r*   Zoutput_textZ
output_pngÚoutput_htmlZ
output_svgZoutput_latexZoutput_jsonZoutput_javascriptZoutput_jpegr4   r5   r6   r7   r(   r,   ÚoutputÚmsgr	   r	   r
   Ú
new_outputH   sL    

















r;   ÚpythonFc                 C   s|   t ƒ }d|_|durt|ƒ|_| dur0t| ƒ|_|durBt|ƒ|_|du rRg |_n||_|durjt|ƒ|_	t |pri ƒ|_
|S )z,Create a new code cell with input and outputÚcodeN)r   Ú	cell_typer   ÚlanguageÚinputr3   r4   ÚoutputsÚboolÚ	collapsedr,   )r@   r4   rA   r?   rC   r,   Úcellr	   r	   r
   Únew_code_cell‰   s    	



rE   c                 C   s<   t ƒ }| dkrd} |dur$t|ƒ|_t |p,i ƒ|_| |_|S )zCreate a new text cell.Z	plaintextÚrawN)r   r   Úsourcer,   r>   )r>   rG   Úrenderedr,   rD   r	   r	   r
   Únew_text_cell¥   s    
rI   é   c                 C   s:   t ƒ }d|_| durt| ƒ|_t|ƒ|_t |p0i ƒ|_|S )z5Create a new section cell with a given integer level.ÚheadingN)r   r>   r   rG   r3   Úlevelr,   )rG   rL   rH   r,   rD   r	   r	   r
   Únew_heading_cell³   s    

rM   c                 C   s2   t ƒ }|du rg |_n
t|ƒ|_t |p(i ƒ|_|S )z5Create a worksheet by name with with a list of cells.N)r   Úcellsr   r,   )ÚnamerN   r,   Úwsr	   r	   r
   Únew_worksheet¾   s    
rQ   c                 C   s`   t ƒ }t|_t|_|du r"g |_n
t|ƒ|_|du r>tƒ |_n
t |ƒ|_| dur\t| ƒ|j_|S )z7Create a notebook by name, id and a list of worksheets.N)	r   ÚnbformatÚnbformat_minorÚ
worksheetsr   Únew_metadatar,   r   rO   )rO   r,   rT   Únbr	   r	   r
   Únew_notebookÉ   s    


rW   c                 C   sv   t ƒ }| durt| ƒ|_|dur*t|ƒ|_|dur<t|ƒ|_|durNt|ƒ|_|dur`t|ƒ|_|durrt|ƒ|_|S )zCreate a new metadata node.N)	r   r   rO   r   ÚauthorsÚcreatedÚmodifiedÚlicenseÚgistid)rO   rX   r[   rY   rZ   r\   r,   r	   r	   r
   rU   Û   s    





rU   c                 C   sR   t ƒ }| durt| ƒ|_|dur*t|ƒ|_|dur<t|ƒ|_|durNt|ƒ|_|S )zCreate a new author.N)r   r   rO   ÚemailÚaffiliationÚurl)rO   r]   r^   r_   Úauthorr	   r	   r
   Ú
new_authorï   s    



ra   )NNNNNNNNNNNNNN)NNNr<   FN)NNN)NrJ   NN)NNN)NNN)NNNNNN)NNNN)r   r!   Znbformat._structr   rR   rS   Znbformat_schemar   r   r   r%   r;   rE   rI   rM   rQ   rW   rU   ra   r	   r	   r	   r
   Ú<module>   sL   	              ñ
B      ú




 ÿ
