ó
‹'=[c           @   s   d  Z  d d l m Z m Z m Z m Z m Z m Z m Z d d l m	 Z	 d „  Z
 d d d „ Z d	 „  Z d
 „  Z d „  Z d S(   s8   Code for converting notebooks to and from the v2 format.i   (   t   new_code_cellt   new_text_cellt   new_worksheett   new_notebookt
   new_outputt   nbformatt   nbformat_minoriÿÿÿÿ(   t   v2c         C   s£   t  |  t ƒ r? x |  j ƒ  D] \ } } t | ƒ |  | <q Wn` t  |  t ƒ r~ xN t |  ƒ D] \ } } t | ƒ |  | <q[ Wn! t  |  t ƒ rŸ |  j d ƒ }  n  |  S(   s^   There should be no bytes objects in a notebook

    v2 stores png/jpeg as b64 ascii bytes
    t   ascii(   t
   isinstancet   dictt   itemst   _unbytest   listt	   enumeratet   bytest   decode(   t   objt   kt   vt   i(    (    s2   lib/python2.7/site-packages/nbformat/v3/convert.pyR      s    i   i    c         C   s¶   | d k rq t  |  _  t |  _ d |  _ t |  ƒ }  x7 |  d D]+ } x" | d D] } | j d i  ƒ qO Wq> W|  S| d k r¢ | t k r• | |  _ n  t |  _ |  St d | ƒ ‚ d S(   sP  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).
    i   t
   worksheetst   cellst   metadatai   sZ   Cannot convert a notebook directly from v%s to v3.  Try using the nbformat.convert module.N(   R   R   t   orig_nbformatR   t
   setdefaultt   orig_nbformat_minort
   ValueError(   t   nbt   from_versiont
   from_minort   wst   cell(    (    s2   lib/python2.7/site-packages/nbformat/v3/convert.pyt   upgrade   s     				c         C   s7   d |  _  |  j d d ƒ } d | d |  j |  _ d S(   s-   turn heading cell into corresponding markdownt   markdownt   leveli   t   #t    N(   t	   cell_typet   popt   source(   R    R#   (    (    s2   lib/python2.7/site-packages/nbformat/v3/convert.pyt   heading_to_md>   s    	c         C   s   d |  _  d S(   s   let raw passthrough as markdownR"   N(   R&   (   R    (    (    s2   lib/python2.7/site-packages/nbformat/v3/convert.pyt	   raw_to_mdE   s    c         C   s€   |  j  d k r |  Sd |  _  x] |  j D]R } xI | j D]> } | j d k rX t | ƒ q6 | j d k r6 t | ƒ q6 q6 Wq& W|  S(   s”   Convert a v3 notebook to v2.

    Parameters
    ----------
    nb : NotebookNode
        The Python representation of the notebook to convert.
    i   i   t   headingt   raw(   R   R   R   R&   R)   R*   (   R   R   R    (    (    s2   lib/python2.7/site-packages/nbformat/v3/convert.pyt	   downgradeJ   s    	N(   t   __doc__t   nbbaseR    R   R   R   R   R   R   R   R   R!   R)   R*   R-   (    (    (    s2   lib/python2.7/site-packages/nbformat/v3/convert.pyt   <module>   s   4	!		