Ë
    :vžjÃ!  ã                   óv   — 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y)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
y	)
Ú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      ú}/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/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                 ó\   — | j                  |«      D ]  }| j                  |d   ||«       Œ y)ú0Rename all checkpoints for old_path to new_path.ÚidN©r%   r   ©r   r   r   Úcps       r   Úrename_all_checkpointsz"Checkpoints.rename_all_checkpoints,   s-   € à×'Ñ'¨Ö1ˆBØ×"Ñ" 2 d¡8¨X°xÕ@ñ 2r   c                 óZ   — | j                  |«      D ]  }| j                  |d   |«       Œ y)ú*Delete all checkpoints for the given path.r(   N©r%   r!   ©r   r   Ú
checkpoints      r   Údelete_all_checkpointsz"Checkpoints.delete_all_checkpoints1   s,   € à×/Ñ/°Ö5ˆJØ×"Ñ" :¨dÑ#3°TÕ:ñ 6r   N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r!   r%   r,   r2   © r   r   r   r      s+   „ ñ
ò"ò"ò"ò"ò"òAó
;r   r   c                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	Ú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                 óÈ   — |j                  |d¬«      }|d   }|dk(  r| j                  |d   |«      S |dk(  r| j                  |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ˆØ�f‘ˆØ�JÒØ×2Ñ2Ø�iÑ Øóð ð �fŠ_Ø×.Ñ.Ø�iÑ Ø�h‘Øóð ô ˜CÐ!5¼Ñ!<Ó=Ð=r   c                 óÒ   — |j                  |d¬«      d   }|dk(  r| j                  ||«      }n'|dk(  r| j                  ||«      }nt        dd|z  «      ‚|j	                  ||«       y)	ú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^   sr   € à× Ñ  ¨uÐ Ó5°fÑ=ˆØ�JÒØ×0Ñ0°ÀÓE‰EØ�fŠ_Ø×,Ñ,¨]¸DÓA‰Eä˜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         ‚©zóGet 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         ‚©zÕGet 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   s%   „ ñò*>ò"	'ò"ò"ò"ó
"r   r:   c                   ó:   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
y	)
ÚAsyncCheckpointszS
    Base class for managing checkpoints for a ContentsManager asynchronously.
    c              ƒ   ó   K  — t         ‚­wr   r	   r   s      r   r   z"AsyncCheckpoints.create_checkpoint—   ó   è ø€ ä!Ð!ùó   ‚	c              ƒ   ó   K  — t         ‚­wr   r	   r   s       r   r   z#AsyncCheckpoints.restore_checkpoint›   r`   ra   c              ƒ   ó   K  — t         ‚­wr   r	   r   s       r   r   z"AsyncCheckpoints.rename_checkpointŸ   r`   ra   c              ƒ   ó   K  — t         ‚­wr   r	   r    s      r   r!   z"AsyncCheckpoints.delete_checkpoint£   r`   ra   c              ƒ   ó   K  — t         ‚­wr#   r	   r$   s     r   r%   z!AsyncCheckpoints.list_checkpoints§   r`   ra   c              ƒ   óŒ   K  — | j                  |«      ƒ d{  –—† D ]   }| j                  |d   ||«      ƒ d{  –—†  Œ" y7 Œ(7 Œ	­w)r'   Nr(   r)   r*   s       r   r,   z'AsyncCheckpoints.rename_all_checkpoints«   sA   è ø€ à×-Ñ-¨hÓ7×7Ò7ˆBØ×(Ñ(¨¨D©°8¸XÓF×FÑFò 8øØFús   ‚A—A ˜ A¸A¹AÁAc              ƒ   óŠ   K  — | j                  |«      ƒ d{  –—† D ]  }| j                  |d   |«      ƒ d{  –—†  Œ! y7 Œ'7 Œ	­w)r.   Nr(   r/   r0   s      r   r2   z'AsyncCheckpoints.delete_all_checkpoints°   s@   è ø€ à $× 5Ñ 5°dÓ ;×;Ò;ˆJØ×(Ñ(¨°DÑ)9¸4Ó@×@Ñ@ò <øØ@ús   ‚A—?˜A·A¸AÁANr3   r8   r   r   r^   r^   ’   s,   „ ñò"ò"ò"ò"ò"òGó
