Ë
    :vžj"Â  ã                  ó¾  — d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZ ddlmZ ddlZddlmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5m6Z6 	 ddl7m8Z8 dZ;dd„Z< G d„ de2e5«      Z= G d„ de=e1e4«      Z>y# e9$ r	 ddl+m:Z8 Y Œ-w xY w)z?A contents manager that uses the local file system for storage.é    )ÚannotationsN)Údatetime)ÚPath)Úrun_sync)ÚexistsÚis_file_hiddenÚ	is_hidden)Ú
send2trash)Úweb)ÚBoolÚIntÚ
TraitErrorÚUnicodeÚdefaultÚvalidate)Ú_tz©ÚAuthenticatedFileHandler)Ú_i18n)Úto_api_pathé   )ÚAsyncFileCheckpointsÚFileCheckpoints)ÚAsyncFileManagerMixinÚFileManagerMixin)ÚAsyncContentsManagerÚContentsManagerÚcopy_pat)Úsamefile)Úsamefile_simplec                ó˜   — t        | dd«      }t        |t        t        f«      r|dk\  rt	        j
                  |«      r|S | j                  S )a^  Get best-effort file creation timestamp from stat result.

    Uses st_birthtime (actual creation time) when available (macOS, BSD,
    and Linux with kernel 4.11+ via statx on supported filesystems).
    On Windows, st_ctime is the creation time.
    On Linux/other, falls back to st_ctime (note: this is inode change time,
    not creation time, so operations like chmod may update 'created').

    Falls back to st_ctime if st_birthtime is unavailable, non-numeric,
    negative, or non-finite. Returns st_ctime as final fallback, which
    is validated in _base_model() during datetime conversion.
    Úst_birthtimeNr   )ÚgetattrÚ
isinstanceÚintÚfloatÚmathÚisfiniteÚst_ctime)ÚinfoÚ	birthtimes     ú}/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/jupyter_server/services/contents/filemanager.pyÚ_get_created_timestampr-   /   sF   € ô ˜˜n¨dÓ3€Iô
 �)œc¤5˜\Ô*¨y¸Aª~Ä$Ç-Á-ÐPYÔBZØÐð �=‰=Ðó    c                  óÒ  ‡ — e Zd ZdZ ed¬«      Z eddd¬«      Z ed«      d„ «       Z	 e
d«      d	„ «       Z ed
«      d„ «       Z e
d
«      ˆ fd„«       Z ed«      d„ «       Z eddd¬«      Z eddd¬«      Z ed«      d„ «       Z ed«      d„ «       Zd„ Zd„ Zd,d„Zd„ Zd„ Zd-d„Zd„ Zd.d„Zd/d„Zd0d„Zd1d „Zd2d!„Zd2d"„Z d#„ Z!d$„ Z"d%„ Z#d3d&„Z$d3ˆ fd'„	Z%d(„ Z&d)„ Z'd4d*„Z(d+„ Z)ˆ xZ*S )5ÚFileContentsManagerzA file contents manager.T)Úconfigéô  z&The max folder size that can be copied)r1   ÚhelpÚroot_dirc                ón   — | j                   st        j                  «       S | j                   j                  S ©N)ÚparentÚosÚgetcwdr4   ©Úselfs    r,   Ú_default_root_dirz%FileContentsManager._default_root_dirO   s%   € à�{Š{Ü—9‘9“;ÐØ�{‰{×#Ñ#Ð#r.   c                óæ   — |d   }t         j                  j                  |«      st         j                  j                  |«      }t         j                  j	                  |«      st        d|z  «      ‚|S )NÚvaluez%r is not a directory)r8   ÚpathÚisabsÚabspathÚisdirr   )r;   Úproposalr>   s      r,   Ú_validate_root_dirz&FileContentsManager._validate_root_dirU   sT   € à˜Ñ!ˆÜ�w‰w�}‰}˜UÔ#ä—G‘G—O‘O EÓ*ˆEÜ�w‰w�}‰}˜UÔ#ÜÐ4°uÑ<Ó=Ð=Øˆr.   Úpreferred_dirc                ó~  — | j                   sy	 | j                   j                  }|| j                   j                  k(  rd }|�Qt        j                  dt
        d¬«       	 t        |«      }|j                  | j                  «      j                  «       S y# t        $ r t        d|z  «      d ‚w xY w# t        $ r Y yw xY w)NÚ zqServerApp.preferred_dir config is deprecated in jupyter-server 2.0. Use FileContentsManager.preferred_dir insteadé   )Ú
stacklevelz%%s is outside root contents directory)r7   rE   r4   ÚwarningsÚwarnÚFutureWarningr   Úrelative_toÚas_posixÚ
ValueErrorr   ÚAttributeError)r;   r>   r?   s      r,   Ú_default_preferred_dirz*FileContentsManager._default_preferred_dir_   sÉ   € à�{Š{Øð	`Ø—K‘K×-Ñ-ˆEØ˜Ÿ™×,Ñ,Ò,Ø�ð Ð Ü—‘ð HÜ!Ø õð
`Ü ›;�DØ×+Ñ+¨D¯M©MÓ:×CÑCÓEÐEð øô "ò `Ü$Ð%LÈuÑ%TÓUÐ[_Ð_ð`ûô ò 	Øð ð	ús   �1B0 Á3B ÂB-Â0	B<Â;B<c                óZ   •— t        |d   | j                  «      |d<   t        ‰| �  |«      S )Nr>   )r   r4   ÚsuperÚ_validate_preferred_dir)r;   rC   Ú	__class__s     €r,   rT   z+FileContentsManager._validate_preferred_dirw   s/   ø€ ô (¨°Ñ(9¸4¿=¹=ÓIˆ�ÑÜ‰wÑ.¨xÓ8Ð8r.   Úcheckpoints_classc                ó   — t         S r6   )r   r:   s    r,   Ú_checkpoints_class_defaultz.FileContentsManager._checkpoints_class_default}   s   € äÐr.   z°If True (default), deleting files will send them to the
        platform's trash/recycle bin, where they can be recovered. If False,
        deleting files really deletes them.Fa¥  If True, deleting a non-empty directory will always be allowed.
        WARNING this may result in files being permanently removed; e.g. on Windows,
        if the data size is too big for the trash/recycle bin the directory will be permanently
        deleted. If False (default), the non-empty directory will be sent to the trash only
        if safe. And if ``delete_to_trash`` is True, the directory won't be deleted.Úfiles_handler_classc                ó   — t         S r6   r   r:   s    r,   Ú_files_handler_class_defaultz0FileContentsManager._files_handler_class_default“   s   € ä'Ð'r.   Úfiles_handler_paramsc                ó   — d| j                   iS )Nr?   )r4   r:   s    r,   Ú_files_handler_params_defaultz1FileContentsManager._files_handler_params_default—   s   € à˜Ÿ™Ð&Ð&r.   c                ót   — |j                  d«      }| j                  |¬«      }t        || j                  «      S )aT  Does the API style path correspond to a hidden directory or file?

        Parameters
        ----------
        path : str
            The path to check. This is an API path (`/` separated,
            relative to root_dir).

        Returns
        -------
        hidden : bool
            Whether the path exists and is hidden.
        Ú/©r?   ©ÚstripÚ_get_os_pathr	   r4   ©r;   r?   Úos_paths      r,   r	   zFileContentsManager.is_hidden›   s5   € ð �z‰z˜#‹ˆØ×#Ñ#¨Ð#Ó.ˆÜ˜ $§-¡-Ó0Ð0r.   c                óè   — |j                  d«      }| j                  |¬«      }	 t        j                  |t        j                  «      S # t
        $ r | j                  j                  d|«       Y yw xY w)aX  Does the API style path correspond to a writable directory or file?

        Parameters
        ----------
        path : str
            The path to check. This is an API path (`/` separated,
            relative to root_dir).

        Returns
        -------
        hidden : bool
            Whether the path exists and is writable.
        r`   ra   z'Failed to check write permissions on %sF)rc   rd   r8   ÚaccessÚW_OKÚOSErrorÚlogÚerrorre   s      r,   Úis_writablezFileContentsManager.is_writable­   sc   € ð �z‰z˜#‹ˆØ×#Ñ#¨Ð#Ó.ˆð	Ü—9‘9˜W¤b§g¡gÓ.Ð.øÜò 	Ø�H‰H�N‰NÐDÀgÔNÙð	ús   ¥#A	 Á	%A1Á0A1c                ó„   — |j                  d«      }| j                  |«      }t        j                  j	                  |«      S )aC  Returns True if the file exists, else returns False.

        API-style wrapper for os.path.isfile

        Parameters
        ----------
        path : str
            The relative path to the file (with '/' as separator)

        Returns
        -------
        exists : bool
            Whether the file exists.
        r`   ©rc   rd   r8   r?   Úisfilere   s      r,   Úfile_existszFileContentsManager.file_existsÃ   s4   € ð �z‰z˜#‹ˆØ×#Ñ# DÓ)ˆÜ�w‰w�~‰~˜gÓ&Ð&r.   c                ó†   — |j                  d«      }| j                  |¬«      }t        j                  j	                  |«      S )av  Does the API-style path refer to an extant directory?

        API-style wrapper for os.path.isdir

        Parameters
        ----------
        path : str
            The path to check. This is an API path (`/` separated,
            relative to root_dir).

        Returns
        -------
        exists : bool
            Whether the path is indeed a directory.
        r`   ra   ©rc   rd   r8   r?   rB   re   s      r,   Ú
dir_existszFileContentsManager.dir_existsÖ   s7   € ð  �z‰z˜#‹ˆØ×#Ñ#¨Ð#Ó.ˆÜ�w‰w�}‰}˜WÓ%Ð%r.   c                ó^   — |j                  d«      }| j                  |¬«      }t        |«      S )a@  Returns True if the path exists, else returns False.

        API-style wrapper for os.path.exists

        Parameters
        ----------
        path : str
            The API path to the file (with '/' as separator)

        Returns
        -------
        exists : bool
            Whether the target exists.
        r`   ra   )rc   rd   r   re   s      r,   r   zFileContentsManager.existsê   s.   € ð �z‰z˜#‹ˆØ×#Ñ#¨Ð#Ó.ˆÜ�g‹Ðr.   c                ó2  — t        |«      }	 |j                  «       }||k7  r‡|j                  «       rwt        t        j
                  j                  | j                  «      «      }t        t        j
                  j                  |«      «      }	 |j                  |«       t        |«      }t        || j                  «      }	 | j                  |¬«      }t        |«      r|S y# t        $ r |}Y ŒÐw xY w# t        $ r Y yw xY w# t        j                  $ r Y yw xY w)z'Resolve path relative to root resource.Nra   )r   Ú
