+
    «úÎjñ³  ã                   óŒ  € R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
HtHt ^ RIHtHt ^ RIHt ^ RIHtHtHt ^RIHtHt ^RIHt ^R	IHt ^R
IHtHtHtH t H!t!H"t"H#t# ^RI$H%t% ^RI&H't' ]'       d   ^RI(H)t) ]PT                  ! ]+4      t,Rt-Rt.] ! R R4      4       t/] ! R R4      4       t0] ! R R4      4       t1] ! R R4      4       t2]! RR7       ! R R4      4       t3] ! R R4      4       t4] ! R R4      4       t5] ! R  R!4      4       t6R" R# lt7R$ R% lt8] ! R& R'4      4       t9] ! R( R)4      4       t: ! R* R+4      t;R, R- lt<R. R/ lt=R0 R1 lt>R2 R3 lt?R4 R5 lt@R6R/R7 R8 lltARVR: R; lltBR< R= ltCR> R? ltDR@ RA ltERWRB RC lltFRD RE ltGRXRFR9RGR9RHR9RIR9RJR9RKRRLRRMRRNRRORRPR9RQR9RRR9RSR/RT RU llltHR# )YzzShared logic for bucket operations.

This module contains the core buckets logic used by both the CLI and the Python API.
N)ÚIterator)Ú	dataclassÚfield)ÚdatetimeÚtimezone)ÚPath)ÚTYPE_CHECKINGÚAnyÚLiteral)Ú	constantsÚlogging)Ú_validate_relative_filename)ÚBucketNotFoundError)ÚHfUriÚ
StatusLineÚXetFileDataÚdisable_progress_barsÚenable_progress_barsÚparse_datetimeÚparse_hf_uri)Ú_looks_like_hf_url)Ú_normalize_separators©ÚHfApizhf://buckets/éè  c                   ó6   a € ] tR t^@t o RtR tV 3R ltRtV tR# )Ú
BucketInfoa«  
Contains information about a bucket on the Hub. This object is returned by [`bucket_info`] and [`list_buckets`].

Attributes:
    id (`str`):
        ID of the bucket.
    private (`bool`):
        Is the bucket private.
    created_at (`datetime`):
        Date of creation of the bucket on the Hub.
    size (`int`):
        Size of the bucket in bytes.
    total_files (`int`):
        Total number of files in the bucket.
c                ó,  € VP                  R 4      V n        VP                  R4      V n        \        VP                  R4      4      V n        VP                  R4      V n        VP                  R4      V n        V P                  P                  ! R/ VB  R# )ÚidÚprivateÚ	createdAtÚsizeÚ
totalFilesN© )	Úpopr   r   r   Ú
created_atr!   Útotal_filesÚ__dict__Úupdate)ÚselfÚkwargss   &,ÚR/opt/data/cache/scratch/pip-target-_o6w5emm/lib/python/huggingface_hub/_buckets.pyÚ__init__ÚBucketInfo.__init__X   sm   € Ø—*‘*˜TÓ"ˆŒØ—z‘z )Ó,ˆŒÜ(¨¯©°KÓ)@ÓAˆŒØ—J‘J˜vÓ&ˆŒ	Ø!Ÿ:™: lÓ3ˆÔØ�‰×ÒÑ&˜vÔ&ó    c                óV   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[;R&   S[;R&   # )é   r   r   r%   r!   r&   )ÚstrÚboolr   Úint)ÚformatÚ__classdict__s   "€r+   Ú__annotate__ÚBucketInfo.__annotate__@   sC   ø‡ ‚ ñ$ 	�Gñ% ñ& �Mñ' ñ( Ññ) ñ* �Iñ+ ñ, Ñò- r.   )r%   r   r   r!   r&   N©	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r,   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r5   s   @r+   r   r   @   s   ø‡ € ñò,'÷1 ƒ r.   r   c                   ó†   a € ] tR t^at o ]! RR7      t]! RR7      t]! RR7      t]! RR7      tV 3R lR lt	V 3R lt
RtV tR# )	Ú_BucketAddFileN©ÚdefaultF©Úinitc                ó   <€ V ^8„  d   QhRR/# ©r0   ÚreturnNr#   )r4   r5   s   "€r+   r6   Ú_BucketAddFile.__annotate__k   s   ø€ ÷ 	
ñ 	
˜tñ 	
r.   c                ó   € R V n         \        V P                  \        \        34      '       d-   \
        P                  ! V P                  4      ^ ,          V n         V P                   f-   \
        P                  ! V P                  4      ^ ,          V n         \        \        V P                  \        4      '       g1   \        P                  P                  V P                  4      R,          M\        P                  ! 4       R,          4      V n        R # )Nr   )Úcontent_typeÚ
isinstanceÚsourcer1   r   Ú	mimetypesÚ
guess_typeÚdestinationr3   ÚbytesÚosÚpathÚgetmtimeÚtimeÚmtime©r)   s   &r+   Ú__post_init__Ú_BucketAddFile.__post_init__k   s¯   € Ø ˆÔÜ�d—k‘k¤C¬ ;×/Ò/Ü )× 4Ò 4°T·[±[Ó AÀ!Õ DˆDÔØ×ÑÒ$Ü )× 4Ò 4°T×5EÑ5EÓ FÀqÕ IˆDÔäÜ8BÀ4Ç;Á;ÔPU×8VÒ8VŒB�G‰G×Ñ˜TŸ[™[Ó)¨DÖ0Ô\`×\eÒ\eÓ\gÐjnÕ\nó
ˆŽ
r.   c                ó¬   <€ V ^8„  d   Qh/ S[ S[,          S[,          ;R&   S[ ;R&   S[ R,          ;R&   S[R,          ;R&   S[;R&   S[ R,          ;R&   # )r0   rO   rR   NÚxet_hashr!   rX   rM   )r1   r   rS   r3   )r4   r5   s   "€r+   r6   rK   a   sf   ø‡ ‚ á‘$�J™ÕÑñ ñ Ññ ñ
 �D�jÑ.ñ ñ ��*Ñ*ñ ñ Ñ"ñ ñ ˜•*Ñ0ò r.   ©rM   rX   )r9   r:   r;   r<   r   r]   r!   rX   rM   rZ   r>   r?   r@   rA   s   @r+   rC   rC   a   s@   ø‡ € ñ
 !¨Ô.€HÙ TÔ*€DÙ˜EÔ"€EÙ$¨%Ô0€L÷	
ð 	
÷ ƒ r.   rC   c                   ót   a € ] tR t^wt o ]! RR7      t]! RR7      t]! RR7      tV 3R lR ltV 3R lt	Rt
V tR# )	Ú_BucketCopyFileNrD   FrF   c                ó   <€ V ^8„  d   QhRR/# rI   r#   )r4   r5   s   "€r+   r6   Ú_BucketCopyFile.__annotate__�   s   ø€ ÷ -ñ -˜tñ -r.   c                ó²   € \         P                  ! V P                  4      ^ ,          V n        \	        \
        P
                  ! 4       R,          4      V n        R# )é    r   N)rP   rQ   rR   rM   r3   rW   rX   rY   s   &r+   rZ   Ú_BucketCopyFile.__post_init__�   s7   € Ü%×0Ò0°×1AÑ1AÓBÀ1ÕEˆÔÜœŸš› tÕ+Ó,ˆŽ
r.   c                óŠ   <€ V ^8„  d   Qh/ S[ ;R&   S[ ;R&   S[ ;R&   S[ ;R&   S[R,          ;R&   S[;R&   S[ R,          ;R&   # )	r0   rR   r]   Úsource_repo_typeÚsource_repo_idNr!   rX   rM   )r1   r3   )r4   r5   s   "€r+   r6   rb   w   se   ø‡ ‚ áÑñ ñ �Mñ ñ Ññ	 ñ
 Ññ ñ ��*Ñ*ñ ñ Ñ"ñ ñ ˜•*Ñ0ò r.   r^   )r9   r:   r;   r<   r   r!   rX   rM   rZ   r>   r?   r@   rA   s   @r+   r`   r`   w   s6   ø‡ € ñ  TÔ*€DÙ˜EÔ"€EÙ$¨%Ô0€L÷-ð -÷ ƒ r.   r`   c                   ó,   a € ] tR t^†t o V 3R ltRtV tR# )Ú_BucketDeleteFilec                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )r0   rU   )r1   )r4   r5   s   "€r+   r6   Ú_BucketDeleteFile.__annotate__†   s   ø‡ ‚ á
�Iò r.   r#   N)r9   r:   r;   r<   r>   r?   r@   rA   s   @r+   rj   rj   †   s   ø‡ ‡ „ r.   rj   T)Úfrozenc                   ó0   a € ] tR t^‹t o RtV 3R ltRtV tR# )ÚBucketFileMetadataa	  Data structure containing information about a file in a bucket.

Returned by [`get_bucket_file_metadata`].

Args:
    size (`int`):
        Size of the file in bytes.
    xet_file_data (`XetFileData`):
        Xet information for the file (hash and refresh route).
c                ó2   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   # )r0   r!   Úxet_file_data)r3   r   )r4   r5   s   "€r+   r6   ÚBucketFileMetadata.__annotate__‹   s   ø‡ ‚ ñ �Iñ ñ Ñò r.   r#   N)r9   r:   r;   r<   r=   r>   r?   r@   rA   s   @r+   ro   ro   ‹   s   ø‡ € ñ	÷ ƒ r.   ro   c                   ó|   a € ] tR t^œt o RtRt]! RR7      t]! RR7      t]! RR7      t	V 3R lR lt
V 3R ltRtV tR	# )
Ú	BucketUrla�  Describes a bucket URL on the Hub.

`BucketUrl` is returned by [`create_bucket`]. At initialization, the URL is parsed to populate properties:
- endpoint (`str`)
- namespace (`str`)
- bucket_id (`str`)
- url (`str`)
- uri (`HfUri`)

Args:
    url (`str`):
        String value of the bucket url.
    endpoint (`str`, *optional*):
        Endpoint of the Hub. Defaults to <https://huggingface.co>.
Ú FrF   c                ó   <€ V ^8„  d   QhRR/# rI   r#   )r4   r5   s   "€r+   r6   ÚBucketUrl.__annotate__´   s   ø€ ÷ ñ ˜tñ r.   c                óò  € V P                   ;'       g    \        P                  V n         V P                  P	                  V P                   R 4      P                  R4      pVP                  R4      '       d   V\        R4      R p\        V4      pVP                  '       d   \        RV P                   24      hVP                  P                  R4      ^ ,          V n        VP                  V n        W n        R# )ru   Ú/zbuckets/NzUnable to parse bucket URL: )Úendpointr   ÚENDPOINTÚurlÚreplaceÚstripÚ
startswithÚlenÚ_parse_bucket_uriÚpath_in_repoÚ
ValueErrorr   ÚsplitÚ	namespaceÚ	bucket_idÚuri)r)   Úurl_pathÚparseds   &  r+   rZ   ÚBucketUrl.__post_init__´   sº   € ØŸ™×;Ð;¬×);Ñ);ˆŒð —8‘8×#Ñ# D§M¡M°2Ó6×<Ñ<¸SÓAˆà×Ñ˜z×*Ò*Ø¤ J£Ð 1Ð2ˆHÜ" 8Ó,ˆØ××ÐÜÐ;¸D¿H¹H¸:ÐFÓGÐGØŸ™Ÿ™¨Ó-¨aÕ0ˆŒØŸ™ˆŒØŽr.   c                óV   <€ V ^8„  d   Qh/ S[ ;R&   S[ ;R&   S[ ;R&   S[ ;R&   S[;R&   # )r0   r|   rz   r…   r†   r‡   ©r1   r   )r4   r5   s   "€r+   r6   rw   œ   sE   ø‡ ‚ ñ$ 
�Hñ% ñ& Ññ' ñ( Ñ&ñ) ñ* Ñ&ñ+ ñ, 
Ñ"ò- r.   )r†   rz   r…   r‡   N)r9   r:   r;   r<   r=   rz   r   r…   r†   r‡   rZ   r>   r?   r@   rA   s   @r+   rt   rt   œ   s@   ø‡ € ñð" €HÙ Ô&€IÙ Ô&€IÙ˜EÔ"€C÷ð ÷1 ƒ r.   rt   c                   ó6   a € ] tR t^Ät o RtR tV 3R ltRtV tR# )Ú
BucketFilezŸ
Contains information about a file in a bucket on the Hub. This object is returned by [`list_bucket_tree`].