Ar   r^   c                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	ÚAsyncGenericCheckpointsMixinzp
    Helper for creating Asynchronous Checkpoints subclasses that can be used with any
    ContentsManager.
    c              ƒ   ó  K  — |j                  |d¬«      ƒ d {  –—† }|d   }|dk(  r| j                  |d   |«      ƒ d {  –—† S |dk(  r!| j                  |d   |d   |«      ƒ d {  –—† S t        dd	|z  «      ‚7 Œ`7 Œ;7 Œ­wr<   )rE   rF   rG   r   rH   s        r   r   z.AsyncGenericCheckpointsMixin.create_checkpoint¼   s«   è ø€ Ø"×&Ñ& t°TÐ&Ó:×:ˆØ�f‘ˆØ�JÒØ×8Ñ8Ø�iÑ Øó÷ ð ð �fŠ_Ø×4Ñ4Ø�iÑ Ø�h‘Øó÷ ð ô ˜CÐ!5¸Ñ!=Ó>Ð>ð ;øðøð
ús3   ‚B ™A:š&B Á A<Á%B Á&A>Á'B Á<B Á>B c              ƒ   ó.  K  — |j                  |d¬«      ƒ d{  –—† }|d   }|dk(  r| j                  ||«      ƒ d{  –—† }n/|dk(  r| j                  ||«      ƒ d{  –—† }nt        dd|z  «      ‚|j	                  ||«      ƒ d{  –—†  y7 Œs7 ŒQ7 Œ37 Œ­w)	rL   Fr=   Nr?   r@   rA   rC   rD   rM   )r   r   r   r   Úcontent_modelrJ   rI   s          r   r   z/AsyncGenericCheckpointsMixin.restore_checkpointÍ   s¡   è ø€ à*×.Ñ.¨t¸UÐ.ÓC×CˆØ˜fÑ%ˆØ�JÒØ×6Ñ6°}ÀdÓK×K‰EØ�fŠ_Ø×2Ñ2°=À$ÓG×G‰Eä˜CÐ!5¸Ñ!=Ó>Ð>Ø×Ñ  tÓ,×,Ñ,ð Døð LøàGøð 	-úsC   ‚B™Bš#B½B¾BÁBÁ)BÂBÂBÂBÂBÂBc              ƒ   ó   K  — t         ‚­wrR   r	   rS   s       r   rG   z3AsyncGenericCheckpointsMixin.create_file_checkpointÚ   ó   è ø€ ô
 "Ð!ùra   c              ƒ   ó   K  — t         ‚­wrR   r	   rV   s      r   rF   z7AsyncGenericCheckpointsMixin.create_notebook_checkpointá   rn   ra   c              ƒ   ó   K  — t         ‚­wrY   r	   r    s      r   rO   z0AsyncGenericCheckpointsMixin.get_file_checkpointè   s   è ø€ ô "Ð!ùra   c              ƒ   ó   K  — t         ‚­wr[   r	   r    s      r   rN   z4AsyncGenericCheckpointsMixin.get_notebook_checkpointõ   s   è ø€ ô "Ð!ùra   Nr\   r8   r   r   ri   ri   ¶   s%   „ ñò
?ò"
-ò"ò"ò"ó
"r   ri   N)	r7   Útornado.webr   Útraitlets.config.configurabler   r   r:   r^   ri   r8   r   r   Ú<module>rt      sK   ðñõ "Ý =ô);Ð%ô );÷XX"ñ X"ôv!A�{ô !AôHI"Ð#:õ I"r   