
    Mh!                         d Z ddlmZ ddlmZ  G d de          Z G d d          Z G d d	e          Z G d
 de          ZdS )z#
Classes for managing Checkpoints.
    )	HTTPError)LoggingConfigurablec                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
Checkpointsaq  
    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                     t           zCreate a checkpoint.NotImplementedErrorselfcontents_mgrpaths      l/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyter_server/services/contents/checkpoints.pycreate_checkpointzCheckpoints.create_checkpoint       !!    c                     t           zRestore a checkpointr	   r   r   checkpoint_idr   s       r   restore_checkpointzCheckpoints.restore_checkpoint   r   r   c                     t           z5Rename a single checkpoint from old_path to new_path.r	   r   r   old_pathnew_paths       r   rename_checkpointzCheckpoints.rename_checkpoint    r   r   c                     t           zdelete a checkpoint for a filer	   r   r   r   s      r   delete_checkpointzCheckpoints.delete_checkpoint$   r   r   c                     t           z-Return a list of checkpoints for a given filer	   r   r   s     r   list_checkpointszCheckpoints.list_checkpoints(   r   r   c                 p    |                      |          D ]}|                     |d         ||            dS )0Rename all checkpoints for old_path to new_path.idNr%   r   r   r   r   cps       r   rename_all_checkpointsz"Checkpoints.rename_all_checkpoints,   sL    ''11 	A 	AB""2d8Xx@@@@	A 	Ar   c                 n    |                      |          D ]}|                     |d         |           dS )*Delete all checkpoints for the given path.r(   Nr%   r!   r   r   
checkpoints      r   delete_all_checkpointsz"Checkpoints.delete_all_checkpoints1   sG    //55 	; 	;J"":d#3T::::	; 	;r   N__name__
__module____qualname____doc__r   r   r   r!   r%   r,   r2    r   r   r   r      s        
 
" " "" " "" " "" " "" " "A A A
; ; ; ; ;r   r   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	GenericCheckpointsMixina  
    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                    |                     |d          }|d         }|dk    r|                     |d         |          S |dk    r#|                     |d         |d         |          S t          dd	t          z            
NTcontenttypenotebookr>   fileformat  Unexpected type %s)getcreate_notebook_checkpointcreate_file_checkpointr   r?   r   r   r   modeltype_s        r   r   z)GenericCheckpointsMixin.create_checkpointM   s      t 44fJ22i    f__..i h   C!5!<===r   c                    |                     |d          d         }|dk    r|                     ||          }n0|dk    r|                     ||          }nt          dd|z            |                    ||           dS )	Restore a checkpoint.Fr=   r?   r@   rA   rC   rD   NrE   get_notebook_checkpointget_file_checkpointr   save)r   r   r   r   rJ   rI   s         r   r   z*GenericCheckpointsMixin.restore_checkpoint^   s      u 55f=J00EEEEf__,,]DAAEEC!5!=>>>%&&&&&r   c                     t           zwCreate a checkpoint of the current state of a file

        Returns a checkpoint model for the new checkpoint.
        r	   r   r>   rB   r   s       r   rG   z.GenericCheckpointsMixin.create_file_checkpointj   
    
 "!r   c                     t           rR   r	   r   nbr   s      r   rF   z2GenericCheckpointsMixin.create_notebook_checkpointq   rT   r   c                     t           zGet the content of a checkpoint for a non-notebook file.

        Returns a dict of the form::

            {
                'type': 'file',
                'content': <str>,
                'format': {'text','base64'},
            }
        r	   r    s      r   rO   z+GenericCheckpointsMixin.get_file_checkpointx   s
     "!r   c                     t           zGet the content of a checkpoint for a notebook.

        Returns a dict of the form::

            {
                'type': 'notebook',
                'content': <output of nbformat.read>,
            }
        r	   r    s      r   rN   z/GenericCheckpointsMixin.get_notebook_checkpoint   s
     "!r   N