Similar to [`RepoFile`] but for files in buckets.
c                ót  € VP                  R 4      V n        VP                  R4      V n        VP                  R4      V n        VP                  R4      V n        VP                  RR4      pV'       d   \        V4      MRV n        VP                  RR4      pV'       d   \        V4      V n        R# RV n        R# )ÚtyperU   r!   ÚxetHashrX   NÚ
uploadedAt)r$   r�   rU   r!   r]   r   rX   Úuploaded_at)r)   r*   rX   r“   s   &,  r+   r,   ÚBucketFile.__init__Ó   sˆ   € Ø—J‘J˜vÓ&ˆŒ	Ø—J‘J˜vÓ&ˆŒ	Ø—J‘J˜vÓ&ˆŒ	ØŸ
™
 9Ó-ˆŒØ—
‘
˜7 DÓ)ˆß.3”^ EÔ*¸ˆŒ
Ø—j‘j ¨tÓ4ˆß:Eœ>¨+Ó6ˆÖÈ4ˆÖr.   c                óŒ   <€ V ^8„  d   Qh/ S[ R,          ;R&   S[;R&   S[;R&   S[;R&   S[R,          ;R&   S[R,          ;R&   # )	r0   Úfiler�   rU   r!   r]   NrX   r“   )r
   r1   r3   r   )r4   r5   s   "€r+   r6   ÚBucketFile.__annotate__Ä   s\   ø‡ ‚ ñ �&�/Ññ ñ �Iñ ñ �Iñ ñ �Mñ ñ �d�?Ññ ñ ˜D•Ñ ò r.   )rX   rU   r!   r�   r“   r]   Nr8   rA   s   @r+   rŽ   rŽ   Ä   s   ø‡ € ñòP÷ ƒ r.   rŽ   c                   ó6   a € ] tR t^Þt o RtR tV 3R ltRtV tR# )ÚBucketFolderz¬
Contains information about a directory in a bucket on the Hub. This object is returned by [`list_bucket_tree`].

Similar to [`RepoFolder`] but for directories in buckets.
c                ó8  € VP                  R 4      V n        VP                  R4      V n        VP                  RR4      ;'       g    VP                  RR4      pV'       d3   \        V\        4      '       d
   VV n        R# \        V4       V n        R# RV n        R# )r�   rU   r’   Nr“   )r$   r�   rU   rN   r   r   r“   )r)   r*   r“   s   &, r+   r,   ÚBucketFolder.__init__ê   s‚   € Ø—J‘J˜vÓ&ˆŒ	Ø—J‘J˜vÓ&ˆŒ	Ø—j‘j ¨tÓ4×WÐW¸¿
¹
À=ÐRVÓ8Wˆ÷ ô ' {´H×=Ò=ˆ[ð 	ÖÜCQÐR]ÔC^ð 	Öð ð 	Ör.   c                óZ   <€ V ^8„  d   Qh/ S[ R,          ;R&   S[;R&   S[R,          ;R&   # )r0   Ú	directoryr�   rU   Nr“   )r
   r1   r   )r4   r5   s   "€r+   r6   ÚBucketFolder.__annotate__Þ   s4   ø‡ ‚ ñ �+Õ
Ññ ñ �Iñ ñ ˜D•Ñ ò r.   )rU   r�   r“   Nr8   rA   s   @r+   r™   r™   Þ   s   ø‡ € ñò
÷ ƒ r.   r™   c                ó0   € V ^8„  d   QhR\         R\        /# ©r0   rU   rJ   rŒ   )r4   s   "r+   r6   r6   ú   s   € ÷ Cñ CœCð C¤Eñ Cr.   c                óÜ  € V P                  \        P                  4      '       g   \        V 4      '       d/   \	        V 4      pVP
                  '       g   \        RV  R24      hV# V P                  R^4      p\        V4      ^8  g   V^ ,          '       d   V^,          '       g   \        RV  R24      hV^ ,           RV^,           2pRP                  VR,          4      p\        RW4R7      # )	zíParse a bucket path into a HfUri.

Accepts:
- `hf://buckets/namespace/name(/path/in/repo)` URIs,
- Hugging Face web URLs such as `https://huggingface.co/buckets/namespace/name(/tree/path)`,
- plain `namespace/name(/path/in/repo)` paths.
zInvalid bucket path: z*. Must be a bucket URI (hf://buckets/...).ry   zInvalid bucket path: 'z)'. Expected format: namespace/bucket_name:r0   NNÚbucket)r�   r   r‚   )r   r   ÚHF_PROTOCOLr   r   Ú	is_bucketrƒ   r„   r€   Újoinr   )rU   r‰   Úpartsr†   Úprefixs   &    r+   r�   r�   ú   sÍ   € ð ‡�”y×,Ñ,×-Ò-Ô1CÀD×1IÒ1Iä˜dÓ#ˆØ××ÐÜÐ4°T°FÐ:dÐeÓfÐfØˆØ�J‰J�s˜AÓ€EÜ
ˆ5ƒz�A„~˜U 1ŸXœX¨U°1¯X¬XÜÐ1°$°Ð7`ÐaÓbÐbØ˜•8�*˜A˜e A�h˜ZÐ(€IØ�X‰X�e˜B•iÓ €FÜ�h 9ÔBÐBr.   c                ó0   € V ^8„  d   QhR\         R\        /# r    ©r1   r2   )r4   s   "r+   r6   r6     s   € ÷ (ñ (œ#ð (¤$ñ (r.   c                óz   € V P                  \        P                  4      '       g   R# \        V 4      P                  # )z�Check if a path is a bucket path.

Do not raise if the path is not a hf:// URI.
Raise if the path is a hf:// URI but with an incorrect format.
F)r   r   r£   r   r¤   )rU   s   &r+   Ú_is_bucket_pathr«     s-   € ð �?‰?œ9×0Ñ0×1Ò1ÙÜ˜Ó×'Ñ'Ð'r.   c                   óD   a € ] tR tRt o RtRtRtRtRtRt	V 3R lt
RtV tR# )ÚSyncOperationi   z,Represents a sync operation to be performed.Nru   c                ó´   <€ V ^8„  d   Qh/ S[ R	,          ;R&   S[;R&   S[R,          ;R&   S[;R&   S[R,          ;R&   S[R,          ;R&   S[R,          ;R&   # )
r0   ÚactionrU   Nr!   ÚreasonÚlocal_mtimeÚremote_mtimeÚbucket_file)ÚuploadÚdownloadÚdeleteÚskip)r
   r1   r3   rŽ   )r4   r5   s   "€r+   r6   ÚSyncOperation.__annotate__   sv   ø‡ ‚ ñ Ð:Õ;Ñ;ñ	 ñ
 �Iñ ñ ��*Ññ ñ Ññ ñ �t•Ñ"ñ ñ ˜•*Ñ#ñ ñ ˜dÕ"Ñ)ò r.   r#   )r9   r:   r;   r<   r=   r!   r°   r±   r²   r³   r>   r?   r@   rA   s   @r+   r­   r­      s*   ø‡ € á6ð €DØ€FØ"€KØ#€LØ%)€K÷ ƒ r.   r­   c                   óT   a € ] tR tRt o Rt]! ]R7      tV 3R lR ltV 3R lt	Rt
V tR# )	ÚSyncPlani-  z Represents a complete sync plan.)Údefault_factoryc                óF   <€ V ^8„  d   QhRS[ S[S[S[,          3,          /# )r0   rJ   )Údictr1   r3   )r4   r5   s   "€r+   r6   ÚSyncPlan.__annotate__6  s!   ø€ ÷ 
ñ 
™™c¡3©¥9˜nÕ-ñ 
r.   c           
     ó2  € \        R  V P                   4       4      p\        R V P                   4       4      p\        R V P                   4       4      p\        R V P                   4       4      p\        R V P                   4       4      pRVRVRVRVR	V/# )
c              3   óJ   "  € T F  qP                   R 8X  g   K  ^x € K  	  R# 5i)r´   N©r¯   ©Ú.0Úops   & r+   Ú	<genexpr>Ú#SyncPlan.summary.<locals>.<genexpr>7  ó   é € ÐK¡/˜B·Y±YÀ(Ñ5J—a’a£/ùó   ‚#™
#c              3   óJ   "  € T F  qP                   R 8X  g   K  ^x € K  	  R# 5i)rµ   NrÁ   rÂ   s   & r+   rÅ   rÆ   8  s   é € ÐO¡O˜b·y±yÀJÑ7NŸš£OùrÈ   c              3   óJ   "  € T F  qP                   R 8X  g   K  ^x € K  	  R# 5i)r¶   NrÁ   rÂ   s   & r+   rÅ   rÆ   9  rÇ   rÈ   c              3   óJ   "  € T F  qP                   R 8X  g   K  ^x € K  	  R# 5i)r·   NrÁ   rÂ   s   & r+   rÅ   rÆ   :  s   é € ÐG¡˜"·9±9ÀÑ3F—A’A£ùrÈ   c              3   ór   "  € T F-  qP                   R9   g   K  VP                  ;'       g    ^ x € K/  	  R# 5i)r´   N©r´   rµ   )r¯   r!   rÂ   s   & r+   rÅ   rÆ   ;  s(   é € Ðg±¨"Ç9Á9ÐPfÑCfœ˜Ÿ™Ÿ˜ Aœ³ùs   ‚7™7¬7ÚuploadsÚ	downloadsÚdeletesÚskipsÚ
total_size)ÚsumÚ
operations)r)   rÎ   rÏ   rÐ   rÑ   rÒ   s   &     r+   ÚsummaryÚSyncPlan.summary6  s‰   € ÜÑK $§/¢/ÓKÓKˆÜÑO D§O¢OÓOÓOˆ	ÜÑK $§/¢/ÓKÓKˆÜÑG §¢ÓGÓGˆÜÑg°·²ÓgÓgˆ
à�wØ˜Ø�wØ�UØ˜*ð
ð 	
r.   c                óZ   <€ V ^8„  d   Qh/ S[ ;R&   S[ ;R&   S[ ;R&   S[S[,          ;R&   # )r0   rO   ÚdestÚ	timestamprÔ   )r1   Úlistr­   )r4   r5   s   "€r+   r6   r¾   -  s;   ø‡ ‚ ñ �Kñ	 ñ
 �Iñ ñ �Nñ ñ ‘]Õ#ÑAò r.   r#   N)r9   r:   r;   r<   r=   r   rÚ   rÔ   rÕ   r>   r?   r@   rA   s   @r+   rº   rº   -  s%   ø‡ € á*ñ
 ',¸DÔ&A€J÷
ð 
÷ ƒ r.   rº   c                   óL   a € ] tR tRt o RtR	V 3R lR lltV 3R lR ltRtV tR# )
ÚFilterMatcheriJ  zëMatches file paths against include/exclude patterns.

Matching is case-sensitive on every platform, like bucket paths. Backslashes in patterns are treated as path
separators, since bucket paths and local relative paths always use `/`.
Nc          	      óœ   <€ V ^8„  d   QhRS[ S[,          R,          RS[ S[,          R,          RS[ S[S[S[3,          ,          R,          /# )r0   Úinclude_patternsNÚexclude_patternsÚfilter_rules)rÚ   r1   Útuple)r4   r5   s   "€r+   r6   ÚFilterMatcher.__annotate__Q  sR   ø€ ÷ añ aá™s�) dÕ*ðañ ™s�) dÕ*ðañ ™5¡¡c �?Õ+¨dÕ2ñ	ar.   c                ó.  € T;'       g    .  Uu. uF  p\        V4      NK  	  upV n        T;'       g    .  Uu. uF  p\        V4      NK  	  upV n        T;'       g    .  UUu. uF  w  rTV\        V4      3NK  	  uppV n        R# u upi u upi u uppi )zêInitialize the filter matcher.

Args:
    include_patterns: Patterns to include (from --include)
    exclude_patterns: Patterns to exclude (from --exclude)
    filter_rules: Rules from filter file as list of ("+"/"-", pattern) tuples
N)r   rÞ   rß   rà   )r)   rÞ   rß   rà   ÚpÚsigns   &&&&  r+   r,   ÚFilterMatcher.__init__Q  sš   € ð DT×CYÐCYÐWYÐCYÓ ZÑCY¸aÔ!6°qÖ!9ÑCYÑ ZˆÔØCS×CYÐCYÐWYÐCYÓ ZÑCY¸aÔ!6°qÖ!9ÑCYÑ ZˆÔØMY×M_ÐM_Ð]_ÐM_Ô`ÑM_Á'À$˜dÔ$9¸!Ó$<Ó=ÑM_Ò`ˆÖùò ![ùÚ ZùÛ`s   �B¹BÁ$Bc                ó&   <€ V ^8„  d   QhRS[ RS[/# r    r©   )r4   r5   s   "€r+   r6   râ   b  s   ø€ ÷ ñ ™Cð ¡Dñ r.   c                óf  € V P                    F(  w  r#\        P                  ! W4      '       g   K#  VR8H  u # 	  V P                   F"  p\        P                  ! W4      '       g   K!   R# 	  V P                   F"  p\        P                  ! W4      '       g   K!   R# 	  V P                  '       d   R# R# )zÞCheck if a path should be included based on the filter rules.

Filtering rules:
- Filters are evaluated in order, first matching rule decides
- If no rules match, include by default (unless include patterns are specified)
Ú+FT)rà   ÚfnmatchÚfnmatchcaserß   rÞ   )r)   rU   rå   Úpatterns   &&  r+   ÚmatchesÚFilterMatcher.matchesb  s“   € ð "×.Ô.‰MˆDÜ×"Ò" 4×1Ô1Ø˜s‘{Ò"ñ /ð
 ×,Ô,ˆGÜ×"Ò" 4×1Ô1Úñ -ð ×,Ô,ˆGÜ×"Ò" 4×1Ô1Úñ -ð
 × × Ð Ùñ r.   )rß   rà   rÞ   )NNN)	r9   r:   r;   r<   r=   r,   rí   r?   r@   rA   s   @r+   rÜ   rÜ   J  s    ø‡ € ñ÷aò a÷"ö r.   rÜ   c                óh   € V ^8„  d   QhR\         R\        \        \         \         3,          ,          /# )r0   Úfilter_filerJ   )r1   rÚ   rá   )r4   s   "r+   r6   r6     s'   € ÷ ñ ¤Cð ¬D´´s¼C°xµÕ,Añ r.   c                ó  € . p\        V 4      ;_uu_ 4       pV FÉ  pVP                  4       pV'       d   VP                  R4      '       d   K4  VP                  R4      '       d+   VP                  RVR,          P                  4       34       Ku  VP                  R4      '       d+   VP                  RVR,          P                  4       34       K¶  VP                  RV34       KË  	  RRR4       V#   + '       g   i     T# ; i)zêParse a filter file and return a list of (sign, pattern) tuples.