expanduserÚRuntimeErrorÚis_absoluter8   r?   rA   r4   rM   rO   Ústrr   rd   r   Ú	HTTPErrorr   )r;   r?   Úoriginal_pathÚexpanded_pathÚrootÚexpanded_absÚrelative_pathrf   s           r,   Úresolve_pathz FileContentsManager.resolve_pathý   s   € ô ˜T›
ˆð	*Ø)×4Ñ4Ó6ˆMð ˜MÒ)¨m×.GÑ.GÔ.IÜœŸ™Ÿ™¨¯©Ó6Ó7ˆDÜ¤§¡§¡°Ó >Ó?ˆLðØ×(Ñ(¨Ô.ô �|Ó$ˆDÜ# D¨$¯-©-Ó8ˆð	Ø×'Ñ'¨]Ð'Ó;ˆGô �'Œ?Ø Ð Øøô% ò 	*Ø)ŠMð	*ûô ò Ùðûô �}‰}ò 	Ùð	ús5   �C  ÂC1 Ã D  Ã C.Ã-C.Ã1	C=Ã<C=Ä DÄDc           	     ó*  — | j                  |«      }t        j                  |«      }d|z  }| j                  sHt	        || j
                  «      r2| j                  j                  d|«       t        j                  d|«      ‚	 |j                  }	 t        j                  |j                   «      }t)        |«      }	 t        j                  |«      }i }	|j+                  dd«      d   |	d<   ||	d<   ||	d<   ||	d<   d|	d<   d|	d<   d|	d<   ||	d<   | j-                  |«      |	d<   d|	d<   d|	d<   |	S # t        t        f$ r  | j                  j                  d«       d}Y ŒÌw xY w# t        t"        t        f$ rJ | j                  j                  d|j                   |«       t%        dddd	d	t        j&                  ¬
«      }Y �Œw xY w# t        t"        t        f$ r@ | j                  j                  d||«       t%        dddd	d	t        j&                  ¬
«      }Y �ŒCw xY w)z)Build the common base of a contents modelú$file or directory does not exist: %rú<Refusing to serve hidden file or directory %r, via 404 Erroré”  zUnable to get size.NzInvalid mtime %s for %si²  r   r   )ÚtzinfozInvalid creation time %s for %sr`   éÿÿÿÿÚnamer?   Úlast_modifiedÚcreatedÚcontentÚformatÚmimetypeÚsizeÚwritableÚhashÚhash_algorithm)rd   r8   ÚlstatÚallow_hiddenr	   r4   rk   r*   r   r{   Úst_sizerO   rj   ÚwarningÚtzÚutcfromtimestampÚst_mtimeÚOverflowErrorr   ÚUTCr-   Úrsplitrm   )
r;   r?   rf   r*   Úfour_o_fourrŽ   r‰   Úraw_createdrŠ   Úmodels
             r,   Ú_base_modelzFileContentsManager._base_model  s  € à×#Ñ# DÓ)ˆÜ�x‰x˜Ó ˆà<¸tÑCˆà× Ò ¤Y¨w¸¿¹Ô%FØ�H‰H�M‰MÐXÐZaÔbÜ—-‘-  [Ó1Ð1ð	à—<‘<ˆDð
	FÜ×/Ñ/°·±Ó>ˆMô -¨TÓ2ˆð	@Ü×)Ñ)¨+Ó6ˆGð ˆØŸ™ C¨Ó+¨BÑ/ˆˆf‰Øˆˆf‰Ø!.ˆˆoÑØ"ˆˆiÑØˆˆiÑØˆˆh‰Ø ˆˆjÑØˆˆf‰Ø ×,Ñ,¨TÓ2ˆˆjÑØˆˆf‰Ø"&ˆÐÑàˆøôG œGÐ$ò 	Ø�H‰H×ÑÐ2Ô3ØŠDð	ûô œM¬7Ð3ò 	Fð
 �H‰H×ÑÐ6¸¿¹ÀwÔOÜ$ T¨1¨a°°A¼b¿f¹fÔE‹Mð	Fûô œM¬7Ð3ò 	@Ø�H‰H×ÑÐ>ÀÈWÔUÜ˜t Q¨¨1¨a¼¿¹Ô?‹Gð	@ús8   ÂD+ ÂE Â9F> Ä+,EÅEÅAF;Æ:F;Æ>AHÈHc                ó  — | j                  |«      }d|z  }t        j                  j                  |«      st	        j
                  d|«      ‚| j                  sHt        || j                  «      r2| j                  j                  d|«       t	        j
                  d|«      ‚| j                  |«      }d|d<   d|d<   |�r-g x|d<   }|}t        j                  |«      D �]  }	 t        j                  j                  ||«      }	 t        j                   |«      }
t+        j,                  |
j.                  «      s[t+        j0                  |
j.                  «      s<t+        j2                  |
j.                  «      s| j                  j5                  d|«       Œµ	 | j7                  |«      r@| j                  st9        ||
¬«      s'|j;                  | j=                  |› d|› �d¬«      «       �Œ	 d|d<   |S # t        $ r(}	| j                  j                  d	||	«       Y d}	~	�Œ=d}	~	ww xY w# t"        $ r}	|	j$                  t$        j&                  k(  r| j                  j                  d
|«       n:|	j$                  t$        j(                  k7  r| j                  j                  d||	«       Y d}	~	�ŒÈd}	~	ww xY w# t"        $ rU}	|	j$                  t$        j>                  t$        j(                  fvr| j                  j                  d|d¬«       Y d}	~	�Œ)d}	~	ww xY w©zpBuild a model for a directory

        if content is requested, will include a listing of the directory
        zdirectory does not exist: %rr…   z4Refusing to serve hidden directory %r, via 404 ErrorÚ	directoryÚtypeNrŽ   r‹   z"failed to decode filename '%s': %rz%s doesn't existzError stat-ing %s: %rz%s not a regular file)Ústat_resr`   F)r?   r‹   z+Unknown error checking if file %r is hiddenT©Úexc_infoÚjsonrŒ   ) rd   r8   r?   rB   r   r{   r“   r	   r4   rk   r*   rŸ   ÚlistdirÚjoinÚUnicodeDecodeErrorr•   r’   rj   ÚerrnoÚENOENTÚEACCESÚstatÚS_ISLNKÚst_modeÚS_ISREGÚS_ISDIRÚdebugÚshould_listr   ÚappendÚgetÚELOOP)r;   r?   r‹   rf   rœ   rž   ÚcontentsÚos_dirrˆ   ÚeÚsts              r,   Ú
_dir_modelzFileContentsManager._dir_modelJ  sp  € ð
 ×#Ñ# DÓ)ˆà4°tÑ;ˆä�w‰w�}‰}˜WÔ%Ü—-‘-  [Ó1Ð1Ø×"Ò"¤y°¸$¿-¹-Ô'HØ�H‰H�M‰MÐPÐRYÔZÜ—-‘-  [Ó1Ð1à× Ñ  Ó&ˆØ#ˆˆf‰Øˆˆf‰ÚØ*,Ð,ˆE�)Ñ˜xØˆFÜŸ
™
 6×*�ðÜ Ÿg™gŸl™l¨6°4Ó8�Gð
