o
    ¹iþ	  ã                   @   sB   d Z ddlmZmZ dd„ Zddd„Zd	d
„ Zdd„ Zdd„ ZdS )z8Code for converting notebooks to and from the v2 format.é   )ÚnbformatÚnbformat_minorc                 C   sp   t | tƒr|  ¡ D ]
\}}t|ƒ| |< q	| S t | tƒr,t| ƒD ]
\}}t|ƒ| |< q| S t | tƒr6|  d¡} | S )z^There should be no bytes objects in a notebook

    v2 stores png/jpeg as b64 ascii bytes
    Úascii)Ú
isinstanceÚdictÚitemsÚ_unbytesÚlistÚ	enumerateÚbytesÚdecode)ÚobjÚkÚvÚi© r   úN/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/nbformat/v3/convert.pyr   	   s   

ú
ý
r   é   é    c                 C   sz   |dkr't | _ t| _d| _t| ƒ} | d D ]}|d D ]}| di ¡ qq| S |dkr7|tkr2|| _t| _| S td| ƒ‚)aP  Convert a notebook to v3.

    Parameters
    ----------
    nb : NotebookNode
        The Python representation of the notebook to convert.
    from_version : int
        The original version of the notebook to convert.
    from_minor : int
        The original minor version of the notebook to convert (only relevant for v >= 3).
    r   Ú
worksheetsÚcellsÚmetadataé   zZCannot convert a notebook directly from v%s to v3.  Try using the nbformat.convert module.)r   r   Úorig_nbformatr   Ú
setdefaultÚorig_nbformat_minorÚ
ValueError)ÚnbÚfrom_versionÚ
from_minorÚwsÚcellr   r   r   Úupgrade   s(   ÿÿÿr"   c                 C   s*   d| _ |  dd¡}d| d | j | _dS )z-turn heading cell into corresponding markdownÚmarkdownÚlevelr   ú#ú N)Ú	cell_typeÚpopÚsource)r!   r$   r   r   r   Úheading_to_md=   s   r*   c                 C   s
   d| _ dS )zlet raw passthrough as markdownr#   N)r'   )r!   r   r   r   Ú	raw_to_mdD   s   
r+   c                 C   sV   | j dkr| S d| _ | jD ]}|jD ]}|jdkrt|ƒ q|jdkr't|ƒ qq| S )z”Convert a v3 notebook to v2.

    Parameters
    ----------
    nb : NotebookNode
        The Python representation of the notebook to convert.
    r   r   ÚheadingÚraw)r   r   r   r'   r*   r+   )r   r    r!   r   r   r   Ú	downgradeI   s   





€ür.   N)r   r   )	Ú__doc__Únbbaser   r   r   r"   r*   r+   r.   r   r   r   r   Ú<module>   s    
#