a
    ø£Be0
  ã                   @   s4   d Z ddlmZ ddlmZ ddlmZ dd„ ZdS )z.API for converting notebooks between versions.é   )Úversions)Úget_version)ÚValidationErrorc           	   
   C   sÞ   t | ƒ\}}||kr| S |tv rÎ||kr<|d }t| j}n|d }t| j}z0|| ƒ}| dd¡|kr|d||f }t|ƒ‚W nD tyÂ } z,d|› d|› d|› �}t|ƒd‚W Y d}~n
d}~0 0 t||ƒS td| ƒ‚dS )	a  Convert a notebook node object to a specific version.  Assumes that
    all the versions starting from 1 to the latest major X are implemented.
    In other words, there should never be a case where v1 v2 v3 v5 exist without
    a v4.  Also assumes that all conversions can be made in one step increments
    between major versions and ignores minor revisions.

    Parameters
    ----------
    nb : NotebookNode
    to_version : int
        Major revision to convert the notebook to.  Can either be an upgrade or
        a downgrade.

    Raises
    ------
    ValueError
        Notebook failed to convert.
    ValueError
        The version specified is invalid or doesn't exist.
    ValidationError
        Conversion failed due to missing expected attributes.
    r   Znbformatz+Failed to convert notebook from v%d to v%d.z-Notebook could not be converted from version z to version z because it's missing a key: NzACannot convert notebook to v%d because that version doesn't exist)	r   r   ÚupgradeÚ	downgradeÚgetÚ
ValueErrorÚAttributeErrorr   Úconvert)	ÚnbZ
to_versionÚversionZversion_minorZstep_versionZconvert_functionZ	convertedÚmsgÚe© r   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/nbformat/converter.pyr
      s*    
 
ÿr
   N)Ú__doc__Ú r   Úreaderr   Ú	validatorr   r
   r   r   r   r   Ú<module>   s   