ÜŸ™ 'Ó*�Bô Ÿ™ R§Z¡ZÔ0Ü ŸL™L¨¯©Ô4Ü ŸL™L¨¯©Ô4à—H‘H—N‘NÐ#:¸GÔDØðØ×'Ñ'¨Ô-Ø×)Ò)´ÀÐRTÕ1Uà Ÿ™¨¯©¸¸¸aÀ¸vÐ6FÐPU¨Ó(VÔWùð; +ðN %ˆE�(‰OàˆøôM *ò Ø—H‘H×$Ñ$Ð%IÈ4ÐQRÔSÝûðûô ò à—w‘w¤%§,¡,Ò.ØŸ™×(Ñ(Ð);¸WÕEØŸ™¤E§L¡LÒ0ØŸ™×(Ñ(Ð)@À'È1ÔMÝûðûô* ò à—w‘w¤u§{¡{´E·L±LÐ&AÑAØŸ™×(Ñ(ØIØ#Ø%)ð )ô ÿùðúsK   Ã! G-ÄH!ÆAJ,Ç-	HÇ6HÈHÈ!	J)È*A4J$Ê$J)Ê,	L
Ê5A
LÌL
c                ó€  — | j                  |«      }d|d<   | j                  |«      }t        j                  |«      d   |d<   d}|r=| j	                  ||d¬«      \  }}}|d   €dd	d
œ|   }||d<   |j                  ||¬«       |r8|€| j	                  |d«      \  }}	 |j
                  di | j                  |«      ¤Ž |S ©a€  Build a model for a file

        if content is requested, include the file contents.

        format:
          If 'text', the contents will be decoded as UTF-8.
          If 'base64', the raw bytes contents will be encoded as base64.
          If not specified, try to decode as UTF-8, and fall back to base64

        if require_hash is true, the model will include 'hash'
        Úfiler£   r   r�   NT)Úrawz
text/plainzapplication/octet-stream)ÚtextÚbase64)r‹   rŒ   Úbyte© ©rŸ   rd   Ú	mimetypesÚ
guess_typeÚ
_read_fileÚupdateÚ	_get_hash©
r;   r?   r‹   rŒ   Úrequire_hashrž   rf   Úbytes_contentÚdefault_mimeÚ_s
             r,   Ú_file_modelzFileContentsManager._file_modelŠ  sï   € ð × Ñ  Ó&ˆØˆˆf‰à×#Ñ# DÓ)ˆÜ%×0Ñ0°Ó9¸!Ñ<ˆˆjÑàˆÙØ-1¯_©_¸WÀfÐRV¨_Ó-WÑ*ˆG�V˜]Ø�ZÑ Ð(à(Ø8ñ ð ñ �ð %1��jÑ!à�L‰LØØð ô ñ
 ØÐ$Ø#'§?¡?°7¸FÓ#CÑ �˜qØˆE�L‰LÑ9˜4Ÿ>™>¨-Ó8Ò9àˆr.   c                ó`  — | j                  |«      }d|d<   | j                  |«      }d}|rHi }| j                  |d|d¬«      \  }}| j                  ||«       ||d<   d|d	<   | j	                  ||«       |r8|€| j                  |d
«      \  }}	 |j                  di | j                  |«      ¤Ž |S )zÜBuild a notebook model

        if content is requested, the notebook content will be populated
        as a JSON structure (not double-serialized)

        if require_hash is true, the model will include 'hash'
        Únotebookr£   Né   T©Ú
as_versionÚcapture_validation_errorrÀ   r‹   r§   rŒ   rÃ   rÄ   ©rŸ   rd   Ú_read_notebookÚmark_trusted_cellsÚvalidate_notebook_modelrÈ   rÉ   rÊ   ©
r;   r?   r‹   rÌ   rž   rf   rÍ   Úvalidation_errorÚnbrÏ   s
             r,   Ú_notebook_modelz#FileContentsManager._notebook_model²  sÓ   € ð × Ñ  Ó&ˆØ"ˆˆf‰Ø×#Ñ# DÓ)ˆàˆÙØ13ÐØ $× 3Ñ 3Ø AÐ@PÐVZð !4ó !ÑˆB�ð ×#Ñ# B¨Ô-Ø!ˆE�)ÑØ$ˆE�(‰OØ×(Ñ(¨Ð0@ÔAáØÐ$Ø#'§?¡?°7¸FÓ#CÑ �˜qØˆE�L‰LÑ9˜4Ÿ>™>¨-Ó8Ò9àˆr.   c                óà  — |j                  d«      }| j                  |«      }d|z  }| j                  |«      st        j                  d|«      ‚| j
                  sHt        || j                  «      r2| j                  j                  d|«       t        j                  d|«      ‚t        j                  j                  |«      r5|dvrt        j                  d|› d|› �d¬	«      ‚| j                  ||¬
