
    Mh                        d Z ddlm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.
    )annotationsN)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__     R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbformat/v3/nbbase.pyr   r      s        !!!!r   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!eT]## )((a((((Hr   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-   4   sm    #u 	. 	4		
 	
 	
 	
 zz'9---c3 Jr   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   	tracebackr4   )r6   output_text
output_pngoutput_html
output_svgoutput_latexoutput_jsonoutput_javascriptoutput_jpegrB   rC   rD   rE   r4   r8   outputmsgs                    r   
new_outputrP   E   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inputrA   rB   outputsbool	collapsedr8   )rV   rB   rW   rU   rY   r8   cells          r   new_code_cellr[      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#   sourcer8   rT   )rT   r_   renderedr8   rZ   s        r   new_text_cellra      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   rT   r#   r_   rA   levelr8   )r_   re   r`   r8   rZ   s        r   new_heading_cellrf      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   r8   )namerh   r8   wss       r   new_worksheetrk      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_metadatar8   r#   ri   )ri   r8   ro   nbs       r   new_notebookrr      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#   ri   r   authorscreatedmodifiedlicensegistid)ri   rt   rw   ru   rv   rx   r8   s          r   rp   rp      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#   ri   emailaffiliationurl)ri   rz   r{   r|   authors        r   
new_authorr~      sd    ^^F%d++&u--,[99
$S))
Mr   )NNNNNNNNNNNNNN)NNNrQ   FN)NNN)Nrb   NN)NNNNNN)NNNN)r   
__future__r   r)   nbformat._structr   rm   rn   nbformat_schemar   r   r#   r-   rP   r[   ra   rf   rk   rr   rp   r~   r   r   r   <module>r      s    # " " " " "  # # # # # # 45" " " " "6 " " "	 	 	    & 
> > > >D    8            & 
   2     r   