o
    ”^©i
  ã                   @  sN   d Z ddlm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.é    )Úannotationsé   )Ú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/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/nbformat/v3/convert.pyr
   
   s   

ú
ý
r
   é   c                 C  s~   |dkr't | _ t| _d| _t| ƒ} | d D ]}|d D ]}| di ¡ qq| S |dkr7|tkr2|| _t| _| S d| }t|ƒ‚)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ÚcellÚmsgr   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_mdE   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   Ú	downgradeJ   s   





€ür0   N)r   r   )Ú__doc__Ú
__future__r   Únbbaser   r   r
   r$   r,   r-   r0   r   r   r   r   Ú<module>   s    
#