«      }nb|dk(  s|€&|j                  d«      r| j                  |||¬«      }n5|dk(  rt        j                  dd|z  d¬	«      ‚| j!                  ||||¬«      }| j#                  d|dœ¬«       |S )áh  Takes a path for an entity and returns its model

        Parameters
        ----------
        path : str
            the API path that describes the relative path for the target
        content : bool
            Whether to include the contents in the reply
        type : str, optional
            The requested type - 'file', 'notebook', or 'directory'.
            Will raise HTTPError 400 if the content doesn't match.
        format : str, optional
            The requested format for file contents. 'text' or 'base64'.
            Ignored if this returns a notebook or directory model.
        require_hash: bool, optional
            Whether to include the hash of the file contents.

        Returns
        -------
        model : dict
            the contents model. If content=True, returns the contents
            of the file or directory as well.
        r`   rƒ   r…   r„   ©Nr¢   é�  ú is a directory, not a úbad type©Úreason©r‹   rÒ   ú.ipynb©r‹   rÌ   r¢   ú%s is not a directory©r‹   rŒ   rÌ   r¶   ©Úactionr?   ©Údata)rc   rd   r   r   r{   r“   r	   r4   rk   r*   r8   r?   rB   r¼   ÚendswithrÞ   rÐ   Úemit)	r;   r?   r‹   r£   rŒ   rÌ   rf   rœ   rž   s	            r,   r¶   zFileContentsManager.getÐ  s^  € ð0 �z‰z˜#‹ˆØ×#Ñ# DÓ)ˆØ<¸tÑCˆà�{‰{˜4Ô Ü—-‘-  [Ó1Ð1à× Ò ¤Y¨w¸¿¹Ô%FØ�H‰H�M‰MÐXÐZaÔbÜ—-‘-  [Ó1Ð1ä�7‰7�=‰=˜Ô!ØÐ.Ñ.Ü—m‘mØØ�fÐ3°D°6Ð:Ø%ôð ð
 —O‘O D°'�OÓ:‰EØ�ZÒ D L°T·]±]À8Ô5LØ×(Ñ(¨°wÈ\Ð(ÓZ‰Eà�{Ò"Ü—m‘m CÐ)@À4Ñ)GÐPZÔ[Ð[Ø×$Ñ$Ø˜g¨fÀ<ð %ó ˆEð 	�	‰	 %°Ñ6ˆ	Ô7Øˆr.   c                óÖ  — | j                   s/t        || j                  «      rt        j                  dd|z  «      ‚t
        j                  j                  |«      s/| j                  «       5  t        j                  |«       ddd«       yt
        j                  j                  |«      st        j                  dd|z  «      ‚| j                  j                  d|«       y# 1 sw Y   yxY w)úcreate a directoryrâ   zCannot create directory %rNúNot a directory: %súDirectory %r already exists)r“   r	   r4   r   r{   r8   r?   r   Úperm_to_403ÚmkdirrB   rk   r³   ©r;   rf   rž   r?   s       r,   Ú_save_directoryz#FileContentsManager._save_directory  s¢   € à× Ò ¤Y¨w¸¿¹Ô%FÜ—-‘- Ð%AÀGÑ%KÓLÐLÜ�w‰w�~‰~˜gÔ&Ø×!Ñ!Õ#Ü—‘˜Ô!÷ $Ð#ä—‘—‘˜wÔ'Ü—-‘- Ð%:¸gÑ%FÓGÐGà�H‰H�N‰NÐ8¸'ÕB÷ $Ð#ús   Á+CÃC(c                óð  — |j                  d«      }| j                  ||¬«       d|vrt        j                  dd«      ‚d|vr|d   dk7  rt        j                  dd«      ‚| j	                  |«      }| j
                  s/t        || j                  «      rt        j                  dd	|›�«      ‚| j                  j                  d
|«       i }	 |d   dk(  rkt        j                  |d   «      }| j                  ||«       | j                  |||¬«       | j                  j                  |«      sx| j!                  |«       nf|d   dk(  r&| j#                  ||d   |j%                  d«      «       n8|d   dk(  r| j'                  |||«       nt        j                  dd|d   z  «      ‚d}|d   dk(  r%| j-                  ||¬«       |j%                  dd«      }| j%                  |d¬«      }|r||d<   | j/                  ||¬«       | j1                  d|dœ¬«       |S # t        j                  $ r ‚ t(        $ rA}| j                  j+                  d||d¬«       t        j                  dd|› d|› �«      |‚d}~ww xY w)ú9Save the file model and return the model with no content.r`   ©rž   r?   r£   râ   úNo file type providedr‹   r¢   úNo file content providedz Cannot create file or directory ú	Saving %srÒ   ©rÖ   r¿   rŒ   úUnhandled contents type: %súError while saving file: %s %sTr¥   r2   ú$Unexpected error while saving file: Ú N©rÜ   ÚmessageFrç   ©rž   rf   Úsaverì   rî   )rc   Úrun_pre_save_hooksr   r{   rd   r“   r	   r4   rk   r³   ÚnbformatÚ	from_dictÚcheck_and_signÚ_save_notebookÚcheckpointsÚlist_checkpointsÚcreate_checkpointÚ
_save_filer¶   rù   Ú	Exceptionrl   rÚ   Úrun_post_save_hooksrñ   ©r;   rž   r?   rf   rÜ   rÝ   rº   Úvalidation_messages           r,   r  zFileContentsManager.save  sn  € à�z‰z˜#‹ˆà×Ñ e°$ÐÔ7à˜ÑÜ—-‘- Ð%<Ó=Ð=Ø˜EÑ! e¨F¡m°{Ò&BÜ—-‘- Ð%?Ó@Ð@Ø×#Ñ# DÓ)ˆà× Ò ¤Y¨w¸¿¹Ô%FÜ—-‘- Ð'GÈÀ{Ð%SÓTÐTà�‰�‰�{ GÔ,à-/Ðð	_Ø�V‰} 
Ò*Ü×'Ñ'¨¨iÑ(8Ó9�Ø×#Ñ# B¨Ô-Ø×#Ñ# G¨RÐJZÐ#Ô[à×'Ñ'×8Ñ8¸Ô>Ø×*Ñ*¨4Õ0Ø�v‘ &Ò(à—‘ ¨¨yÑ)9¸5¿9¹9ÀXÓ;NÕOØ�v‘ +Ò-Ø×$Ñ$ W¨e°TÕ:ä—m‘m CÐ)FÈÈvÉÑ)VÓWÐWð "ÐØ�‰=˜JÒ&Ø×(Ñ(¨ÐAQÐ(ÔRØ!&§¡¨9°dÓ!;Ðà—‘˜ u�Ó-ˆÙØ1ˆE�)Ñà× Ñ  u°gÐ Ô>Ø�	‰	 &°$Ñ7ˆ	Ô8Øˆøô# �}‰}ò 	ØÜò 	_Ø�H‰H�N‰NÐ;¸TÀ1ÈtˆNÔTÜ—-‘- Ð'KÈDÈ6ÐQRÐSTÐRUÐ%VÓWÐ]^Ð^ûð	_ús   ÃCH ÈI5È4<I0É0I5c                ó°  ‡ — |j                  d«      }‰ j                  |«      }t        j                  }‰ j                  s/t        |‰ j                  «      rt        j                  dd|›�«      ‚d|z  }‰ j                  |«      st        j                  d|«      ‚ˆ fd„}‰ j                  r”‰ j                  s4t        j                  dk(  r! ||«      rt        j                  dd|z  «      ‚‰ j                  |«      st        j                  d	d
|z  «      d‚‰ j                  j!                  d|«       	 t#        |«       yt        j&                  j)                  |«      rx‰ j                  s! ||«      rt        j                  dd|z  «      ‚‰ j                  j!                  d|«       ‰ j+                  «       5  t-        j.                  |«       ddd«       y‰ j                  j!                  d|«       ‰ j+                  «       5   ||«       ddd«       y# t$        $ r}t        j                  dd|z  «      |‚d}~ww xY w# 1 sw Y   yxY w# 1 sw Y   yxY w)úDelete file at path.r`   râ   ú Cannot delete file or directory rƒ   r…   c                ó¸   •— t         j                  j                  | «      r:t        ‰j                  dd «      }t        t        j                  | «      «      |hz
  ryy©NÚcheckpoint_dirTF)r8   r?   rB   r#   r  Úsetr¨   )rf   Úcp_dirr;   s     €r,   Úis_non_empty_dirz9FileContentsManager.delete_file.<locals>.is_non_empty_dirS  sH   ø€ Ü�w‰w�}‰}˜WÔ%ô ! ×!1Ñ!1Ð3CÀTÓJ�Ü”r—z‘z 'Ó*Ó+¨v¨hÒ6Øàr.   Úwin32úDirectory %s not emptyé“  úPermission denied: %sNúSending %s to trashúsend2trash failed: %súRemoving directory %súUnlinking file %s)rc   rd   r8   Úunlinkr“   r	   r4   r   r{   r   Údelete_to_trashÚalways_delete_dirÚsysÚplatformrm   rk   r³   r
   rj   r?   rB   rö   ÚshutilÚrmtree)r;   r?   rf   Úrmrœ   r  rº   s   `      r,   Údelete_filezFileContentsManager.delete_fileF  sì  ø€ à�z‰z˜#‹ˆØ×#Ñ# DÓ)ˆÜ�Y‰Yˆà× Ò ¤Y¨w¸¿¹Ô%FÜ—-‘- Ð'GÈÀ{Ð%SÓTÐTà<¸tÑCˆØ�{‰{˜4Ô Ü—-‘-  [Ó1Ð1ô	ð ×ÒØ×)Ò)¬c¯l©l¸gÒ.EÑJZÐ[bÔJcô —m‘m CÐ)AÀGÑ)KÓLÐLà×#Ñ# DÔ)Ü—m‘m CÐ)@À4Ñ)GÓHÈdÐRØ�H‰H�N‰NÐ0°'Ô:ðMÜ˜7Ô#ð ä�7‰7�=‰=˜Ô!à×)Ò)Ñ.>¸wÔ.GÜ—m‘m CÐ)AÀGÑ)KÓLÐLØ�H‰H�N‰NÐ2°GÔ<Ø×!Ñ!Õ#Ü—‘˜gÔ&÷ $Ð#ð �H‰H�N‰NÐ.°Ô8Ø×!Ñ!Õ#Ù�7”÷ $Ð#øô ò MÜ—m‘m CÐ)@À1Ñ)DÓEÈ1ÐLûðMú÷ $Ð#ú÷ $Ð#ús0   Ä4H Æ8I È	IÈ	H=ÈH8È8H=É I	ÉIc                ó   — |j                  d«      }|j                  d«      }||k(  ry| j                  |«      }| j                  |«      }| j                  sEt        || j                  «      st        || j                  «      rt        j                  dd|›�«      ‚t        j                  j                  |«      r%t        ||«      st        j                  dd|z  «      ‚	 | j                  «       5  t        j                  ||«       ddd«       y# 1 sw Y   yxY w# t
        j                  $ r ‚ t        $ r t        j                  dd|› �«      d‚t        $ r"}t        j                  d	d
|› d|› �«      |‚d}~ww xY w©zRename a file.r`   Nrâ   z Cannot rename file or directory i™  zFile already exists: %sr…   z"File or directory does not exist: r2   zUnknown error renaming file: r  )rc   rd   r“   r	   r4   r   r{   r8   r?   r   r   rö   r,  ÚmoveÚFileNotFoundErrorr  ©r;   Úold_pathÚnew_pathÚnew_os_pathÚold_os_pathrº   s         r,   Úrename_filezFileContentsManager.rename_filex  sL  € à—>‘> #Ó&ˆØ—>‘> #Ó&ˆØ�xÒØà×'Ñ'¨Ó1ˆØ×'Ñ'¨Ó1ˆà× Ò Ü�k 4§=¡=Ô1´Y¸{ÈDÏMÉMÔ5Zä—-‘- Ð'GÈÀÐ%WÓXÐXô �7‰7�>‰>˜+Ô&¬x¸À[Ô/QÜ—-‘- Ð%>ÀÑ%IÓJÐJð	\Ø×!Ñ!Õ#Ü—‘˜K¨Ô5÷ $×#Ñ#ûä�}‰}ò 	ØÜ ò 	`Ü—-‘- Ð'IÈ(ÈÐ%TÓUÐ[_Ð_Üò 	\Ü—-‘- Ð'DÀXÀJÈaÐPQÈsÐ%SÓTÐZ[Ð[ûð	\ús6   Ã!D Ã1DÄD ÄDÄD ÄD Ä>E=ÅE8Å8E=c                ó2   — t        d«      | j                  z  S )z+Get the information string for the manager.z*Serving notebooks from local directory: %s)r   r4   r:   s    r,   Úinfo_stringzFileContentsManager.info_string–  s   € äÐAÓBÀTÇ]Á]ÑRÐRr.   c                óf   — | j                  |«      r|S d|v r|j                  dd«      d   }|S d}|S )zIReturn the initial API path of  a kernel associated with a given notebookr`   r   r   rG   ©rt   r›   ©r;   r?   rž   Ú
parent_dirs       r,   Úget_kernel_pathz#FileContentsManager.get_kernel_pathš  sC   € à�?‰?˜4Ô ØˆKØ/2°d©{�T—[‘[  aÓ(¨Ñ+ˆ
ØÐð ACˆ
ØÐr.   c                óü  •— t        |«      }|j                  d«      }|�|j                  d«      }d|v r|j                  dd«      \  }}nd}|}| j                  |«      }|d   dk(  r| j	                  |«       nt
        ‰| �  ||¬«      S |du}t        j                  d|«      }	|s|}| j                  |«      r(t        j                  d|«      }
t
        ‰| �)  |