r4   r5   r6   r7   r   r   rG   rF   rO   rN   r8   r   r   r:   r:   7   sx         *> > >"	' 	' 	'" " "" " "" " "
" 
" 
" 
" 
"r   r:   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
AsyncCheckpointszS
    Base class for managing checkpoints for a ContentsManager asynchronously.
    c                    K   t           r   r	   r   s      r   r   z"AsyncCheckpoints.create_checkpoint         !!r   c                    K   t           r   r	   r   s       r   r   z#AsyncCheckpoints.restore_checkpoint   r`   r   c                    K   t           r   r	   r   s       r   r   z"AsyncCheckpoints.rename_checkpoint   r`   r   c                    K   t           r   r	   r    s      r   r!   z"AsyncCheckpoints.delete_checkpoint   r`   r   c                    K   t           r#   r	   r$   s     r   r%   z!AsyncCheckpoints.list_checkpoints   r`   r   c                    K   |                      |           d{V D ]%}|                     |d         ||           d{V  &dS )r'   Nr(   r)   r*   s       r   r,   z'AsyncCheckpoints.rename_all_checkpoints   st      --h77777777 	G 	GB((D8XFFFFFFFFFF	G 	Gr   c                    K   |                      |           d{V D ]$}|                     |d         |           d{V  %dS )r.   Nr(   r/   r0   s      r   r2   z'AsyncCheckpoints.delete_all_checkpoints   ss       $ 5 5d ; ;;;;;;; 	A 	AJ((D)94@@@@@@@@@@	A 	Ar   Nr3   r8   r   r   r^   r^      s         " " "" " "" " "" " "" " "G G G
A A A A Ar   r^   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	AsyncGenericCheckpointsMixinzp
    Helper for creating Asynchronous Checkpoints subclasses that can be used with any
    ContentsManager.
    c                 $  K   |                     |d           d {V }|d         }|dk    r"|                     |d         |           d {V S |dk    r)|                     |d         |d         |           d {V S t          dd	|z            r<   )rE   rF   rG   r   rH   s        r   r   z.AsyncGenericCheckpointsMixin.create_checkpoint   s      "&&tT&::::::::fJ88i          f__44i h         C!5!=>>>r   c                 >  K   |                     |d           d{V }|d         }|dk    r|                     ||           d{V }n6|dk    r|                     ||           d{V }nt          dd|z            |                    ||           d{V  dS )	rL   Fr=   Nr?   r@   rA   rC   rD   rM   )r   r   r   r   content_modelrJ   rI   s          r   r   z/AsyncGenericCheckpointsMixin.restore_checkpoint   s      *..tU.CCCCCCCCf%J66}dKKKKKKKKEEf__22=$GGGGGGGGEEC!5!=>>>t,,,,,,,,,,,r   c                    K   t           rR   r	   rS   s       r   rG   z3AsyncGenericCheckpointsMixin.create_file_checkpoint         
 "!r   c                    K   t           rR   r	   rV   s      r   rF   z7AsyncGenericCheckpointsMixin.create_notebook_checkpoint   rm   r   c                    K   t           rY   r	   r    s      r   rO   z0AsyncGenericCheckpointsMixin.get_file_checkpoint   s       "!r   c                    K   t           r[   r	   r    s      r   rN   z4AsyncGenericCheckpointsMixin.get_notebook_checkpoint   s       "!r   Nr\   r8   r   r   rh   rh      sx         
? ? ?"
- 
- 
-" " "" " "" " "
" 
" 
" 
" 
"r   rh   N)	r7   tornado.webr   traitlets.config.configurabler   r   r:   r^   rh   r8   r   r   <module>rs      s    " ! ! ! ! ! = = = = = =); ); ); ); );% ); ); );XX" X" X" X" X" X" X" X"v!A !A !A !A !A{ !A !A !AHI" I" I" I" I"#: I" I" I" I" I"r   