Filter file format:
- Lines starting with "+" are include patterns
- Lines starting with "-" are exclude patterns
- Empty lines and lines starting with "#" are ignored
Ú#ré   ºé   NNÚ-N)Úopenr~   r   Úappend)rð   ÚrulesÚfÚlines   &   r+   Ú_parse_filter_filerû     sÃ   € ð €EÜ	ˆk×	Ô	˜aÛˆDØ—:‘:“<ˆDß˜4Ÿ?™?¨3×/Ò/ÙØ�‰˜s×#Ò#Ø—‘˜c 4¨¥8§>¡>Ó#3Ð4Ö5Ø—‘ ×%Ò%Ø—‘˜c 4¨¥8§>¡>Ó#3Ð4Ö5ð —‘˜c 4˜[Ö)ñ ÷ 
ð €L÷ 
Ö	ð €Lús   –4C0ÁC0Á$A C0Â%AC0Ã0D	c                ó`   € V ^8„  d   QhR\         R\        \        \        3,          R,          /# )r0   rU   rJ   N)r1   rá   r3   Úfloat)r4   s   "r+   r6   r6   œ  s(   € ÷ *ñ *”cð *œe¤C¬ JÕ/°$Õ6ñ *r.   c                óâ   €  \         P                  ! V 4      p\        P                  ! TP                  4      '       d   R# TP
                  TP                  R,          3#   \         d     R# i ; i)z»Stat a local file and return (size, mtime_ms).

Returns None if the path is missing or is a directory. Uses a single
``os.stat`` call so callers don't pay for multiple syscalls per file.
Nr   )rT   ÚstatÚOSErrorÚS_ISDIRÚst_modeÚst_sizeÚst_mtime)rU   Ústs   & r+   Ú_stat_localr  œ  sX   € ðÜ�WŠW�T‹]ˆô ‡|‚|�B—J‘J×ÒÙØ�:‰:�r—{‘{ TÕ)Ð)Ð)øô	 ô Úðús   ‚A ÁA.Á-A.c                ór   € V ^8„  d   QhR\         R\        \        \         \        \        3,          ,          /# )r0   Ú
local_pathrJ   )r1   r   rá   r3   rý   )r4   s   "r+   r6   r6   «  s*   € ÷ 7ñ 7¤#ð 7¬(´5¼¼cÄ5¸Õ3IÕ*Jñ 7r.   c              #  ó
  "  € \         P                  P                  V 4      p \         P                  P                  V 4      '       g   \	        RV  24      h\         P
                  ! V 4       F’  w  rpV F†  p\         P                  P                  W4      p\        V4      pVf   K3  \         P                  P                  WP4      pVP                  \         P                  R4      pWv^ ,          V^,          3x € Kˆ  	  K”  	  R# 5i)zgList all files in a local directory.

Yields:
    tuple: (relative_path, size, mtime_ms) for each file
z Local path must be a directory: Nry   )rT   rU   ÚabspathÚisdirrƒ   Úwalkr¥   r  Úrelpathr}   Úsep)r  ÚrootÚ_ÚfilesÚfilenameÚ	full_pathÚ	stat_infoÚrel_paths   &       r+   Ú_list_local_filesr  «  sÀ   é € ô —‘—‘ Ó,€JÜ�7‰7�=‰=˜×$Ò$ÜÐ;¸J¸<ÐHÓIÐIäŸ'š' *Ö-‰ˆ�ÛˆHÜŸ™Ÿ™ TÓ4ˆIÜ# IÓ.ˆIØÒ ÙÜ—w‘w—‘ yÓ=ˆHà×'Ñ'¬¯©°Ó4ˆHØ a�L¨)°A­,Ð6Ô6ó ó .ùs   ‚DDc                óŒ   € V ^8„  d   QhRRR\         R\         R\        \        \         \        \        \
        3,          ,          /# )r0   Úapir   r†   r§   rJ   )r1   r   rá   r3   rý   r	   )r4   s   "r+   r6   r6   Á  s?   € ÷ 2ñ 2˜Gð 2´ð 2¼Sð 2ÄXÌeÔTWÔY\Ô^cÔehÐThÕNiÕEjñ 2r.   c              #  ó  "  € T P                  Y;'       g    RRR7       Fà  p\        V\        4      '       d   K  VP                  pV'       d`   VP	                  VR,           4      '       d   V\        V4      ^,           R pM-WB8X  d$   RV9   d   VP                  R^4      R,          MTpMKŽ  Tp\        V4       VP                  '       d"   VP                  P                  4       R,          M^ pWSP                  Wc3x € Kâ  	  R# 5i)zÄList all files in a bucket with a given prefix.