|d	¬
«      }	|› d|	› �}| j                  |||	|¬«      S ©aA  
        Copy an existing file or directory and return its new model.
        If to_path not specified, it will be the parent directory of from_path.
        If copying a file and to_path is a directory, filename/directoryname will increment `from_path-Copy#.ext`.
        Considering multi-part extensions, the Copy# part will be placed before the first dot for all the extensions except `ipynb`.
        For easier manual searching in case of notebooks, the Copy# part will be placed before the last dot.
        from_path must be a full path to a file or directory.
        r`   Nr   rG   r£   r¢   )Ú	from_pathÚto_pathÚ.z-Copy)Úinsert)rC  Úto_path_originalÚto_namerD  )rz   rc   r›   r¶   Úcheck_folder_sizerS   Úcopyr   Úsubrt   Úincrement_filenameÚ	_copy_dir©r;   rC  rD  rG  r?   Úfrom_dirÚ	from_namerž   Úis_destination_specifiedrH  rˆ   rU   s              €r,   rJ  zFileContentsManager.copy¡  s  ø€ ô ˜w›<ÐØ�‰˜sÓ#ˆØÐØ—m‘m CÓ(ˆGà�$‰;Ø"&§+¡+¨c°1Ó"5ÑˆH‘iàˆHØˆIà—‘˜“ˆà�‰=˜KÒ'Ø×"Ñ" 4Õ(ô ‘7‘<¨)¸W�<ÓEÐEà#*°$Ð#6Ð Ü—,‘,˜s IÓ.ˆÙ'ØˆGØ�?‰?˜7Ô#Ü—<‘<  YÓ/ˆDÜ‘gÑ0°°wÀwÐ0ÓOˆGØ�I˜Q˜w˜iÐ(ˆà�~‰~ØØ-ØØð	 ó 
ð 	
r.   c           	     ó~  — 	 | j                  |j                  d«      «      }| j                  |j                  d«      «      › d|› �}t        j                  ||«       | j	                  |d¬«      }|S # t
        $ rA}| j                  j                  d|› �«       t        j                  dd|› d|› d�«      |‚d	}~ww xY w)
ú`
        handles copying directories
        returns the model for the copied directory
        r`   Frç   úOSError in _copy_dir: râ   úCan't copy 'z' into Folder 'Ú'N©
rd   rc   r,  Úcopytreer¶   rj   rk   rl   r   r{   ©	r;   rC  rG  rH  rD  Úos_from_pathÚ
os_to_pathrž   Úerrs	            r,   rM  zFileContentsManager._copy_dirÍ  sÄ   € ð

	Ø×,Ñ,¨Y¯_©_¸SÓ-AÓBˆLØ ×-Ñ-Ð.>×.DÑ.DÀSÓ.IÓJÐKÈ1ÈWÈIÐVˆJÜ�O‰O˜L¨*Ô5Ø—H‘H˜W¨e�HÓ4ˆEð ˆøô ò 	Ø�H‰H�N‰NÐ3°C°5Ð9Ô:Ü—-‘-ØØ˜y˜k¨¸¸	ÀÐCóð ðûð	ús   ‚A.A2 Á2	B<Á;<B7Â7B<c                ó2  — | j                   dz  dz  }t        | j                  | j                  |«      «      «      }t	        j
                  «       dk(  r|dz  n|}||kD  r9t        j                  dd| j                   › d|› d| j                  |«      › d�«      ‚y)	ú�
        limit the size of folders being copied to be no more than the
        trait max_copy_folder_size_mb to prevent a timeout error
        é   ÚDarwinrâ   ú4
                    Can't copy folders larger than úMB,
                    "ú" is ú
                N©	Úmax_copy_folder_size_mbr%   Ú_get_dir_sizerd   r+  Úsystemr   r{   Ú_human_readable_size©r;   r?   Úlimit_bytesrŽ   s       r,   rI  z%FileContentsManager.check_folder_sizeà  s¬   € ð
 ×2Ñ2°TÑ9¸DÑ@ˆÜ�4×%Ñ% d×&7Ñ&7¸Ó&=Ó>Ó?ˆä&Ÿo™oÓ/°8Ò;ˆt�dŠ{Àˆà�+ÒÜ—-‘-Øð4Ø48×4PÑ4PÐ3Qð RØ�V˜5 ×!:Ñ!:¸4Ó!@Ð Að Bðóð ð r.   c                óÀ  — 	 t        j                  «       dk(  r4t        j                  dd|gdd¬«      j                  j                  «       }n4t        j                  ddd|gdd¬«      j                  j                  «       }| j                  j                  d|› �«       |d	   j                  d
«      }|S # t        $ r | j                  j                  d|«       Y yw xY w)úM
        calls the command line program du to get the directory size
        r`  Úduú-skT)Úcapture_outputÚcheckú-sú--block-size=1úcurrent status of du command r   úutf-8ú^Not able to get the size of the %s directory. Copying might be slow if the directory is large!Ú0)r+  rh  Ú
subprocessÚrunÚstdoutÚsplitrk   r*   Údecoder  r•   )r;   r?   ÚresultrŽ   s       r,   rg  z!FileContentsManager._get_dir_sizeó  sÚ   € ð	Ü�‰Ó  HÒ,ä#Ÿ™Ø˜5 $Ð'Ø#'Øô÷ ‘&Ÿ™›ñ	 ô $Ÿ™Ø˜4Ð!1°4Ð8Ø#'Øô÷ ‘&Ÿ™›ð	 ð �H‰H�M‰MÐ9¸&¸ÐBÔCØ˜!‘9×#Ñ# GÓ,ˆDð ˆøô ò 	Ø�H‰H×ÑØpØôñ ð	ús   ‚B1B5 Â5%CÃCc                óˆ   — |dk(  ryg d¢}|r!t        t        j                  |«      dz  «      nd}|d|dz  z  z  d›d||   › �S ©z@
        returns folder size in a human readable format
        r   z0 Bytes)ÚBytesÚKBÚMBÚGBÚTBÚPBé
   r   z.4gr  ©r%   r'   Úlog2©r;   rŽ   ÚunitsÚorders       r,   ri  z(FileContentsManager._human_readable_size  sT   € ð �1Š9Øâ7ˆÙ-1””D—I‘I˜d“O bÑ(Ô)°qˆà˜! ¨¡
Ñ+Ñ,¨SÐ1°°5¸±<°.ÐAÐAr.   )r?   rz   Úreturnzbool | t.Awaitable[bool])r?   rz   rŒ  z
str | None©T©TNF©TF©TNNF©rG   r6   ©rE  )+Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r4   r   rf  r   r<   r   rD   rQ   rT   rX   r   r(  r)  r[   r^   r	   rm   rq   rt   r   r�   rŸ   r¼   rÐ   rÞ   r¶   rù   r  r/  r9  r;  r@  rJ  rM  rI  rg  ri  Ú__classcell__©rU   s   @r,   r0   r0   H   sy  ø„ Ù"á˜dÔ#€Há! #¨dÐ9aÔbÐáˆZÓñ$ó ð$ñ
 ˆjÓñó ðñ ˆ_Óñó ðñ. ˆoÓó9ó ð9ñ
 Ð Ó!ñó "ðñ ØØð/ô€Oñ ØØðXôÐñ Ð"Ó#ñ(ó $ð(ñ Ð#Ó$ñ'ó %ð'ò1ò$ó,'ò&&ò(ó&ò41óf>ó@&óPó<4ól
Có2òh0òd\ò<Sóõ*
òXò&ó&ö:
Br.   r0   c                  óÎ   ‡ — e Zd ZdZ ed«      d„ «       Zdd„Zdd„Zdd„Zdd„Z	dd„Z
dd	„Zd
„ Zd„ Zd„ Zdd„Zd„ Zdd„Zdˆ fd„	Z	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zddd„Zd d„Zˆ xZS )!ÚAsyncFileContentsManagerzAn async file contents manager.rV   c                ó   — t         S r6   )r   r:   s    r,   rX   z3AsyncFileContentsManager._checkpoints_class_default"  s   € ä#Ð#r.   c              ƒ  óz  K  — | j                  |«      }d|z  }t        j                  j                  |«      st	        j
                  d|«      ‚| j                  sHt        || j                  «      r2| j                  j                  d|«       t	        j
                  d|«      ‚| j                  |«      }d|d<   d|d<   |�rQg x|d<   }|}t        t        j                  |«      ƒ d{  –—† }|D �]  }		 t        j                  j                  ||	«      }	 t        t        j"                  |«      ƒ d{  –—† }t-        j.                  |j0                  «      s[t-        j2                  |j0                  «      s<t-        j4                  |j0                  «      s| j                  j7                  d|«       ŒÂ	 | j9                  |	«      rH| j                  st;        ||¬«      s/|j=                  | j?                  |› d|	› �d¬«      ƒ d{  –—† «       �Œ d|d<   |S 7 �Œ-# t        $ r(}
| j                  j!                  d	|	|
«       Y d}
~
�ŒUd}
~
ww xY w7 �Œ# t$        $ r}
|
j&                  t&        j(                  k(  r| j                  j!                  d
|«       n:|
j&                  t&        j*                  k7  r| j                  j!                  d||
«       Y d}
~
�Œãd}
~
ww xY w7 Œ×# t$        $ rU}
|
j&                  t&        j@                  t&        j*                  fvr| j                  j!                  d|d¬«       Y d}
~
�ŒFd}
~
ww xY w­wr¡   )!rd   r8   r?   rB   r   r{   r“   r	   r4   rk   r*   rŸ   r   r¨   r©   rª   r•   r’   rj   r«   r¬   r­   r®   r¯   r°   r±   r²   r³   r´   r   rµ   r¶   r·   )r;   r?   r‹   rf   rœ   rž   r¸   r¹   Údir_contentsrˆ   rº   r»   s               r,   r¼   z#AsyncFileContentsManager._dir_model&  s“  è ø€ ð
 ×#Ñ# DÓ)ˆà4°tÑ;ˆä�w‰w�}‰}˜WÔ%Ü—-‘-  [Ó1Ð1Ø×"Ò"¤y°¸$¿-¹-Ô'HØ�H‰H�M‰MÐPÐRYÔZÜ—-‘-  [Ó1Ð1à× Ñ  Ó&ˆØ#ˆˆf‰Øˆˆf‰ÚØ*,Ð,ˆE�)Ñ˜xØˆFÜ!)¬"¯*©*°fÓ!=×=ˆLÜ$�ðÜ Ÿg™gŸl™l¨6°4Ó8�Gð
