
    Ud                         d Z ddlZddlmZ dZdZddiZ G d de      Zd	 Zd
 Z	d Z
	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZddZddZddZ	 ddZddZy)zThe 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                       e Zd ZdZy)NotebookNodezA notebook node object.N)__name__
__module____qualname____doc__     4/usr/lib/python3/dist-packages/nbformat/v3/nbbase.pyr   r      s    !r   r   c                     t        | t              r2t               }| j                         D ]  \  }}t	        |      ||<    |S t        | t
        t        f      r| D cg c]  }t	        |       c}S | S c c}w )z'Create notebook node(s) from an object.)
isinstancedictr   items	from_dicttuplelist)dnewdkvis        r   r   r       sk    !T~GGI 	#DAqlDG	#	At}	%&'(	!(( )s   A4c                 2    t        | t              st        | S )zY
    Used to be cast_unicode, add this temporarily to make sure no further breakage.
    )r   strAssertionErrorobjs    r   str_passthroughr   -   s     c3Jr   c                     t        | t              r.t        j                  dt        d       | j                  dd      S t        | t              st        | 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replace)r   byteswarningswarnUserWarningdecoder   r   r   s    r   cast_strr)   6   sM    #u 	4		
 zz'9--#s#  
r   c                    t               }t        |       |_        |i }t        |t              sd}t        |      | dv r||_        | dk7  r|t        |      |_        |t        |      |_
        |t        |      |_        |t        |      |_        |t        |      |_        |t        |      |_        |t        |      |_        |t        |      |_        | dk(  r|	t#        |	      |_        | dk(  rM|
t        |
      |_        |t        |      |_        |'t+        |      D cg c]  }t        |       c}|_        | dk(  r|dn
t        |      |_        |S c c}w )zGCreate a new output, to go in the ``cell.outputs`` list of a code cell.zmetadata must be dict>   pyoutdisplay_datapyerrr+   streamstdout)r   r   output_typer   r   	TypeErrormetadatar   textr)   pngjpeghtmlsvglatexjson
javascriptintprompt_numberenameevaluer   	tracebackr.   )r0   output_text
output_pngoutput_html
output_svgoutput_latexoutput_jsonoutput_javascriptoutput_jpegr<   r=   r>   r?   r.   r2   outputmsgframes                     r   
new_outputrK   H   ss   $ ^F[)Fh%%n//"g")+6FK!!*-FJ"";/FK")+6FK!(4FJ#*<8FL")+6FK( /0A BFg-";"=1g*51FL+F3FM DHOT5 6TFh$*N8OM  Us   +E c                    t               }d|_        |t        |      |_        | t        |       |_        |t        |      |_        |g |_        n||_        |t        |      |_	        t        |xs i       |_
        |S )z,Create a new code cell with input and outputcode)r   	cell_typer   languageinputr;   r<   outputsbool	collapsedr2   )rP   r<   rQ   rO   rS   r2   cells          r   new_code_cellrU      s     >DDN'1$U+
  /i R0DMKr   c                     t               }| dk(  rd} |t        |      |_        t        |xs i       |_        | |_        |S )zCreate a new text cell.	plaintextraw)r   r   sourcer2   rN   )rN   rY   renderedr2   rT   s        r   new_text_cellr[      sF    >D K	%f- R0DMDNKr   c                     t               }d|_        | t        |       |_        t	        |      |_        t        |xs i       |_        |S )z5Create a new section cell with a given integer level.heading)r   rN   r   rY   r;   levelr2   )rY   r^   rZ   r2   rT   s        r   new_heading_cellr_      sB    >DDN%f-UDJ R0DMKr   c                 v    t               }|g |_        nt        |      |_        t        |xs i       |_        |S )z5Create a worksheet by name with with a list of cells.)r   cellsr   r2   )namera   r2   wss       r   new_worksheetrd      s5    	B};x~2.BKIr   c                     t               }t        |_        t        |_        |g |_        nt	        |      |_        |t               |_        nt        |      |_        | t        |       |j                  _        |S )z7Create a notebook by name, id and a list of worksheets.)	r   nbformatnbformat_minor
worksheetsr   new_metadatar2   r   rb   )rb   r2   rh   nbs       r   new_notebookrk      sh    	BBK&BZ("n"8,*40Ir   c                     t               }| t        |       |_        |t        |      |_        |t        |      |_        |t        |      |_        |t        |      |_        |t        |      |_        |S )zCreate a new metadata node.)	r   r   rb   r   authorscreatedmodifiedlicensegistid)rb   rm   rp   rn   ro   rq   r2   s          r   ri   ri      s     ~H'-=*73+H5*73)&1Or   c                     t               }| t        |       |_        |t        |      |_        |t        |      |_        |t        |      |_        |S )zCreate a new author.)r   r   rb   emailaffiliationurl)rb   rs   rt   ru   authors        r   
new_authorrw      sV    ^F%d+&u-,[9
$S)
Mr   )NNNNNNNNNNNNNN)NNNpythonFN)NNN)N   NN)NNNNNN)NNNN)r
   r%   nbformat._structr   rf   rg   nbformat_schemar   r   r   r)   rK   rU   r[   r_   rd   rk   ri   rw   r   r   r   <module>r|      s     # 45	6 	
( 
>D 8& PT(r   