ó
‹'=[c           @   s¹   d  Z  d d l m Z m Z d d l Z d d l m Z m Z m Z d „  Z	 d d d d	 d
 d g Z
 d „  Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sO   Base classes and utilities for readers and writers.

Authors:

* Brian Granger
iÿÿÿÿ(   t   encodestringt   decodestringN(   t   str_to_bytest   unicode_typet   string_typesc         C   sš   x“ |  j  D]ˆ } x | j D]t } | j d k r x\ | j D]N } d | k rc t | j d ƒ | _ n  d | k r9 t | j d ƒ | _ q9 q9 Wq q Wq
 W|  S(   sÒ   Restore bytes of image data from unicode-only formats.
    
    Base64 encoding is handled elsewhere.  Bytes objects in the notebook are
    always b64-encoded. We DO NOT encode/decode around file formats.
    t   codet   pngt   asciit   jpeg(   t
   worksheetst   cellst	   cell_typet   outputsR   R   R   (   t   nbt   wst   cellt   output(    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyt   restore_bytes   s    't   textt   htmlt   svgt   latext
   javascriptt   jsonc         C   s  x|  j  D]} x| j D]ø } | j d k rÄ d | k re t | j t ƒ re d j | j ƒ | _ n  xª | j D]N } xE t D]= } | j	 | d ƒ } t | t ƒ r| d j | ƒ | | <q| q| Wqo Wq xK d d g D]= } | j	 | d ƒ } t | t ƒ rÑ d j | ƒ | | <qÑ qÑ Wq Wq
 W|  S(   s2  rejoin multiline text into strings
    
    For reversing effects of ``split_lines(nb)``.
    
    This only rejoins lines that have been split, so if text objects were not split
    they will pass through unchanged.
    
    Used when reading JSON files that may have been passed through split_lines.
    R   t   inputu   
t   sourcet   renderedN(   R	   R
   R   t
   isinstanceR   t   listt   joinR   t   _multiline_outputst   gett   None(   R   R   R   R   t   keyt   item(    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyt   rejoin_lines/   s    
!"c         C   s  x|  j  D]} xú | j D]ï } | j d k r¾ d | k rb t | j t ƒ rb | j j ƒ  | _ n  x¤ | j D]K } xB t D]: } | j	 | d ƒ } t | t ƒ ry | j ƒ  | | <qy qy Wql Wq xH d d g D]: } | j	 | d ƒ } t | t ƒ rË | j ƒ  | | <qË qË Wq Wq
 W|  S(   sá   split likely multiline text into lists of strings
    
    For file output more friendly to line-based VCS. ``rejoin_lines(nb)`` will
    reverse the effects of ``split_lines(nb)``.
    
    Used when writing JSON files.
    R   R   R   R   N(   R	   R
   R   R   R   R   t
   splitlinesR   R   R   R    (   R   R   R   R   R!   R"   (    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyt   split_linesK   s    c         C   sè   xá |  j  D]Ö } xÍ | j D]Â } | j d k r xª | j D]œ } d | k rŠ t | j t ƒ ru | j j d ƒ | _ n  t | j ƒ | _ n  d | k r9 t | j	 t ƒ rÀ | j	 j d ƒ | _	 n  t | j	 ƒ | _	 q9 q9 Wq q Wq
 W|  S(   sm   Restore all bytes objects in the notebook from base64-encoded strings.
    
    Note: This is never used
    R   R   R   R   (
   R	   R
   R   R   R   R   R   t   encodeR   R   (   R   R   R   R   (    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyt   base64_decodeg   s    $c         C   s¦   xŸ |  j  D]” } x‹ | j D]€ } | j d k r xh | j D]Z } d | k ri t | j ƒ j d ƒ | _ n  d | k r9 t | j ƒ j d ƒ | _ q9 q9 Wq q Wq
 W|  S(   sŠ   Base64 encode all bytes objects in the notebook.
    
    These will be b64-encoded unicode strings
    
    Note: This is never used
    R   R   R   R   (   R	   R
   R   R   R    R   t   decodeR   (   R   R   R   R   (    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyt   base64_encode{   s    -t   NotebookReaderc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   A class for reading notebooks.c         K   s   t  d ƒ ‚ d S(   s   Read a notebook from a string.s'   loads must be implemented in a subclassN(   t   NotImplementedError(   t   selft   st   kwargs(    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyt   reads   s    c         K   s   |  j  | j  ƒ  |  S(   s'   Read a notebook from a file like object(   t   read(   R,   t   fpR.   (    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyR0   ”   s    (   t   __name__t
   __module__t   __doc__R/   R0   (    (    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyR*      s   	t   NotebookWriterc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   A class for writing notebooks.c         K   s   t  d ƒ ‚ d S(   s   Write a notebook to a string.s'   loads must be implemented in a subclassN(   R+   (   R,   R   R.   (    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyt   writesœ   s    c         K   s   | j  |  j | |  ƒ S(   s&   Write a notebook to a file like object(   t   writeR6   (   R,   R   R1   R.   (    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyR7       s    (   R2   R3   R4   R6   R7   (    (    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyR5   ™   s   	(   R4   t   base64R    R   t   pprintt   ipython_genutils.py3compatR   R   R   R   R   R#   R%   R'   R)   t   objectR*   R5   (    (    (    s1   lib/python2.7/site-packages/nbformat/v2/rwbase.pyt   <module>   s   					