Ü'¬¯©°'Ó:×:�Bô Ÿ™ R§Z¡ZÔ0Ü ŸL™L¨¯©Ô4Ü ŸL™L¨¯©Ô4à—H‘H—N‘NÐ#:¸GÔDØðØ×'Ñ'¨Ô-Ø×)Ò)´ÀÐRTÕ1Uà Ÿ™¨d¯h©h¸t¸fÀAÀdÀVÐ<LÐV[¨hÓ.\×(\Ô]ùð; %ðN %ˆE�(‰OàˆðU >úô *ò Ø—H‘H×$Ñ$Ð%IÈ4ÐQRÔSÝûðúð
 ;úÜò à—w‘w¤%§,¡,Ò.ØŸ™×(Ñ(Ð);¸WÕEØŸ™¤E§L¡LÒ0ØŸ™×(Ñ(Ð)@À'È1ÔMÝûðúð( )]ùÜò à—w‘w¤u§{¡{´E·L±LÐ&AÑAØŸ™×(Ñ(ØIØ#Ø%)ð )ô ÿùðüs²   ‚C$L;Ã&HÃ'
L;Ã2 HÄIÄ0I
Ä1IÄ5A:L;Æ0AKÈ K
ÈKÈ	L;È	IÈIÈ<L;ÉIÉL;É
IÉ	KÉA4KË
L;ËKËL;ËKË	L8Ë#A
L3Ì-L;Ì3L8Ì8L;c              ƒ  ó°  K  — | j                  |«      }d|d<   | j                  |«      }t        j                  |«      d   |d<   d}|rE| j	                  ||d¬«      ƒ d{  –—† \  }}}|d   €dd	d
œ|   }||d<   |j                  ||¬«       |r@|€| j	                  |d«      ƒ d{  –—† \  }}	 |j
                  di | j                  |«      ¤Ž |S 7 Œq7 Œ,­wr¾   rÅ   rË   s
             r,   rÐ   z$AsyncFileContentsManager._file_modelg  s  è ø€ ð × Ñ  Ó&ˆØˆˆf‰à×#Ñ# DÓ)ˆÜ%×0Ñ0°Ó9¸!Ñ<ˆˆjÑàˆÙØ37·?±?À7ÈFÐX\°?Ó3]×-]Ñ*ˆG�V˜]Ø�ZÑ Ð(à(Ø8ñ ð ñ �ð %1��jÑ!à�L‰LØØð ô ñ
 ØÐ$Ø)-¯©¸À&Ó)I×#IÑ �˜qØˆE�L‰LÑ9˜4Ÿ>™>¨-Ó8Ò9àˆð% .^øð $Jús%   ‚ACÁ CÁ!ACÂ'CÂ(+CÃCc              ƒ  ó�  K  — | j                  |«      }d|d<   | j                  |«      }d}|rPi }| j                  |d|d¬«      ƒ d{  –—† \  }}| j                  ||«       ||d<   d|d	<   | j	                  ||«       |r@|€| j                  |d
