
    ^h!                     v    S r SSKJr  SSKJr   " S S\5      r " S S5      r " S S	\5      r " S
 S\5      rg)z#
Classes for managing Checkpoints.
    )	HTTPError)LoggingConfigurablec                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)Checkpoints   aQ  
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                     [         ezCreate a checkpoint.NotImplementedErrorselfcontents_mgrpaths      f/home/james-whalen/.local/lib/python3.13/site-packages/jupyter_server/services/contents/checkpoints.pycreate_checkpointCheckpoints.create_checkpoint       !!    c                     [         ezRestore a checkpointr
   r   r   checkpoint_idr   s       r   restore_checkpointCheckpoints.restore_checkpoint   r   r   c                     [         ez5Rename a single checkpoint from old_path to new_path.r
   r   r   old_pathnew_paths       r   rename_checkpointCheckpoints.rename_checkpoint    r   r   c                     [         ezdelete a checkpoint for a filer
   r   r   r   s      r   delete_checkpointCheckpoints.delete_checkpoint$   r   r   c                     [         ez-Return a list of checkpoints for a given filer
   r   r   s     r   list_checkpointsCheckpoints.list_checkpoints(   r   r   c                 ^    U R                  U5       H  nU R                  US   X5        M     g)0Rename all checkpoints for old_path to new_path.idNr*   r    r   r   r   cps       r   rename_all_checkpoints"Checkpoints.rename_all_checkpoints,   s+    ''1B""2d8X@ 2r   c                 ^    U R                  U5       H  nU R                  US   U5        M     g)*Delete all checkpoints for the given path.r.   Nr*   r%   r   r   
checkpoints      r   delete_all_checkpoints"Checkpoints.delete_all_checkpoints1   s,    //5J"":d#3T: 6r    N__name__
__module____qualname____firstlineno____doc__r   r   r    r%   r*   r2   r9   __static_attributes__r;   r   r   r   r      s+    
"""""A
;r   r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)GenericCheckpointsMixin7   a  
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                     UR                  USS9nUS   nUS:X  a  U R                  US   U5      $ US:X  a  U R                  US   US   U5      $ [        SS	[        -  5      e
NTcontenttypenotebookrI   fileformat  Unexpected type %s)getcreate_notebook_checkpointcreate_file_checkpointr   rJ   r   r   r   modeltype_s        r   r   )GenericCheckpointsMixin.create_checkpointM   s      t 4fJ22i   f_..i h  C!5!<==r   c                     UR                  USS9S   nUS:X  a  U R                  X#5      nO'US:X  a  U R                  X#5      nO[        SSU-  5      eUR	                  XS5        g)	Restore a checkpoint.FrH   rJ   rK   rL   rN   rO   NrP   get_notebook_checkpointget_file_checkpointr   save)r   r   r   r   rU   rT   s         r   r   *GenericCheckpointsMixin.restore_checkpoint^   sl      u 5f=J00EEf_,,]AEC!5!=>>%&r   c                     [         ezgCreate a checkpoint of the current state of a file

Returns a checkpoint model for the new checkpoint.
r
   r   rI   rM   r   s       r   rR   .GenericCheckpointsMixin.create_file_checkpointj   
    
 "!r   c                     [         er_   r
   r   nbr   s      r   rQ   2GenericCheckpointsMixin.create_notebook_checkpointq   rb   r   c                     [         e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   r[   +GenericCheckpointsMixin.get_file_checkpointx   s
     "!r   c                     [         e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   rZ   /GenericCheckpointsMixin.get_notebook_checkpoint   s
     "!r   r;   Nr=   r>   r?   r@   rA   r   r   rR   rQ   r[   rZ   rB   r;   r   r   rD   rD   7   s%    *>"	'"""
"r   rD   c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)AsyncCheckpoints   zK
Base class for managing checkpoints for a ContentsManager asynchronously.
c                    #    [         e7fr	   r
   r   s      r   r   "AsyncCheckpoints.create_checkpoint        !!   	c                    #    [         e7fr   r
   r   s       r   r   #AsyncCheckpoints.restore_checkpoint   rs   rt   c                    #    [         e7fr   r
   r   s       r   r    "AsyncCheckpoints.rename_checkpoint   rs   rt   c                    #    [         e7fr#   r
   r$   s      r   r%   "AsyncCheckpoints.delete_checkpoint   rs   rt   c                    #    [         e7fr(   r
   r)   s     r   r*   !AsyncCheckpoints.list_checkpoints   rs   rt   c                    #    U R                  U5      I Sh  vN  H   nU R                  US   X5      I Sh  vN   M"     g N) N7f)r-   Nr.   r/   r0   s       r   r2   'AsyncCheckpoints.rename_all_checkpoints   s=     --h777B((D8FFF 8F   AAAA
AAc                    #    U R                  U5      I Sh  vN  H   nU R                  US   U5      I Sh  vN   M"     g N) N7f)r5   Nr.   r6   r7   s      r   r9   'AsyncCheckpoints.delete_all_checkpoints   s>      $ 5 5d ;;;J((D)94@@@ <@r   r;   Nr<   r;   r   r   ro   ro      s,    """""G
Ar   ro   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)AsyncGenericCheckpointsMixin   zd
Helper for creating Asynchronous Checkpoints subclasses that can be used with any
ContentsManager.
c                   #    UR                  USS9I S h  vN nUS   nUS:X  a  U R                  US   U5      I S h  vN $ US:X  a!  U R                  US   US   U5      I S h  vN $ [        SS	U-  5      e Nb N< N7frG   )rP   rQ   rR   r   rS   s        r   r   .AsyncGenericCheckpointsMixin.create_checkpoint   s     "&&tT&::fJ88i    f_44i h   C!5!=>> ;
s1   A?A9'A?A;&A?%A=&A?;A?=A?c                 &  #    UR                  USS9I Sh  vN nUS   nUS:X  a  U R                  X#5      I Sh  vN nO/US:X  a  U R                  X#5      I Sh  vN nO[        SSU-  5      eUR	                  Xc5      I Sh  vN   g Nr NP N2 N7f)	rX   FrH   NrJ   rK   rL   rN   rO   rY   )r   r   r   r   content_modelrU   rT   s          r   r   /AsyncGenericCheckpointsMixin.restore_checkpoint   s     *..tU.CCf%J66}KKEf_22=GGEC!5!=>>,,, D LG 	-sC   BB	#BBBB(BBBBBBc                    #    [         e7fr_   r
   r`   s       r   rR   3AsyncGenericCheckpointsMixin.create_file_checkpoint        
 "!rt   c                    #    [         e7fr_   r
   rd   s      r   rQ   7AsyncGenericCheckpointsMixin.create_notebook_checkpoint   r   rt   c                    #    [         e7frh   r
   r$   s      r   r[   0AsyncGenericCheckpointsMixin.get_file_checkpoint   s      "!rt   c                    #    [         e7frk   r
   r$   s      r   rZ   4AsyncGenericCheckpointsMixin.get_notebook_checkpoint   s      "!rt   r;   Nrm   r;   r   r   r   r      s%    
?"
-"""
"r   r   N)	rA   tornado.webr   traitlets.config.configurabler   r   rD   ro   r   r;   r   r   <module>r      sK    " =);% );XX" X"v!A{ !AHI"#: I"r   