Yields:
    tuple: (relative_path, size, mtime_ms, bucket_file) for each file.
        bucket_file is the BucketFile object from list_bucket_tree.
NT)r§   Ú	recursivery   r   éÿÿÿÿ)Úlist_bucket_treerN   r™   rU   r   r€   Úrsplitr   rX   rÙ   r!   )r  r†   r§   ÚitemrU   r  Úmtime_mss   &&&    r+   Ú_list_remote_filesr   Á  sÓ   é € ð ×$Ñ$ Y·~°~ÀÐQUÐ$ÖVˆÜ�dœL×)Ò)ÙØ�y‰yˆ÷ Ø�‰˜v¨�|×,Ò,Ø¤ F£¨a¥Ð 1Ð2‘Ø”à69¸T´k˜4Ÿ;™; s¨AÓ.¨rÖ2Àt‘ñ àˆHä# HÔ-Ø48·J·J°J�4—:‘:×'Ñ'Ó)¨DÖ0ÀAˆØŸ	™	 8Ð1Ô1ó+ Wùs   ‚ADÁDÁ-BDc                ó0   € V ^8„  d   QhR\         R\        /# )r0   r  rJ   )rý   r1   )r4   s   "r+   r6   r6   å  s   € ÷ Pñ PœEð P¤cñ Pr.   c                óx   € \         P                  ! V R,          \        P                  R7      P	                  4       # )z3Convert mtime in milliseconds to ISO format string.r   )Útz)r   Úfromtimestampr   ÚutcÚ	isoformat)r  s   &r+   Ú_mtime_to_isor'  å  s&   € ä×!Ò! (¨T¥/´h·l±lÔC×MÑMÓOÐOr.   r³   c                óÐ   € V ^8„  d   QhR\         R\        R,          R\        R\        R\        R\        R\         R\         R	\        R
\        R\        R\
        R,          R\        /# )r0   rU   r¯   Úsource_sizeÚsource_mtimeÚ	dest_sizeÚ
dest_mtimeÚsource_newer_labelÚdest_newer_labelÚignore_sizesÚignore_timesÚignore_existingr³   NrJ   rÍ   )r1   r
   r3   rý   r2   r	   r­   )r4   s   "r+   r6   r6   ê  s´   € ÷ ESñ ESä
ðESô Ð(Õ)ðESô ð	ESô
 ðESô ðESô ðESô ðESô ðESô ðESô ðESô ðESô �t•ðESô ñESr.   c           	     ó(  € \        VR8X  d   TMT4      p\        VR8X  d   TMT4      pRV RVRVRV/pV
'       d   \        RRRRR	/VB # W$8g  pW5,
          \        8„  pV'       dD   V'       d   \        RRVRVR
V/VB # WS,
          \        8„  pV'       d   TMRp\        RRRRV/VB # V	'       d)   V'       d   \        RRVRRR
V/VB # \        RRRRR/VB # V'       g	   V'       d   V'       d   RMTp\        RRVRVR
V/VB # \        RRRRR/VB # )aS  Compare source and dest files and return the appropriate sync operation.

This is a unified helper for both upload and download directions.

Args:
    path: Relative file path
    action: "upload" or "download"
    source_size: Size of the source file (bytes)
    source_mtime: Mtime of the source file (milliseconds)
    dest_size: Size of the destination file (bytes)
    dest_mtime: Mtime of the destination file (milliseconds)
    source_newer_label: Label when source is newer (e.g., "local newer" or "remote newer")
    dest_newer_label: Label when dest is newer (e.g., "remote newer" or "local newer")
    ignore_sizes: Only compare mtime
    ignore_times: Only compare size
    ignore_existing: Skip files that exist on receiver
    bucket_file: BucketFile object (for downloads only)

Returns:
    SyncOperation describing the action to take