«      ƒ d{  –—† \  }}	 |j                  di | j                  |«      ¤Ž |S 7 Œy7 Œ,­w)zœBuild a notebook model

        if content is requested, the notebook content will be populated
        as a JSON structure (not double-serialized)
        rÒ   r£   NrÓ   TrÔ   r‹   r§   rŒ   rÃ   rÄ   r×   rÛ   s
             r,   rÞ   z(AsyncFileContentsManager._notebook_model�  së   è ø€ ð × Ñ  Ó&ˆØ"ˆˆf‰Ø×#Ñ# DÓ)ˆàˆÙØ13ÐØ&*×&9Ñ&9Ø AÐ@PÐVZð ':ó '÷ !ÑˆB�ð ×#Ñ# B¨Ô-Ø!ˆE�)ÑØ$ˆE�(‰OØ×(Ñ(¨Ð0@ÔAáØÐ$Ø)-¯©¸À&Ó)I×#IÑ �˜qØˆE�L‰LÑ;˜DŸN™N¨=Ó9Ò;àˆð!øð $Jús%   ‚ACÁCÁ	ACÂCÂ+CÃCc              ƒ  óx  K  — |j                  d«      }| j                  |«      st        j                  dd|z  «      ‚| j	                  |«      }t
        j                  j                  |«      r=|dvrt        j                  d|› d|› �d¬«      ‚| j                  ||¬	«      ƒ d
{  –—† }nr|dk(  s|€.|j                  d«      r| j                  |||¬«      ƒ d
{  –—† }n=|dk(  rt        j                  dd|z  d¬«      ‚| j                  ||||¬«      ƒ d
{  –—† }| j                  d|dœ¬«       |S 7 ŒŽ7 Œ[7 Œ­w)rà   r`   r…   zNo such file or directory: %srá   râ   rã   rä   rå   rç   NrÒ   rè   ré   r¢   rê   rë   r¶   rì   rî   )rc   r   r   r{   rd   r8   r?   rB   r¼   rð   rÞ   rÐ   rñ   )r;   r?   r‹   r£   rŒ   rÌ   rf   rž   s           r,   r¶   zAsyncFileContentsManager.get«  s?  è ø€ ð0 �z‰z˜#‹ˆà�{‰{˜4Ô Ü—-‘- Ð%DÀtÑ%KÓLÐLà×#Ñ# DÓ)ˆÜ�7‰7�=‰=˜Ô!ØÐ.Ñ.Ü—m‘mØØ�fÐ3°D°6Ð:Ø%ôð ð
 Ÿ/™/¨$¸˜/Ó@×@‰EØ�ZÒ D L°T·]±]À8Ô5LØ×.Ñ.¨t¸WÐS_Ð.Ó`×`‰Eà�{Ò"Ü—m‘m CÐ)@À4Ñ)GÐPZÔ[Ð[Ø×*Ñ*Ø˜g¨fÀ<ð +ó ÷ ˆEð 	�	‰	 %°Ñ6ˆ	Ô7Øˆð Aøà`øðús6   ‚B#D:Â%D4Â&4D:ÃD6Ã=D:ÄD8ÄD:Ä6D:Ä8D:c              ƒ  óü  K  — | j                   s/t        || j                  «      rt        j                  dd|z  «      ‚t
        j                  j                  |«      s<| j                  «       5  t        t
        j                  |«      ƒ d{  –—†  ddd«       yt
        j                  j                  |«      st        j                  dd|z  «      ‚| j                  j                  d|«       y7 Œb# 1 sw Y   yxY w­w)ró   râ   z!Cannot create hidden directory %rNrô   rõ   )r“   r	   r4   r   r{   r8   r?   r   rö   r   r÷   rB   rk   r³   rø   s       r,   rù   z(AsyncFileContentsManager._save_directoryÜ  s³   è ø€ à× Ò ¤Y¨w¸¿¹Ô%FÜ—-‘- Ð%HÈ7Ñ%RÓSÐSÜ�w‰w�~‰~˜gÔ&Ø×!Ñ!Õ#ÜœrŸx™x¨Ó1×1Ð1÷ $Ð#ä—‘—‘˜wÔ'Ü—-‘- Ð%:¸gÑ%FÓGÐGà�H‰H�N‰NÐ8¸'ÕBð	 2ø÷ $Ð#üs1   ‚A+C<Á-C0ÂC.ÂC0ÂAC<Ã.C0Ã0C9Ã5C<c              ƒ  óþ  K  — |j                  d«      }| j                  ||¬«       d|vrt        j                  dd«      ‚d|vr|d   dk7  rt        j                  dd«      ‚| j	                  |«      }| j
                  j                  d	|«       i }	 |d   d
k(  rƒt        j                  |d   «      }| j                  ||«       | j                  |||¬«      ƒ d{  –—†  | j                  j                  |«      ƒ d{  –—† s�| j                  |«      ƒ d{  –—†  nv|d   dk(  r.| j                  ||d   |j                  d«      «      ƒ d{  –—†  n@|d   dk(  r| j!                  |||«      ƒ d{  –—†  nt        j                  dd|d   z  «      ‚d}|d   d
k(  r%| j'                  ||¬«       |j                  dd«      }| j                  |d¬«      ƒ d{  –—† }|r||d<   | j)                  ||¬«       | j+                  d|dœ¬«       |S 7 �Œ37 �Œ7 Œü7 ŒÈ7 Œ¦# t        j                  $ r ‚ t"        $ rA}| j
                  j%                  d||d¬«       t        j                  dd|› d|› �«      |‚d}~ww xY w7 Œ¡­w)rû   r`   rü   r£   râ   rý   r‹   r¢   rþ   rÿ   rÒ   r   Nr¿   rŒ   r  r  Tr¥   r2   r  r  r  r  Frç   r  r  rì   rî   )rc   r	  r   r{   rd   rk   r³   r
  r  r  r  r  r  r  r  r¶   rù   r  rl   rÚ   r  rñ   r  s           r,   r  zAsyncFileContentsManager.saveè  s‚  è ø€ à�z‰z˜#‹ˆà×Ñ e°$ÐÔ7à˜ÑÜ—-‘- Ð%<Ó=Ð=Ø˜EÑ! e¨F¡m°{Ò&BÜ—-‘- Ð%?Ó@Ð@à×#Ñ# DÓ)ˆØ�‰�‰�{ GÔ,à-/Ðð	_Ø�V‰} 
Ò*Ü×'Ñ'¨¨iÑ(8Ó9�Ø×#Ñ# B¨Ô-Ø×)Ñ)¨'°2ÐP`Ð)Óa×aÐaà"×.Ñ.×?Ñ?ÀÓE×EÐEØ×0Ñ0°Ó6×6Ñ6Ø�v‘ &Ò(à—o‘o g¨u°YÑ/?ÀÇÁÈ8ÓATÓU×UÑUØ�v‘ +Ò-Ø×*Ñ*¨7°E¸4Ó@×@Ñ@ä—m‘m CÐ)FÈÈvÉÑ)VÓWÐWð "ÐØ�‰=˜JÒ&Ø×(Ñ(¨ÐAQÐ(ÔRØ!&§¡¨9°dÓ!;Ðà—h‘h˜t¨U�hÓ3×3ˆÙØ1ˆE�)Ñà× Ñ  u°gÐ Ô>Ø�	‰	 &°$Ñ7ˆ	Ô8Øˆð9 bùàEùØ6øð Vøà@ùô �}‰}ò 	ØÜò 	_Ø�H‰H�N‰NÐ;¸TÀ1ÈtˆNÔTÜ—-‘- Ð'KÈDÈ6ÐQRÐSTÐRUÐ%VÓWÐ]^Ð^ûð	_úð 4ús’   ‚BI=ÂA	H ÃHÃ"H Ã?HÄ H ÄHÄ5H ÅHÅ#H Å2HÅ3!H ÆAI=ÇI;Ç5I=ÈH ÈH ÈH ÈH ÈH ÈI8È7<I3É3I8É8I=c              ƒ  ó4  ‡ K  — |j                  d«      }‰ j                  |«      }t        j                  }‰ j                  s/t        |‰ j                  «      rt        j                  dd|›�«      ‚t        j                  j                  |«      st        j                  dd|z  «      ‚ˆ fd„}‰ j                  rœ‰ j                  s<t        j                  dk(  r) ||«      ƒ d{  –—† rt        j                  dd	|z  «      ‚‰ j                  |«      st        j                  d
d|z  «      d‚‰ j                   j#                  d|«       	 t%        |«       yt        j                  j)                  |«      r�‰ j                  s) ||«      ƒ d{  –—† rt        j                  dd	|z  «      ‚‰ j                   j#                  d|«       ‰ j+                  «       5  t-        t.        j0                  |«      ƒ d{  –—†  ddd«       y‰ j                   j#                  d|«       ‰ j+                  «       5  t-        ||«      ƒ d{  –—†  ddd«       y7 �Œh# t&        $ r}t        j                  dd|z  «      |‚d}~ww xY w7 Œí7 Œ‡# 1 sw Y   yxY w7 ŒK# 1 sw Y   yxY w­w)r  r`   râ   r  r…   z$File or directory does not exist: %sc              “  óâ   •K  — t         j                  j                  | «      rIt        ‰j                  dd «      }t        t        t         j                  | «      ƒ d {  –—† «      }||hz
  ryy7 Œ­wr  )r8   r?   rB   r#   r  r  r   r¨   )rf   r  r�  r;   s      €r,   r  z>AsyncFileContentsManager.delete_file.<locals>.is_non_empty_dir%  s\   øè ø€ Ü�w‰w�}‰}˜WÔ%ô ! ×!1Ñ!1Ð3CÀTÓJ�Ü"¬´"·*±*¸gÓ)F×#FÓG�Ø 6 (Ò*Øàð	 $Gús   ƒAA/ÁA-ÁA/r  Nr   r!  r"  r#  r$  r%  r&  )rc   rd   r8   r'  r“   r	   r4   r   r{   r?   r   r(  r)  r*  r+  rm   rk   r³   r
   rj   rB   rö   r   r,  r-  )r;   r?   rf   r.  r  rº   s   `     r,   r/  z$AsyncFileContentsManager.delete_file  s$  øè ø€ à�z‰z˜#‹ˆØ×#Ñ# DÓ)ˆÜ�Y‰Yˆà× Ò ¤Y¨w¸¿¹Ô%FÜ—-‘- Ð'GÈÀ{Ð%SÓTÐTä�w‰w�~‰~˜gÔ&Ü—-‘- Ð%KÈgÑ%UÓVÐVô		ð ×Òà×*Ò*Ü—L‘L GÒ+Ù*¨7Ó3×3Ð3ô —m‘m CÐ)AÀGÑ)KÓLÐLà×#Ñ# DÔ)Ü—m‘m CÐ)@À4Ñ)GÓHÈdÐRØ�H‰H�N‰NÐ0°'Ô:ðMÜ˜7Ô#ð ä�7‰7�=‰=˜Ô!à×)Ò)Ñ4DÀWÓ4M×.MÐ.MÜ—m‘m CÐ)AÀGÑ)KÓLÐLØ�H‰H�N‰NÐ2°GÔ<Ø×!Ñ!Õ#ÜœvŸ}™}¨gÓ6×6Ð6÷ $Ð#ð �H‰H�N‰NÐ.°Ô8Ø×!Ñ!Õ#Ü˜r 7Ó+×+Ð+÷ $Ð#ð1 4úô ò MÜ—m‘m CÐ)@À1Ñ)DÓEÈ1ÐLûðMúð /Nøð 7ø÷ $Ð#úð
 ,ø÷ $Ð#üs˜   ƒC!JÃ$IÃ%A$JÅ
I Å7JÆI:ÆA	JÇI>Ç4I<Ç5I>Ç95JÈ.JÈ>J
È?JÉ
JÉ	I7ÉI2É2I7É7JÉ<I>É>JÊJÊ
JÊJÊJc              ƒ  ó&  K  — |j                  d«      }|j                  d«      }||k(  ry| j                  |«      }| j                  |«      }| j                  sEt        || j                  «      st        || j                  «      rt        j                  dd|›�«      ‚t        j                  j                  |«      r%t        ||«      st        j                  dd|z  «      ‚	 | j                  «       5  t        t        j                  ||«      ƒ d{  –—†  ddd«       y7 Œ# 1 sw Y   yxY w# t
        j                  $ r ‚ t        $ r t        j                  dd|› �«      d‚t         $ r"}t        j                  d	d
|› d|› �«      |‚d}~ww xY w­wr1  )rc   rd   r“   r	   r4   r   r{   r8   r?   r   r   rö   r   r,  r2  r3  r  r4  s         r,   r9  z$AsyncFileContentsManager.rename_fileO  s`  è ø€ à—>‘> #Ó&ˆØ—>‘> #Ó&ˆØ�xÒØà×'Ñ'¨Ó1ˆØ×'Ñ'¨Ó1ˆà× Ò Ü�k 4§=¡=Ô1´Y¸{ÈDÏMÉMÔ5Zä—-‘- Ð'GÈÀÐ%WÓXÐXô �7‰7�>‰>˜+Ô&¬x¸À[Ô/QÜ—-‘- Ð%>ÀÑ%IÓJÐJð	\Ø×!Ñ!Õ#ÜœvŸ{™{¨K¸ÓE×EÐE÷ $Ð#ØEø÷ $Ð#ûä�}‰}ò 	ØÜ ò 	`Ü—-‘- Ð'IÈ(ÈÐ%TÓUÐ[_Ð_Üò 	\Ü—-‘- Ð'DÀXÀJÈaÐPQÈsÐ%SÓTÐZ[Ð[ûð	\üs`   ‚C FÃ#D. Ã3D"ÄD ÄD"ÄD. ÄFÄ D"Ä"D+Ä'D. Ä*FÄ+D. Ä.>FÅ,F	Æ	FÆFc              ƒ  óŽ   K  — |j                  d«      }| j                  |¬«      }t        j                  j	                  |«      S ­w)z(Does a directory exist at the given pathr`   ra   rs   re   s      r,   rt   z#AsyncFileContentsManager.dir_existsm  s9   è ø€ à�z‰z˜#‹ˆØ×#Ñ#¨Ð#Ó.ˆÜ�w‰w�}‰}˜WÓ%Ð%ùs   ‚AAc              ƒ  óŒ   K  — |j                  d«      }| j                  |«      }t        j                  j	                  |«      S ­w)z#Does a file exist at the given pathr`   ro   re   s      r,   rq   z$AsyncFileContentsManager.file_existss  s6   è ø€ à�z‰z˜#‹ˆØ×#Ñ# DÓ)ˆÜ�w‰w�~‰~˜gÓ&Ð&ùs   ‚AAc              ƒ  ó|   K  — |j                  d«      }| j                  |¬«      }t        || j                  «      S ­w)z"Is path a hidden directory or filer`   ra   rb   re   s      r,   r	   z"AsyncFileContentsManager.is_hiddeny  s7   è ø€ à�z‰z˜#‹ˆØ×#Ñ#¨Ð#Ó.ˆÜ˜ $§-¡-Ó0Ð0ùs   ‚:<c              ƒ  ó‚   K  — | j                  |«      ƒ d{  –—† r|S d|v r|j                  dd«      d   }|S d}|S 7 Œ%­w)zHReturn the initial API path of a kernel associated with a given notebookNr`   r   r   rG   r=  r>  s       r,   r@  z(AsyncFileContentsManager.get_kernel_path  sR   è ø€ à—‘ Ó&×&Ð&ØˆKØ/2°d©{�T—[‘[  aÓ(¨Ñ+ˆ
ØÐð ACˆ
ØÐð 'ús   ‚?—=˜&?c              ƒ  óŠ  •K  — t        |«      }|j                  d«      }|�|j                  d«      }d|v r|j                  dd«      \  }}nd}|}| j                  |«      ƒ d{  –—† }|d   dk(  r| j	                  |«      ƒ d{  –—†  n t        j                  | ||¬«      ƒ d{  –—† S |du}t        j                  d|«      }	|s|}| j                  |«      ƒ d{  –—† r0t        j                  d|«      }
t        ‰| �-  |
|d	¬
«      ƒ d{  –—† }	|› d|	› �}| j                  |||	|¬«      ƒ d{  –—† S 7 ŒÑ7 Œ²7 Œ“7 Œ^7 Œ07 Œ­wrB  )rz   rc   r›   r¶   rI  r   rJ  r   rK  rt   rS   rL  rM  rN  s              €r,   rJ  zAsyncFileContentsManager.copy†  s]  øè ø€ ô ˜w›<ÐØ�‰˜sÓ#ˆØÐØ—m‘m CÓ(ˆGà�$‰;Ø"&§+¡+¨c°1Ó"5ÑˆH‘iàˆHØˆIà—h‘h˜t“n×$ˆà�‰=˜KÒ'Ø×(Ñ(¨Ó.×.Ñ.ô .×2Ñ2°4À9ÐV]Ô^×^Ð^à#*°$Ð#6Ð Ü—,‘,˜s IÓ.ˆÙ'ØˆGØ—‘ Ó)×)Ð)Ü—<‘<  YÓ/ˆDÜ!™GÑ6°t¸WÈWÐ6ÓU×UˆGØ�I˜Q˜w˜iÐ(ˆà—^‘^ØØ-ØØð	 $ó 
÷ 
ð 	
ð# %øð /øð _øð *øàUøð
úsl   ƒA"EÁ%D7Á& EÂD9Â EÂ'D;Â(6EÃD=Ã/EÄD?Ä#EÄ2EÄ3EÄ9EÄ;EÄ=EÄ?EÅEc           	   ƒ  óš  K  — 	 | j                  |j                  d«      «      }| j                  |j                  d«      «      › d|› �}t        j                  ||«       | j	                  |d¬«      ƒ d{  –—† }|S 7 Œ# t
        $ rA}| j                  j                  d|› �«       t        j                  dd|› d|› d	�«      |‚d}~ww xY w­w)
