ó
ù2¢\c           @   sV   d  Z  d d l m Z d d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(	   s#   
Classes for managing Checkpoints.
iÿÿÿÿ(   t	   HTTPError(   t   LoggingConfigurablet   Checkpointsc           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   sq  
    Base class for managing checkpoints for a ContentsManager.

    Subclasses are required to implement:

    create_checkpoint(self, contents_mgr, path)
    restore_checkpoint(self, contents_mgr, checkpoint_id, path)
    rename_checkpoint(self, checkpoint_id, old_path, new_path)
    delete_checkpoint(self, checkpoint_id, path)
    list_checkpoints(self, path)
    c         C   s   t  d ƒ ‚ d S(   s   Create a checkpoint.s!   must be implemented in a subclassN(   t   NotImplementedError(   t   selft   contents_mgrt   path(    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyt   create_checkpoint   s    c         C   s   t  d ƒ ‚ d S(   s   Restore a checkpoints!   must be implemented in a subclassN(   R   (   R   R   t   checkpoint_idR   (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyt   restore_checkpoint   s    c         C   s   t  d ƒ ‚ d S(   s5   Rename a single checkpoint from old_path to new_path.s!   must be implemented in a subclassN(   R   (   R   R   t   old_patht   new_path(    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyt   rename_checkpoint!   s    c         C   s   t  d ƒ ‚ d S(   s   delete a checkpoint for a files!   must be implemented in a subclassN(   R   (   R   R   R   (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyt   delete_checkpoint%   s    c         C   s   t  d ƒ ‚ d S(   s-   Return a list of checkpoints for a given files!   must be implemented in a subclassN(   R   (   R   R   (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyt   list_checkpoints)   s    c         C   s5   x. |  j  | ƒ D] } |  j | d | | ƒ q Wd S(   s0   Rename all checkpoints for old_path to new_path.t   idN(   R   R   (   R   R
   R   t   cp(    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyt   rename_all_checkpoints-   s    c         C   s2   x+ |  j  | ƒ D] } |  j | d | ƒ q Wd S(   s*   Delete all checkpoints for the given path.R   N(   R   R   (   R   R   t
   checkpoint(    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyt   delete_all_checkpoints2   s    (
   t   __name__t
   __module__t   __doc__R   R	   R   R   R   R   R   (    (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyR      s   						t   GenericCheckpointsMixinc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s  
    Helper for creating Checkpoints subclasses that can be used with any
    ContentsManager.

    Provides a ContentsManager-agnostic implementation of `create_checkpoint`
    and `restore_checkpoint` in terms of the following operations:

    - create_file_checkpoint(self, content, format, path)
    - create_notebook_checkpoint(self, nb, path)
    - get_file_checkpoint(self, checkpoint_id, path)
    - get_notebook_checkpoint(self, checkpoint_id, path)

    To create a generic CheckpointManager, add this mixin to a class that
    implement the above four methods plus the remaining Checkpoints API
    methods:

    - delete_checkpoint(self, checkpoint_id, path)
    - list_checkpoints(self, path)
    - rename_checkpoint(self, checkpoint_id, old_path, new_path)
    c         C   s}   | j  | d t ƒ} | d } | d k r? |  j | d | ƒ S| d k rf |  j | d | d | ƒ St d d | ƒ ‚ d  S(   Nt   contentt   typet   notebookt   filet   formatiô  u   Unexpected type %s(   t   gett   Truet   create_notebook_checkpointt   create_file_checkpointR    (   R   R   R   t   modelR   (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyR   N   s    
c         C   s‚   | j  | d t ƒd } | d k r: |  j | | ƒ } n4 | d k r[ |  j | | ƒ } n t d d | ƒ ‚ | j | | ƒ d S(   s   Restore a checkpoint.R   R   R   R   iô  u   Unexpected type %sN(   R   t   Falset   get_notebook_checkpointt   get_file_checkpointR    t   save(   R   R   R   R   R   R!   (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyR	   _   s    c         C   s   t  d ƒ ‚ d S(   sw   Create a checkpoint of the current state of a file

        Returns a checkpoint model for the new checkpoint.
        s!   must be implemented in a subclassN(   R   (   R   R   R   R   (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyR    k   s    c         C   s   t  d ƒ ‚ d S(   sw   Create a checkpoint of the current state of a file

        Returns a checkpoint model for the new checkpoint.
        s!   must be implemented in a subclassN(   R   (   R   t   nbR   (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyR   r   s    c         C   s   t  d ƒ ‚ d S(   sã   Get the content of a checkpoint for a non-notebook file.

         Returns a dict of the form:
         {
             'type': 'file',
             'content': <str>,
             'format': {'text','base64'},
         }
        s!   must be implemented in a subclassN(   R   (   R   R   R   (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyR$   y   s    
c         C   s   t  d ƒ ‚ d S(   sÃ   Get the content of a checkpoint for a notebook.

        Returns a dict of the form:
        {
            'type': 'notebook',
            'content': <output of nbformat.read>,
        }
        s!   must be implemented in a subclassN(   R   (   R   R   R   (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyR#   …   s    	(	   R   R   R   R   R	   R    R   R$   R#   (    (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyR   8   s   					N(   R   t   tornado.webR    t   traitlets.config.configurableR   R   t   objectR   (    (    (    sE   lib/python2.7/site-packages/notebook/services/contents/checkpoints.pyt   <module>   s   +