r´   rU   r!   r±   r²   r¯   r·   r°   z&exists on receiver (--ignore-existing)r³   z
same mtimezsize differsz	same sizeÚ	identicalr#   )r'  r­   Ú_SYNC_TIME_WINDOW_MS)rU   r¯   r)  r*  r+  r,  r-  r.  r/  r0  r1  r³   Úlocal_mtime_isoÚremote_mtime_isoÚbase_kwargsÚsize_differsÚsource_newerÚ
dest_newerÚskip_reasonr°   s   $$$$$$$$$$$$        r+   Ú_compare_files_for_syncr<  ê  sW  € ôH $°F¸hÔ4F¡LÈJÓW€OÜ$°6¸XÔ3E¡ZÈ<ÓXÐð 	�Ø�Ø�ØÐ(ð	#€K÷ ÜÑk FÐkÐ3[ÐkÐ_jÑkÐkàÑ+€LØ Õ-Ô1EÑE€LçßÜ Ñr¨ÐrÐ7IÐrÐWbÐrÐfqÑrÐrà$Õ3Ô7KÑKˆJß.8Ñ*¸lˆKÜ ÑR¨ÐR°{ÐRÀkÑRÐRß	ßÜ Ñn¨Ðn°~ÐnÐS^ÐnÐbmÑnÐnä ÑR¨ÐR°{ÐRÀkÑRÐRçŸ<ß'3‘^Ð9KˆFÜ Ñf¨Ðf°vÐfÈ;ÐfÐZeÑfÐfä ÑR¨ÐR°{ÐRÀkÑRÐRr.   Fc                ó°   € V ^8„  d   QhR\         R\         RRR\        R\        R\        R\        R	\        R
\        R,          R\        R,          R\        /# )r0   rO   rØ   r  r   r¶   r0  r/  Úexistingr1  Úfilter_matcherNÚstatusrJ   )r1   r2   rÜ   r	   rº   )r4   s   "r+   r6   r6   2  sŒ   € ÷ tñ tÜðtä
ðtð 
ðtô ð	tô
 ðtô ðtô ðtô ðtô " DÕ(ðtô �$�Jðtô ñtr.   c
                ól  € T;'       g    \        4       p\        V 4      '       * ;'       d    \        V4      p
\        V 4      ;'       d    \        V4      '       * pV
'       g   V'       g   \        R4      h\        V V\        P
                  ! \        P                  4      P                  4       R7      pRpV
'       Ed‘   \        P                  P                  V 4      p\        V4      pVP                  VP                  pp\        P                  P                  V4      '       g   \        RV 24      h/ p\!        V4       FM  w  pppVP#                  V4      '       d   VV3VV&   V	'       g   K/  V	P%                  R\'        V4       R24       KO  	  V	'       d   V	P)                  R\'        V4       R24       / pV	'       d    VP+                  V4      P,                  p \1        VVV4       F[  w  ppppVP#                  V4      '       d   VV3VV&   V	'       g   K0  Ve   RV 2MRpV	P%                  R	\'        V4       V R24       K]  	  V	'       d   V	P)                  R	\'        V4       R24       \9        VP;                  4       4      \9        VP;                  4       4      ,          pV	'       d   V	P)                  R\'        V4       R24       \=        V4       EFo  pVP?                  V4      pVP?                  V4      pV'       d•   V'       g�   V'       dC   VP@                  PC                  \E        RVV^ ,          R\G        V^,          4      R7      4       K€  VP@                  PC                  \E        RVV^ ,          R\G        V^,          4      R7      4       KÂ  V'       dE   V'       d=   Vw  ppVw  pp VP@                  PC                  \I        VRVVVV RRVVVR7      4       EK  V'       d   EK  V'       g   EK$  V'       g   EK/  VP@                  PC                  \E        RVV^ ,          R\G        V^,          4      R7      4       EKr  	  V# \        V 4      pVP                  VP                  pp\        P                  P                  V4      p/ p/ p!V	'       d    VP+                  V4      P,                  p\1        VVV4       F`  w  pppp"VP#                  V4      '       d   VV3VV&   V"V!V&   V	'       g   K5  Ve   RV 2MRpV	P%                  R	\'        V4       V R24       Kb  	  V	'       d   V	P)                  R	\'        V4       R24       / p\        P                  P                  V4      '       dÍ   V'       d^   \!        V4       FM  w  pppVP#                  V4      '       d   VV3VV&   V	'       g   K/  V	P%                  R\'        V4       R24       KO  	  MgV Fa  p\        P                  PK                  VV4      p#\M        V#4      p$V$f   K4  V$VV&   V	'       g   KC  V	P%                  R\'        V4       R24       Kc  	  V	'       d   V	P)                  R\'        V4       R24       \9        VP;                  4       4      \9        VP;                  4       4      ,          pV	'       d   V	P)                  R\'        V4       R24       \=        V4       EF�  pVP?                  V4      pVP?                  V4      pV'       d¥   V'       g�   V'       dC   VP@                  PC                  \E        RVV^ ,          R\G        V^,          4      R7      4       K€  VP@                  PC                  \E        RVV^ ,          R\G        V^,          4      V!P?                  V4      R7      4       KÒ  V'       dU   V'       dM   Vw  pp Vw  ppVP@                  PC                  \I        VRVV VVRRVVVV!P?                  V4      R7      4       EK.  V'       d   EK9  V'       g   EKD  V'       g   EKO  VP@                  PC                  \E        RVV^ ,          R\G        V^,          4      R7      4       EK’  	  V#   \.         d     EL—i ; i  \2         d    \4        P7                  R
T R24        ELUi ; i  \.         d     ELùi ; i)zvCompute the sync plan by comparing source and destination.

Returns:
    SyncPlan with all operations to be performed