rS  r`   Frç   NrT  râ   rU  z' into read-only Folder 'rV  rW  rY  s	            r,   rM  z"AsyncFileContentsManager._copy_dir²  sÎ   è ø€ ð
	Ø×,Ñ,¨Y¯_©_¸SÓ-AÓBˆLØ ×-Ñ-Ð.>×.DÑ.DÀSÓ.IÓJÐKÈ1ÈWÈIÐVˆJÜ�O‰O˜L¨*Ô5ØŸ(™( 7°E˜(Ó:×:ˆEð ˆð ;ùÜò 	Ø�H‰H�N‰NÐ3°C°5Ð9Ô:Ü—-‘-ØØ˜y˜kÐ)BÀ7À)È1ÐMóð ðûð	üs;   ‚C„A1A> Á5A<Á6A> Á:CÁ<A> Á>	CÂ<CÃCÃCc              ƒ  ób  K  — | j                   dz  dz  }t        | j                  | j                  |«      «      ƒ d{  –—† «      }t	        j
                  «       dk(  r|dz  n|}||kD  rAt        j                  dd| j                   › d|› d| j                  |«      ƒ d{  –—† › d�«      ‚y7 Œm7 Œ­w)	r^  r_  Nr`  râ   ra  rb  rc  rd  re  rj  s       r,   rI  z*AsyncFileContentsManager.check_folder_sizeÇ  sÃ   è ø€ ð
 ×2Ñ2°TÑ9¸DÑ@ˆä˜×+Ñ+¨D×,=Ñ,=¸dÓ,CÓD×DÓEˆä&Ÿo™oÓ/°8Ò;ˆt�dŠ{ÀˆØ�+ÒÜ—-‘-Øð4Ø48×4PÑ4PÐ3Qð RØ�V˜5 t×'@Ñ'@ÀÓ'F×!FÐ Gð Hðóð ð ð Eøð "Gús"   ‚;B/½B+¾A B/ÂB-ÂB/Â-B/c              ƒ  óL  K  — 	 t        j                  «       dk(  rd|g}ndd|g}t        j                  dg|¢­t        j                  j
                  t        j                  j
                  dœŽƒ d{  –—† }|j                  «       ƒ d{  –—† \  }}|j                  «       ƒ d{  –—† }| j                  j                  d|› �«       |d	k(  sJ ‚|j                  d
«      j                  «       d	   }|S 7 Œ€7 Œj7 ŒQ# t        $ r | j                  j                  d|«       Y yw xY w­w)rm  r`  ro  rr  rs  rn  )rz  ÚstderrNrt  r   ru  rv  rw  )r+  rh  ÚasyncioÚcreate_subprocess_execrx  ÚPIPEÚcommunicateÚwaitrk   r*   r|  r{  r  r•   )r;   r?   ÚargsÚprocrz  rÏ   r}  rŽ   s           r,   rg  z&AsyncFileContentsManager._get_dir_sizeÚ  s  è ø€ ð	Ü�‰Ó  HÒ,à˜t�}‘àÐ.°Ð5�Ü ×7Ñ7ØðØñÜ$+×$6Ñ$6×$;Ñ$;ÄG×DVÑDV×D[ÑD[ò÷ ˆDð #×.Ñ.Ó0×0‰IˆF�AØŸ9™9›;×&ˆFØ�H‰H�M‰MÐ9¸&¸ÐBÔCØ˜Q’;Ð�;Ø—=‘= Ó)×/Ñ/Ó1°!Ñ4ˆDð ˆðøð 1øØ&ùô ò 	Ø�H‰H×ÑØpØôñ ð	üs`   ‚D$„A.C9 Á2C3Á3C9 Â
C5ÂC9 Â%C7Â&AC9 Ã1D$Ã3C9 Ã5C9 Ã7C9 Ã9%D!ÄD$Ä D!Ä!D$c              ƒ  ó�   K  — |dk(  ryg d¢}|r!t        t        j                  |«      dz  «      nd}|d|dz  z  z  d›d||   › �S ­wr  r‡  r‰  s       r,   ri  z-AsyncFileContentsManager._human_readable_sizeõ  sX   è ø€ ð �1Š9Øâ7ˆÙ-1””D—I‘I˜d“O bÑ(Ô)°qˆà˜! ¨¡
Ñ+Ñ,¨SÐ1°°5¸±<°.ÐAÐAùs   ‚AAr�  rŽ  r�  r�  r‘  )r?   rz   rŒ  Úboolr6   )
rC  rz   rG  rz   rH  rz   rD  rz   rŒ  zdict[str, t.Any])r?   rz   rŒ  ÚNoner’  )r?   rz   rŒ  rz   )rŽ   r%   rŒ  rz   )r“  r”  r•  r–  r   rX   r¼   rÐ   rÞ   r¶   rù   r  r/  r9  rt   rq   r	   r@  rJ  rM  rI  rg  ri  r—  r˜  s   @r,   rš  rš    s¦   ø„ ñ *áÐ Ó!ñ$ó "ð$ó?óB&óPó8/ób
Có/òb4,òl\ò<&ó'ò1óõ*
ðXØðØ03ðØ>AðØLOðà	óó*ô&÷6
Br.   rš  )r*   zos.stat_resultrŒ  r&   )?r–  Ú
__future__r   r¯  r«   r'   rÆ   r8   r+  r,  r®   rx  r*  ÚtypingÚtrJ   r   Úpathlibr   r
  Úanyio.to_threadr   Újupyter_core.pathsr   r   r	   r
   Útornador   Ú	traitletsr   r   r   r   r   r   Újupyter_serverr   r–   Újupyter_server.base.handlersr   Újupyter_server.transutilsr   Újupyter_server.utilsr   Úfilecheckpointsr   r   Úfileior   r   Úmanagerr   r   r   Úos.pathr   ÚImportErrorr    Ú_script_exporterr-   r0   rš  rÄ   r.   r,   Ú<module>rË     s¿   ðÙ Eõ #ã Û Û Û Û 	Û Û Û Û Û 
Û Û Ý Ý ã Ý $ß @Ñ @Ý !Ý ß G× Gå $Ý AÝ +Ý ,ç Bß ;ß DÑ DðAÝ ð
 Ð óô2RBÐ*¨Oô RBôjbBØÐ.Ð0DõbBøðk ò Aç@ðAús   Â(C ÃCÃC