
    e                         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dS )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dS )NotebookNodezA notebook node object.N)__name__
__module____qualname____doc__     2lib/python3.11/site-packages/nbformat/v3/nbbase.pyr   r      s        !!Dr   r   c                     t          | t                    r<t                      }|                                 D ]\  }}t	          |          ||<   |S t          | t
          t          f          rd | D             S | S )z'Create notebook node(s) from an object.c                 ,    g | ]}t          |          S r   )	from_dict).0is     r   
<listcomp>zfrom_dict.<locals>.<listcomp>(   s    (((	!(((r   )
isinstancedictr   itemsr   tuplelist)dnewdkvs       r   r   r       s}    !T ~~GGII 	# 	#DAqllDGG	At}	%	% ((a((((r   c                 >    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                    r2t          j        dt          d           |                     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                 8   t                      }t          |           |_        |i }t          |t                    sd}t          |          | dv r||_        | dk    r|t          |          |_        |t          |          |_
        |t          |          |_        |t          |          |_        |t          |          |_        |t          |          |_        |t          |          |_        |t          |          |_        | dk    r|	t#          |	          |_        | dk    rL|
t          |
          |_        |t          |          |_        |d t+          |          D             |_        | dk    r|dnt          |          |_        |S )	zGCreate a new output, to go in the ``cell.outputs`` list of a code cell.Nzmetadata must be dict>   pyoutdisplay_datapyerrr.   c                 ,    g | ]}t          |          S r   )r"   )r   frames     r   r   znew_output.<locals>.<listcomp>   s     TTT5 6 6TTTr   streamstdout)r   r   output_typer   r   	TypeErrormetadatar"   textr,   pngjpeghtmlsvglatexjson
javascriptintprompt_numberenameevaluer   	tracebackr3   )r5   output_text
output_pngoutput_html
output_svgoutput_latexoutput_jsonoutput_javascriptoutput_jpegrA   rB   rC   rD   r3   r7   outputmsgs                    r   
new_outputrO   H   s   $ ^^F[))Fh%% %nn///"g")+66FK!!*--FJ"";//FK")+66FK!(44FJ#*<88FL")+66FK( /0A B BFg-";"=11g*511FL+F33FM TTDOOTTTFh$*N8O8OMr   pythonFc                 .   t                      }d|_        |t          |          |_        | t          |           |_        |t          |          |_        |g |_        n||_        |t          |          |_	        t          |pi           |_
        |S )z,Create a new code cell with input and outputcode)r   	cell_typer"   languageinputr@   rA   outputsbool	collapsedr7   )rU   rA   rV   rT   rX   r7   cells          r   new_code_cellrZ      s     >>DDN'11$U++
  //i R00DMKr   c                     t                      }| dk    rd} |t          |          |_        t          |pi           |_        | |_        |S )zCreate a new text cell.	plaintextraw)r   r"   sourcer7   rS   )rS   r^   renderedr7   rY   s        r   new_text_cellr`      sQ    >>D K	%f-- R00DMDNKr      c                     t                      }d|_        | t          |           |_        t	          |          |_        t          |pi           |_        |S )z5Create a new section cell with a given integer level.heading)r   rS   r"   r^   r@   levelr7   )r^   rd   r_   r7   rY   s        r   new_heading_cellre      sL    >>DDN%f--UDJ R00DMKr   c                     t                      }|g |_        nt          |          |_        t          |pi           |_        |S )z5Create a worksheet by name with with a list of cells.)r   cellsr   r7   )namerg   r7   wss       r   new_worksheetrj      s>    	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_metadatar7   r"   rh   )rh   r7   rn   nbs       r   new_notebookrq      sw    	BBK&BZ(("nn"8,,*400Ir   c                 *   t                      }| t          |           |_        |t          |          |_        |t          |          |_        |t          |          |_        |t          |          |_        |t          |          |_        |S )zCreate a new metadata node.)	r   r"   rh   r   authorscreatedmodifiedlicensegistid)rh   rs   rv   rt   ru   rw   r7   s          r   ro   ro      s     ~~H'--==*733+H55*733)&11Or   c                     t                      }| t          |           |_        |t          |          |_        |t          |          |_        |t          |          |_        |S )zCreate a new author.)r   r"   rh   emailaffiliationurl)rh   ry   rz   r{   authors        r   
new_authorr}      sd    ^^F%d++&u--,[99
$S))
Mr   )NNNNNNNNNNNNNN)NNNrP   FN)NNN)Nra   NN)NNNNNN)NNNN)r
   r(   nbformat._structr   rl   rm   nbformat_schemar   r   r"   r,   rO   rZ   r`   re   rj   rq   ro   r}   r   r   r   <module>r      s     # # # # # # 45	 	 	 	 	6 	 	 	
 
 
    ( 
> > > >D    8            & PT   (     r   