z[One of source or dest must be a bucket path (hf://buckets/...) and the other must be local.©rO   rØ   rÙ   NzSource must be a directory: zScanning local directory (z files)ry   ru   zScanning remote bucket (zBucket 'z' not found, treating as empty.zComparing files (z paths)r·   znew file (--existing))r¯   rU   r!   r°   r±   r´   znew filezlocal newerzremote newer)rU   r¯   r)  r*  r+  r,  r-  r.  r/  r0  r1  r¶   znot in source (--delete))r¯   rU   r!   r°   r²   rµ   )r¯   rU   r!   r°   r²   r³   )rU   r¯   r)  r*  r+  r,  r-  r.  r/  r0  r1  r³   )'rÜ   r«   rƒ   rº   r   Únowr   r%  r&  rT   rU   r
  r�   r   r‚   r  r  rí   r(   r€   ÚdoneÚbucket_infor&   Ú	Exceptionr   r   ÚloggerÚdebugÚsetÚkeysÚsortedÚgetrÔ   r÷   r­   r'  r<  r¥   r  )%rO   rØ   r  r¶   r0  r/  r>  r1  r?  r@  Ú	is_uploadÚis_downloadÚplanÚremote_totalr  r‰   r†   r§   Úlocal_filesr  r!   r  Úremote_filesr  Ú	total_strÚ	all_pathsrU   Ú
local_infoÚremote_infoÚ
local_sizer±   Úremote_sizer²   Úbucket_file_mapr³   Ú
local_filer  s%   &&&&&&&&&&                           r+   Ú_compute_sync_planr[  2  sž  € ð" $×6Ð6¤}£€NÜ# FÓ+Ô+×EÐE´ÀÓ0E€IÜ! &Ó)×GÐG´/À$Ó2GÔ.G€KçŸ[ÜÐvÓwÐwäØØÜ—,’,œxŸ|™|Ó,×6Ñ6Ó8ô€Dð  $€Lß€yä—W‘W—_‘_ VÓ,ˆ
Ü" 4Ó(ˆØ"ŸI™I v×':Ñ':�6ˆ	ä�w‰w�}‰}˜Z×(Ò(ÜÐ;¸J¸<ÐHÓIÐIð ˆÜ(9¸*Ö(EÑ$ˆH�d˜HØ×%Ñ% h×/Ò/Ø)-¨xÐ(8�˜HÑ%ß‰vØ—‘Ð :¼3¸{Ó;KÐ:LÈGÐTÖUñ	 )F÷
 Ø�K‰KÐ4´S¸Ó5EÐ4FÀgÐNÔOàˆßðØ"Ÿ™¨yÓ9×EÑE�ð		PÜ/AÀ#ÀyÐRXÖ/YÑ+�˜$ ¨!Ø!×)Ñ)¨(×3Ò3Ø.2°HÐ-=�L Ñ*ß‘6Ø6BÒ6N ! L >Ñ 2ÐTV�IØ—M‘MÐ$<¼SÀÓ=NÐ<OÐPYÈ{ÐZaÐ"bÖcñ 0Z÷ Ø�K‰KÐ2´3°|Ó3DÐ2EÀWÐMÔNô ˜×(Ñ(Ó*Ó+¬c°,×2CÑ2CÓ2EÓ.FÕFˆ	ßØ�K‰KÐ+¬C°	«NÐ+;¸7ÐCÔDÜ˜9×%ˆDØ$Ÿ™¨Ó.ˆJØ&×*Ñ*¨4Ó0ˆKç§+çà—O‘O×*Ñ*Ü%Ø#)Ø!%Ø!+¨A¥Ø#:Ü(5°jÀµmÓ(Dôöð —O‘O×*Ñ*Ü%Ø#+Ø!%Ø!+¨A¥Ø#-Ü(5°jÀµmÓ(Dôö÷ §à*4Ñ'�
˜KØ,7Ñ)�˜\Ø—‘×&Ñ&Ü+Ø!Ø'Ø$.Ø%0Ø"-Ø#/Ø+8Ø)7Ø%1Ø%1Ø(7ô÷÷  ’Z§K¢K·F²Fà—‘×&Ñ&Ü!Ø'Ø!Ø(¨�^Ø9Ü%2°;¸qµ>Ó%Bô÷ña &ðV €Kô_ # 6Ó*ˆØ"ŸI™I v×':Ñ':�6ˆ	Ü—W‘W—_‘_ TÓ*ˆ
ð ˆØ*,ˆßðØ"Ÿ™¨yÓ9×EÑE�ô 6HÈÈYÐX^Ö5_Ñ1ˆH�d˜H kØ×%Ñ% h×/Ò/Ø*.°Ð)9�˜XÑ&Ø,7� Ñ)ß‰vØ2>Ò2J˜a ˜~Ñ.ÐPR�	Ø—‘Ð 8¼¸\Ó9JÐ8KÈIÈ;ÐV]Ð^Ö_ñ 6`÷ Ø�K‰KÐ2´3°|Ó3DÐ2EÀWÐMÔNàˆÜ�7‰7�=‰=˜×$Ò$ßä0AÀ*Ö0MÑ,�H˜d HØ%×-Ñ-¨h×7Ò7Ø15°xÐ0@˜ HÑ-ß‘vØŸ™Ð(BÄ3À{ÓCSÐBTÐT[Ð&\Ö]ò	 1Nó !-�HÜ!#§¡§¡¨j¸(Ó!C�JÜ +¨JÓ 7�IØ Ò(Ù Ø,5�K Ñ)ß‘vØŸ™Ð(BÄ3À{ÓCSÐBTÐT[Ð&\Ö]ñ !-÷ Ø�K‰KÐ4´S¸Ó5EÐ4FÀgÐNÔOô ˜×)Ñ)Ó+Ó,¬s°;×3CÑ3CÓ3EÓ/FÕFˆ	ßØ�K‰KÐ+¬C°	«NÐ+;¸7ÐCÔDÜ˜9×%ˆDØ&×*Ñ*¨4Ó0ˆKØ$Ÿ™¨Ó.ˆJç§:çà—O‘O×*Ñ*Ü%Ø#)Ø!%Ø!,¨Q¥Ø#:Ü)6°{À1µ~Ó)Fôöð —O‘O×*Ñ*Ü%Ø#-Ø!%Ø!,¨Q¥Ø#-Ü)6°{À1µ~Ó)FØ(7×(;Ñ(;¸DÓ(Aôö	÷ §à,7Ñ)�˜\Ø*4Ñ'�
˜KØ—‘×&Ñ&Ü+Ø!Ø)Ø$/Ø%1Ø",Ø#.Ø+9Ø)6Ø%1Ø%1Ø(7Ø$3×$7Ñ$7¸Ó$=ô÷÷  !’[§Z¢Z·F²Fà—‘×&Ñ&Ü!Ø'Ø!Ø'¨�]Ø9Ü$1°*¸Qµ-Ó$@ô÷ñe &ðx €Køô} ô Úðûô #ô 	Pä�L‰L˜8 I ;Ð.MÐN×Oð	Pûô` ô Úðús<   Ça' Ç8a9 È/a9 Òb$ á'a6á5a6á9$b!â b!â$b3â2b3c                ó(   € V ^8„  d   QhR\         RR/# ©r0   rO  rJ   N©rº   )r4   s   "r+   r6   r6   .  s   € ÷ ,ñ ,”hð , dñ ,r.   c                óJ  € RRRV P                   RV P                  RV P                  RV P                  4       /pVP	                  \
        P                  ! V4      R,           4       V P                   F®  pRRR	VP                  R
VP                  RVP                  /pVP                  e   VP                  VR&   VP                  e   VP                  VR&   VP                  e   VP                  VR&   VP	                  \
        P                  ! V4      R,           4       K°  	  R# )z1Write a sync plan as JSONL to a file-like object.r�   ÚheaderrO   rØ   rÙ   rÕ   Ú
Ú	operationr¯   rU   r°   Nr!   r±   r²   )rO   rØ   rÙ   rÕ   ÚwriteÚjsonÚdumpsrÔ   r¯   rU   r°   r!   r±   r²   )rO  rù   r`  rÄ   Úop_dicts   &&   r+   Ú_write_planrg  .  sì   € ð 	�Ø�$—+‘+Ø�—	‘	Ø�T—^‘^Ø�4—<‘<“>ð€Fð ‡G�GŒD�JŠJ�vÓ Õ%Ô&ð �oŒoˆà�KØ�b—i‘iØ�B—G‘GØ�b—i‘ið	#
ˆð �7‰7ÒØ Ÿg™gˆG�F‰OØ�>‰>Ò%Ø%'§^¡^ˆG�MÑ"Ø�?‰?Ò&Ø&(§o¡oˆG�NÑ#Ø	�‰”—
’
˜7Ó# dÕ*Ö+ó r.   c                ó4   € V ^8„  d   QhR\         R\        RR/# )r0   rO  Ú	plan_filerJ   N)rº   r1   )r4   s   "r+   r6   r6   K  s!   € ÷ ñ ”Xð ¬#ð °$ñ r.   c                ó~   € \        VR4      ;_uu_ 4       p\        W4       RRR4       R#   + '       g   i     R# ; i)z!Save a sync plan to a JSONL file.ÚwN)rö   rg  )rO  ri  rù   s   && r+   Ú
_save_planrl  K  s(   € ä	ˆi˜×	Ô	 Ü�DÔ÷ 
×	×	Ò	ús   •+«<	c                ó0   € V ^8„  d   QhR\         R\        /# )r0   ri  rJ   )r1   rº   )r4   s   "r+   r6   r6   Q  s   € ÷ #ñ #œ#ð #¤(ñ #r.   c                óÚ  € \        V 4      ;_uu_ 4       pVP                  4       pRRR4       X'       g   \        RV  24      h\        P                  ! V^ ,          4      pVP                  R4      R8w  d   \        R4      h\        VR,          VR,          VR,          R	7      pVR
,           F¦  p\        P                  ! V4      pVP                  R4      R8w  d   K1  VP                  P                  \        VR,          VR,          VP                  R4      VP                  RR4      VP                  R4      VP                  R4      R7      4       K¨  	  V#   + '       g   i     EL=; i)z#Load a sync plan from a JSONL file.NzEmpty plan file: r�   r`  z0Invalid plan file: expected header as first linerO   rØ   rÙ   rB  ró   rb  r¯   rU   r!   r°   ru   r±   r²   )r¯   rU   r!   r°   r±   r²   )
rö   Ú	readlinesrƒ   rd  ÚloadsrL  rº   rÔ   r÷   r­   )ri  rù   Úlinesr`  rO  rú   rf  s   &      r+   Ú
_load_planrr  Q  s(  € ä	ˆi�Œ˜AØ—‘“ˆ÷ 
÷ ÜÐ,¨Y¨KÐ8Ó9Ð9ô �ZŠZ˜˜a�Ó!€FØ‡z�z�&Ó˜XÔ%ÜÐKÓLÐLäØ�hÕØ�F�^Ø˜Õ%ô€Dð �b—	�	ˆÜ—*’*˜TÓ"ˆØ�;‰;�vÓ +Ô-ÙØ�‰×ÑÜØ˜xÕ(Ø˜V•_Ø—[‘[ Ó(Ø—{‘{ 8¨RÓ0Ø#ŸK™K¨Ó6Ø$Ÿ[™[¨Ó8ôö		
ñ	 ð €K÷C 
�ˆús   ”EÅE*	c          
      óR   € V ^8„  d   QhR\         RRR\        R\        R,          RR/# )r0   rO  r  r   Úverboser@  NrJ   )rº   r2   r	   )r4   s   "r+   r6   r6   |  s<   € ÷ eñ eœð e wð e¼ð eÌsÐUYÍzð eÐeiñ er.   c                ó<  € \        V P                  4      '       * ;'       d    \        V P                  4      p\        V P                  4      ;'       d    \        V P                  4      '       * pV P                   F  p\	        VP
                  4       K  	  V'       Ed{   \        P
                  P                  V P                  4      p\        V P                  4      pVP                  VP                  r©. p. pV P                   EFP  pVP                  ;R8X  d’    \        P
                  P                  WvP
                  4      pV
'       d   V
 RVP
                   2MVP
                  pV'       d'   \        RVP
                   RVP                   R24       VP                  WÞ34       K§  ;R8X  di    V
'       d   V
 RVP
                   2MVP
                  pV'       d'   \        RVP
                   RVP                   R24       VP                  V4       EK  R8X  g   EK  V'       g   EK*  \        R	VP
                   RVP                   R24       EKS  	  V'       g	   V'       d¯   V'       d}   . pV'       d   VP                  R
\!        V4       R24       V'       d   VP                  R\!        V4       R24       VP#                  RP                  V4      P%                  4       4       TP'                  T	T;'       g    RT;'       g    RR7       R# R# V'       Edh   \        V P                  4      pVP                  VP                  r©\        P
                  P                  V P                  4      p\        P(                  ! VRR7       . p. pV P                   EFÉ  pVP                  R8X  dô   \        P
                  P                  WvP
                  4      p\        P(                  ! \        P
                  P+                  V4      RR7       V'       d'   \        RVP
                   RVP                   R24       VP,                  e    VP                  VP,                  V34       KÎ  V
'       d   V
 RVP
                   2MVP
                  pVP                  Wí34       EK  VP                  R8X  dl   \        P
                  P                  WvP
                  4      pV'       d'   \        RVP
                   RVP                   R24       VP                  V4       EK„  VP                  R8X  g   EK˜  V'       g   EK£  \        R	VP
                   RVP                   R24       EKÌ  	  \!        V4      ^ 8”  d9   V'       d   VP#                  R\!        V4       R24       VP/                  V	V4       V'       d'   V'       d   VP#                  R\!        V4       R24       V Fž  p\        P
                  P1                  V4      '       g   K*  \        P2                  ! V4       \        P
                  P+                  V4      pVV8w  g   Kh   \        P4                  ! V4       \        P
                  P+                  V4      pKA  	  R# R#   \6         d     K´  i ; i)zExecute a sync plan.r´   ry   z  Uploading: z (Ú)r¶   z  Deleting: r·   z  Skipping: z
uploading z filesz	deleting z, N)Úaddr¶   T)Úexist_okrµ   z  Downloading: zDownloading z	Deleting z local files)r«   rO   rØ   rÔ   r   rU   rT   r
  r�   r   r‚   r¯   r¥   Úprintr°   r÷   r€   rD  Ú
capitalizeÚbatch_bucket_filesÚmakedirsÚdirnamer³   Údownload_bucket_filesÚexistsÚremoveÚrmdirr   )rO  r  rt  r@  rM  rN  rÄ   r  r‰   r†   r§   Ú	add_filesÚdelete_pathsrZ  Úremote_pathr¦   Údownload_filesÚdelete_filesÚ	file_pathÚparents   &&&&                r+   Ú_execute_planr‰  |  s¯  € ä# D§K¡KÓ0Ô0×OÐO´_ÀTÇYÁYÓ5O€IÜ! $§+¡+Ó.×QÐQ´ÀtÇyÁyÓ7QÔ3Q€Kð �oŒoˆÜ# B§G¡GÖ,ñ ÷ €yÜ—W‘W—_‘_ T§[¡[Ó1ˆ
Ü" 4§9¡9Ó-ˆØ"ŸI™I v×':Ñ':�6ð ;=ˆ	Ø"$ˆà—/•/ˆBØ—)‘)ÞÝ!#§¡§¡¨j¿'¹'Ó!B�Jß;A V H¨A¨b¯g©g¨YÑ"7ÀrÇwÁw�KßÜ ¨b¯g©g¨Y°b¸¿¹¸À1ÐEÔFØ×$Ñ$ jÐ%>Ö?Þß;A¸6 V H¨A¨b¯g©g¨YÑ"7ÀrÇwÁw�KßÜ ¨R¯W©W¨I°R¸¿	¹	°{À!ÐDÔEØ ×'Ñ'¨×4ß�VŸwšwÜ˜L¨¯©¨	°°B·I±I°;¸aÐ@×Añ "÷" ŸßØ�ßØ—L‘L :¬c°)«nÐ-=¸VÐ!DÔEßØ—L‘L 9¬S°Ó->Ð,?¸vÐ!FÔGØ—‘˜DŸI™I eÓ,×7Ñ7Ó9Ô:Ø×"Ñ"ØØ×%Ð% Ø#×+Ð+ tð #ö ñ %÷ 
ˆÜ" 4§;¡;Ó/ˆØ"ŸI™I v×':Ñ':�6Ü—W‘W—_‘_ T§Y¡YÓ/ˆ
ô 	�Š�J¨Õ.ð EGˆØ"$ˆà—/•/ˆBØ�y‰y˜JÔ&ÜŸW™WŸ\™\¨*·g±gÓ>�
ä—’œBŸG™GŸO™O¨JÓ7À$ÕGßÜ˜O¨B¯G©G¨9°B°r·y±y°kÀÐCÔDà—>‘>Ò-Ø"×)Ñ)¨2¯>©>¸:Ð*FÖGç;A V H¨A¨b¯g©g¨YÑ"7ÀrÇwÁw�KØ"×)Ñ)¨;Ð*C×DØ—‘˜hÔ&ÜŸW™WŸ\™\¨*·g±gÓ>�
ßÜ˜L¨¯©¨	°°B·I±I°;¸aÐ@ÔAØ×#Ñ# J×/Ø—‘˜f×$¯ªÜ˜ R§W¡W I¨R°·	±	¨{¸!Ð<×=ñ' "ô, ˆ~Ó Ô"ßØ—‘˜l¬3¨~Ó+>Ð*?¸vÐFÔGØ×%Ñ% i°Ô@÷ —lØ�K‰K˜)¤C¨Ó$5Ð#6°lÐCÔDÛ%ˆIÜ�w‰w�~‰~˜i×(Ô(Ü—	’	˜)Ô$äŸ™Ÿ™¨Ó3�Ø 
Ö*ðÜŸš Ô(Ü!#§¡§¡°Ó!8šó &ñU 
øôf #ô Úðús   Ù5ZÚZÚZc                ó(   € V ^8„  d   QhR\         RR/# r]  r^  )r4   s   "r+   r6   r6   ä  s   € ÷ *ñ *œhð *¨4ñ *r.   c                ó  € V P                  4       p\        RV P                   RV P                   24       \        RVR,           24       \        RVR,           24       \        RVR,           24       \        R	VR
,           24       R# )z!Print a summary of the sync plan.zSync plan: z -> z  Uploads: rÎ   z  Downloads: rÏ   z  Deletes: rÐ   z	  Skips: rÑ   N)rÕ   ry  rO   rØ   )rO  rÕ   s   & r+   Ú_print_plan_summaryrŒ  ä  s~   € à�l‰l‹n€GÜ	ˆK˜Ÿ™�} D¨¯©¨Ð
4Ô5Ü	ˆK˜ 	Õ*Ð+Ð
,Ô-Ü	ˆM˜' +Õ.Ð/Ð
0Ô1Ü	ˆK˜ 	Õ*Ð+Ð
,Ô-Ü	ˆI�g˜gÕ&Ð'Ð
(Ö)r.   r¶   r0  r/  r>  r1  ÚincludeÚexcludeÚfilter_fromrO  ÚapplyÚdry_runrt  ÚquietÚtokenc          $      óš  € V ^8„  d   QhR\         R,          R\         R,          RRR\        R\        R\        R	\        R
\        R\        \         ,          R,          R\        \         ,          R,          R\         R,          R\         R,          R\         R,          R\        R\        R\        R\        \         ,          R,          R\        /# )r0   rO   NrØ   r  r   r¶   r0  r/  r>  r1  r�  rŽ  r�  rO  r�  r‘  rt  r’  r“  rJ   )r1   r2   rÚ   rº   )r4   s   "r+   r6   r6   ó  sÿ   € ÷ uñ uÜ�$�Jðuä
��*ðuð 
ð	uô
 ðuô ðuô ðuô ðuô ðuô ”#�Y˜Õðuô ”#�Y˜Õðuô �t•ðuô ��*ðuô ��:ðuô ðuô  ð!uô" ð#uô$ ”#�:˜Õð%uô& ñ'ur.   c               ó.	  € VeG   ^RI Hp V! VP                  VVP                  VP                  VP
                  VP                  R7      pV'       EdX   V '       g	   V'       d   \        R4      hVe   \        R4      hV'       d   \        R4      hV'       d   \        R4      hV'       d   \        R4      hV'       d   \        R	4      hV	'       d   \        R
4      hV
'       d   \        R4      hV'       d   \        R4      hV'       d   \        R4      hV'       d   \        R4      h\        V4      p\        V'       * R7      pV'       g   \        V4       \        R4       V'       d   \        4         \        VW.VR7       V'       d   \        4        T'       g   \        R4       T# V '       d	   V'       g   \        R4      h\        V 4      p\        V4      pV'       d   V'       d   \        R4      hV'       g   V'       g   \        R4      hV'       d   V'       d   \        R4      hV'       d   V'       d   \        R4      hV'       d   V'       d   \        R4      hV'       dZ   \         P"                  P%                  V4      '       d4   \         P"                  P'                  V4      '       g   \        RV 24      hM3\         P"                  P'                  V 4      '       g   \        RV  24      hRpV
'       d   \)        V
4      p\+        VV	VR7      p\        V'       * ;'       d    V'       * R7      p\-        V VVVVVVVVVR7
      pV'       d   \/        V\0        P2                  4       V# V'       d0   \5        VV4       V'       g   \        V4       \        RV 24       V# V'       g   \        V4       VP7                  4       pVR,          ^ 8X  d2   VR,          ^ 8X  d$   VR ,          ^ 8X  d   V'       g   \        R!4       V# V'       g   \        R"4       V'       d   \        4         \        VW.VR7       V'       d   \        4        T'       g   \        R4       T#   T'       d   \        4        i i ; i  T'       d   \        4        i i ; i)#a  Sync files between a local directory and a bucket.

This is equivalent to the ``hf buckets sync`` CLI command. One of ``source`` or ``dest`` must be a bucket path
(``hf://buckets/...``) and the other must be a local directory path.

Args:
    source (`str`, *optional*):
        Source path: local directory or ``hf://buckets/namespace/bucket_name(/prefix)``.
        Required unless using ``apply``.
    dest (`str`, *optional*):
        Destination path: local directory or ``hf://buckets/namespace/bucket_name(/prefix)``.
        Required unless using ``apply``.
    api ([`HfApi`]):
        The HfApi instance to use for API calls.
    delete (`bool`, *optional*, defaults to `False`):
        Delete destination files not present in source.
    ignore_times (`bool`, *optional*, defaults to `False`):
        Skip files only based on size, ignoring modification times.
    ignore_sizes (`bool`, *optional*, defaults to `False`):
        Skip files only based on modification times, ignoring sizes.
    existing (`bool`, *optional*, defaults to `False`):
        Skip creating new files on receiver (only update existing files).
    ignore_existing (`bool`, *optional*, defaults to `False`):
        Skip updating files that exist on receiver (only create new files).
    include (`list[str]`, *optional*):
        Include files matching patterns (fnmatch-style).
    exclude (`list[str]`, *optional*):
        Exclude files matching patterns (fnmatch-style).
    filter_from (`str`, *optional*):
        Path to a filter file with include/exclude rules.
    plan (`str`, *optional*):
        Save sync plan to this JSONL file instead of executing.
    apply (`str`, *optional*):
        Apply a previously saved plan file. When set, ``source`` and ``dest`` are not needed.
    dry_run (`bool`, *optional*, defaults to `False`):
        Print sync plan to stdout as JSONL without executing.
    verbose (`bool`, *optional*, defaults to `False`):
        Show detailed per-file operations.
    quiet (`bool`, *optional*, defaults to `False`):
        Suppress all output and progress bars.
    token (Union[bool, str, None], optional):
        A valid user access token. If not provided, the locally saved token will be used.

Returns:
    [`SyncPlan`]: The computed (or loaded) sync plan.

Raises:
    `ValueError`: If arguments are invalid (e.g., both paths are remote, conflicting options).

Example:
    ```python
    >>> from huggingface_hub import HfApi
    >>> api = HfApi()

    # Upload local directory to bucket
    >>> api.sync_bucket("./data", "hf://buckets/username/my-bucket")

    # Download bucket to local directory
    >>> api.sync_bucket("hf://buckets/username/my-bucket", "./data")

    # Sync with delete and filtering
    >>> api.sync_bucket(
    ...     "./data",
    ...     "hf://buckets/username/my-bucket",
    ...     delete=True,
    ...     include=["*.safetensors"],
    ... )

    # Dry run: preview what would be synced
    >>> plan = api.sync_bucket("./data", "hf://buckets/username/my-bucket", dry_run=True)
    >>> plan.summary()
    {'uploads': 3, 'downloads': 0, 'deletes': 0, 'skips': 1, 'total_size': 4096}

    # Save plan for review, then apply
    >>> api.sync_bucket("./data", "hf://buckets/username/my-bucket", plan="sync-plan.jsonl")
    >>> api.sync_bucket(apply="sync-plan.jsonl")
    ```
Nr   )rz   r“  Úlibrary_nameÚlibrary_versionÚ
user_agentÚheadersz,Cannot specify source/dest when using apply.z#Cannot specify both plan and apply.z'Cannot specify delete when using apply.z-Cannot specify ignore_times when using apply.z-Cannot specify ignore_sizes when using apply.z(Cannot specify include when using apply.z(Cannot specify exclude when using apply.z,Cannot specify filter_from when using apply.z)Cannot specify existing when using apply.z0Cannot specify ignore_existing when using apply.z(Cannot specify dry_run when using apply.)ÚenabledzExecuting plan...)rt  r@  zSync completed.z7Both source and dest are required (unless using apply).z?Remote to remote sync is not supported. One path must be local.z?One of source or dest must be a bucket path (hf://buckets/...).z2Cannot specify both ignore_times and ignore_sizes.z1Cannot specify both existing and ignore_existing.z%Cannot specify both dry_run and plan.z!Destination must be a directory: z&Source must be an existing directory: )rÞ   rß   rà   )
rO   rØ   r  r¶   r0  r/  r>  r1  r?  r@  zPlan saved to: rÎ   rÏ   rÐ   zNothing to sync.z
Syncing...)Úhf_apir   rz   r–  r—  r˜  r™  rƒ   rr  r   rŒ  ry  r   r‰  r   r«   rT   rU   r  r  rû   rÜ   r[  rg  ÚsysÚstdoutrl  rÕ   )rO   rØ   r  r¶   r0  r/  r>  r1  r�  rŽ  r�  rO  r�  r‘  rt  r’  r“  r   Ú	sync_planr@  Úsource_is_bucketÚdest_is_bucketrà   r?  rÕ   s   &&$$$$$$$$$$$$$$$        r+   Úsync_bucket_internalr¡  ó  s˜  € ðF ÒÝ!áØ—\‘\ØØ×)Ñ)Ø×/Ñ/Ø—~‘~Ø—K‘Kô
ˆ÷ €uß—TÜÐKÓLÐLØÒÜÐBÓCÐCßÜÐFÓGÐGßÜÐLÓMÐMßÜÐLÓMÐMßÜÐGÓHÐHßÜÐGÓHÐHßÜÐKÓLÐLßÜÐHÓIÐIßÜÐOÓPÐPßÜÐGÓHÐHä˜uÓ%ˆ	Ü¨¤IÔ.ˆßÜ 	Ô*ÜÐ%Ô&çÜ!Ô#ð	'Ü˜) SÀ&ÕIçÜ$Ô&çÜÐ#Ô$àÐ÷ ŸÜÐRÓSÐSä& vÓ.ÐÜ$ TÓ*€NçŸNÜÐZÓ[Ð[ç§NÜÐZÓ[Ð[çŸÜÐMÓNÐNç—OÜÐLÓMÐMç—4ÜÐ@ÓAÐA÷ Ü�7‰7�>‰>˜$×Ò¬¯©¯©°d×(;Ò(;ÜÐ@ÀÀÐGÓHÐHøä�w‰w�}‰}˜V×$Ò$ÜÐEÀfÀXÐNÓOÐOð €LßÜ)¨+Ó6ˆä"Ø Ø Ø!ô€Nô  E¤	× 9Ð 9°'¬kÔ:€FÜ"ØØØØØ!Ø!ØØ'Ø%Øô€I÷ Ü�IœsŸz™zÔ*ØÐçÜ�9˜dÔ#ßÜ 	Ô*Ü�O D 6Ð*Ô+ØÐ÷ Ü˜IÔ&à×ÑÓ!€GØˆyÕ˜QÔ 7¨;Õ#7¸1Ô#<ÀÈÕASÐWXÔAXßÜÐ$Ô%ØÐçÜˆlÔçÜÔð#Ü�i ¸fÕEçÜ Ô"çÜÐÔ àÐø÷G Ü$Õ&ð û÷z Ü Õ"ð ús   Å6Q' Ð2Q? Ñ'Q<Ñ?R)FFFFFNN)FN)NN)Ir=   rê   rd  rP   rT   rÿ   rœ  rW   Úcollections.abcr   Údataclassesr   r   r   r   Úpathlibr   Útypingr   r	   r
   ru   r   r   Ú_local_folderr   Úerrorsr   Úutilsr   r   r   r   r   r   r   Úutils._hf_urisr   Úutils._pathsr   r›  r   Ú
get_loggerr9   rG  ÚBUCKET_PREFIXr4  r   rC   r`   rj   ro   rt   rŽ   r™   r�   r«   r­   rº   rÜ   rû   r  r  r   r'  r<  r[  rg  rl  rr  r‰  rŒ  r¡  r#   r.   r+   Ú<module>r­     sŒ  ðñó
 Û Û Û 	Û Û 
Û Ý $ß (ß 'Ý ß .Ñ .ç  Ý 6Ý '÷÷ ñ õ /Ý /÷ Ýð 
×	Ò	˜HÓ	%€ð  €ØÐ ð ÷'ð 'ó ð'ð@ ÷
ð 
ó ð
ð* ÷-ð -ó ð-ð ÷ð ó ðñ �$Ô÷ð ó ðð  ÷$ð $ó ð$ðN ÷Pð Pó ðPð2 ÷
ð 
ó ð
õ6Cõ,(ð  ÷	*ð 	*ó ð	*ð ÷
ð 
ó ð
÷82ñ 2õjõ:*õ7õ,2õHPð
ESð #÷ES÷Ptõx,õ:õ#÷VeõP*ñuð
 ðuð ðuð ðuð ðuð "ðuð !%ðuð !%ðuð #ðuð ðuð ðuð ðuð  ð!uð" ð#uð$  $÷%uò ur.   