+
    QV-j!°  ã                   ót  € 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HtHtHtHtH t H!t! ^R
I"H#t# ]'       d   ^RI$H%t% ]PL                  ! ]'4      t(Rt)Rt*] ! R R4      4       t+] ! R R4      4       t,] ! R R4      4       t-] ! R R4      4       t.]! RR7       ! R R4      4       t/] ! R R4      4       t0] ! R R4      4       t1] ! R R4      4       t2R  R! lt3R" R# lt4] ! R$ R%4      4       t5] ! R& R'4      4       t6 ! R( R)4      t7R* R+ lt8R, R- lt9R. R/ lt:R0 R1 lt;R2 R3 lt<R4R/R5 R6 llt=RTR8 R9 llt>R: R; lt?R< R= lt@R> R? ltARUR@ RA lltBRB RC ltCRVRDR7RER7RFR7RGR7RHR7RIRRJRRKRRLRRMRRNR7ROR7RPR7RQR/RR RS llltDR# )WzzShared 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)ÚBucketNotFoundError)ÚHfUriÚ
StatusLineÚXetFileDataÚdisable_progress_barsÚenable_progress_barsÚparse_datetimeÚparse_hf_uri)Ú_looks_like_hf_url©Ú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   &,Úi/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/huggingface_hub/_buckets.pyÚ__init__ÚBucketInfo.__init__V   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__©r3   s   @r)   r   r   >   s   ø‡ € ñò,'÷1 ƒ r,   r   c                   ó†   a € ] tR t^_t 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/# ©r.   ÚreturnNr!   )r2   r3   s   "€r)   r4   Ú_BucketAddFile.__annotate__i   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Úsourcer/   r   Ú	mimetypesÚ
guess_typeÚdestinationr1   ÚbytesÚosÚpathÚgetmtimeÚtimeÚmtime©r'   s   &r)   Ú__post_init__Ú_BucketAddFile.__post_init__i   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&   # )r.   rM   rP   NÚxet_hashr   rV   rK   )r/   r   rQ   r1   )r2   r3   s   "€r)   r4   rI   _   sf   ø‡ ‚ á‘$�J™ÕÑñ ñ Ññ ñ
 �D�jÑ.ñ ñ ��*Ñ*ñ ñ Ñ"ñ ñ ˜•*Ñ0ò r,   ©rK   rV   )r7   r8   r9   r:   r   r[   r   rV   rK   rX   r<   r=   r>   r?   s   @r)   rA   rA   _   s@   ø‡ € ñ
 !¨Ô.€HÙ TÔ*€DÙ˜EÔ"€EÙ$¨%Ô0€L÷	
ð 	
÷ ƒ r,   rA   c                   ót   a € ] tR t^ut 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# )	Ú_BucketCopyFileNrB   FrD   c                ó   <€ V ^8„  d   QhRR/# rG   r!   )r2   r3   s   "€r)   r4   Ú_BucketCopyFile.__annotate__   s   ø€ ÷ -ñ -˜tñ -r,   c                ó²   € \         P                  ! V P                  4      ^ ,          V n        \	        \
        P
                  ! 4       R,          4      V n        R# )é    r   N)rN   rO   rP   rK   r1   rU   rV   rW   s   &r)   rX   Ú_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&   # )	r.   rP   r[   Úsource_repo_typeÚsource_repo_idNr   rV   rK   )r/   r1   )r2   r3   s   "€r)   r4   r`   u   se   ø‡ ‚ áÑñ ñ �Mñ ñ Ññ	 ñ
 Ññ ñ ��*Ñ*ñ ñ Ñ"ñ ñ ˜•*Ñ0ò r,   r\   )r7   r8   r9   r:   r   r   rV   rK   rX   r<   r=   r>   r?   s   @r)   r^   r^   u   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&   # )r.   rS   )r/   )r2   r3   s   "€r)   r4   Ú_BucketDeleteFile.__annotate__„   s   ø‡ ‚ á
�Iò r,   r!   N)r7   r8   r9   r:   r<   r=   r>   r?   s   @r)   rh   rh   „   s   ø‡ ‡ „ r,   rh   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&   # )r.   r   Úxet_file_data)r1   r   )r2   r3   s   "€r)   r4   ÚBucketFileMetadata.__annotate__‰   s   ø‡ ‚ ñ �Iñ ñ Ñò r,   r!   N)r7   r8   r9   r:   r;   r<   r=   r>   r?   s   @r)   rm   rm   ‰   s   ø‡ € ñ	÷ ƒ r,   rm   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>.
Ú FrD   c                ó   <€ V ^8„  d   QhRR/# rG   r!   )r2   r3   s   "€r)   r4   Ú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# )rs   Ú/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)   rX   Ú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&   # )r.   rz   rx   rƒ   r„   r…   ©r/   r   )r2   r3   s   "€r)   r4   ru   š   sE   ø‡ ‚ ñ$ 
�Hñ% ñ& Ññ' ñ( Ñ&ñ) ñ* Ñ&ñ+ ñ, 
Ñ"ò- r,   )r„   rx   rƒ   r…   N)r7   r8   r9   r:   r;   rx   r   rƒ   r„   r…   rX   r<   r=   r>   r?   s   @r)   rr   rr   š   s@   ø‡ € ñð" €HÙ Ô&€IÙ Ô&€IÙ˜EÔ"€C÷ð ÷1 ƒ r,   rr   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# )ÚtyperS   r   ÚxetHashrV   NÚ
uploadedAt)r"   rŽ   rS   r   r[   r   rV   Úuploaded_at)r'   r(   rV   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&   # )	r.   ÚfilerŽ   rS   r   r[   NrV   r‘   )r
   r/   r1   r   )r2   r3   s   "€r)   r4   ÚBucketFile.__annotate__Â   s\   ø‡ ‚ ñ �&�/Ññ ñ �Iñ ñ �Iñ ñ �Mñ ñ �d�?Ññ ñ ˜D•Ñ ò r,   )rV   rS   r   rŽ   r‘   r[   Nr6   r?   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Ž   rS   r�   Nr‘   )r"   rŽ   rS   rL   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&   # )r.   Ú	directoryrŽ   rS   Nr‘   )r
   r/   r   )r2   r3   s   "€r)   r4   ÚBucketFolder.__annotate__Ü   s4   ø‡ ‚ ñ �+Õ
Ññ ñ �Iñ ñ ˜D•Ñ ò r,   )rS   rŽ   r‘   Nr6   r?   s   @r)   r—   r—   Ü   s   ø‡ € ñò
÷ ƒ r,   r—   c                ó0   € V ^8„  d   QhR\         R\        /# ©r.   rS   rH   rŠ   )r2   s   "r)   r4   r4   ø   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/...).rw   zInvalid bucket path: 'z)'. Expected format: namespace/bucket_name:r.   NNÚbucket)rŽ   r   r€   )r}   r   ÚHF_PROTOCOLr   r   Ú	is_bucketr�   r‚   r~   Újoinr   )rS   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ž   ©r/   r0   )r2   s   "r)   r4   r4     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¢   )rS   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.Nrs   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&   # )
r.   ÚactionrS   Nr   ÚreasonÚlocal_mtimeÚremote_mtimeÚbucket_file)ÚuploadÚdownloadÚdeleteÚskip)r
   r/   r1   rŒ   )r2   r3   s   "€r)   r4   ÚSyncOperation.__annotate__  sv   ø‡ ‚ ñ Ð:Õ;Ñ;ñ	 ñ
 �Iñ ñ ��*Ññ ñ Ññ ñ �t•Ñ"ñ ñ ˜•*Ñ#ñ ñ ˜dÕ"Ñ)ò r,   r!   )r7   r8   r9   r:   r;   r   r®   r¯   r°   r±   r<   r=   r>   r?   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,          /# )r.   rH   )Údictr/   r1   )r2   r3   s   "€r)   r4   ÚSyncPlan.__annotate__4  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>5  ó   é € Ð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Ä   6  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Ä   7  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Ä   8  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Ä   9  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.summary4  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&   # )r.   rM   ÚdestÚ	timestamprÒ   )r/   Úlistr«   )r2   r3   s   "€r)   r4   r¼   +  s;   ø‡ ‚ ñ �Kñ	 ñ
 �Iñ ñ �Nñ ñ ‘]Õ#ÑAò r,   r!   N)r7   r8   r9   r:   r;   r   rØ   rÒ   rÓ   r<   r=   r>   r?   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# )
ÚFilterMatcheriH  z4Matches file paths against include/exclude patterns.Nc          	      óœ   <€ V ^8„  d   QhRS[ S[,          R,          RS[ S[,          R,          RS[ S[S[S[3,          ,          R,          /# )r.   Úinclude_patternsNÚexclude_patternsÚfilter_rules)rØ   r/   Útuple)r2   r3   s   "€r)   r4   ÚFilterMatcher.__annotate__K  sM   ø€ ÷ /ñ /á™s�) dÕ*ð/ñ ™s�) dÕ*ð/ñ ™5¡¡c �?Õ+¨dÕ2ñ	/r,   c                ól   € T;'       g    . V n         T;'       g    . V n        T;'       g    . V n        R# )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Þ   s   &&&&r)   r*   ÚFilterMatcher.__init__K  s4   € ð !1× 6Ð 6°BˆÔØ 0× 6Ð 6°BˆÔØ(×.Ð.¨BˆÖr,   c                ó&   <€ V ^8„  d   QhRS[ RS[/# rž   r§   )r2   r3   s   "€r)   r4   rà   \  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Þ   ÚfnmatchrÝ   rÜ   )r'   rS   ÚsignÚpatterns   &&  r)   ÚmatchesÚFilterMatcher.matches\  s�   € ð "×.Ô.‰MˆDÜ�Š˜t×-Ô-Ø˜s‘{Ò"ñ /ð
 ×,Ô,ˆGÜ�Š˜t×-Ô-Úñ -ð ×,Ô,ˆGÜ�Š˜t×-Ô-Úñ -ð
 × × Ð Ùñ r,   )rÝ   rÞ   rÜ   )NNN)	r7   r8   r9   r:   r;   r*   rê   r=   r>   r?   s   @r)   rÚ   rÚ   H  s   ø‡ € Ù>÷/ò /÷"ö r,   rÚ   c                óh   € V ^8„  d   QhR\         R\        \        \         \         3,          ,          /# )r.   Úfilter_filerH   )r/   rØ   rß   )r2   s   "r)   r4   r4   y  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ø   y  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,          /# )r.   rS   rH   N)r/   rß   r1   Úfloat)r2   s   "r)   r4   r4   –  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   )rR   ÚstatÚOSErrorÚS_ISDIRÚst_modeÚst_sizeÚst_mtime)rS   Ú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,          ,          /# )r.   Ú
local_pathrH   )r/   r   rß   r1   rú   )r2   s   "r)   r4   r4   ¥  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: Nrw   )rR   rS   Ú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,          ,          /# )r.   Úapir   r„   r¥   rH   )r/   r   rß   r1   rú   r	   )r2   s   "r)   r4   r4   »  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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¥   Ú	recursiverw   r   éÿÿÿÿ)
Úlist_bucket_treerL   r—   rS   r}   r~   ÚrsplitrV   r×   r   )r  r„   r¥   ÚitemrS   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Ø48·J·J°J�4—:‘:×'Ñ'Ó)¨DÖ0ÀAˆØŸ	™	 8Ð1Ô1ó' Wùs   ‚AC;ÁC;Á-AC;Ã9C;c                ó0   € V ^8„  d   QhR\         R\        /# )r.   r  rH   )rú   r/   )r2   s   "r)   r4   r4   Ý  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\        /# )r.   rS   r­   Úsource_sizeÚsource_mtimeÚ	dest_sizeÚ
dest_mtimeÚsource_newer_labelÚdest_newer_labelÚignore_sizesÚignore_timesÚignore_existingr±   NrH   rË   )r/   r
   r1   rú   r0   r	   r«   )r2   s   "r)   r4   r4   â  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²   rS   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)rS   r­   r&  r'  r(  r)  r*  r+  r,  r-  r.  r±   Úlocal_mtime_isoÚremote_mtime_isoÚbase_kwargsÚsize_differsÚsource_newerÚ
dest_newerÚskip_reasonr®   s   $$$$$$$$$$$$        r)   Ú_compare_files_for_syncr9  â  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\        /# )r.   rM   rÖ   r  r   r´   r-  r,  Úexistingr.  Úfilter_matcherNÚstatusrH   )r/   r0   rÚ   r	   r¸   )r2   s   "r)   r4   r4   *  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.©rM   rÖ   r×   NzSource must be a directory: zScanning local directory (z files)rw   rs   zScanning remote bucket (zBucket 'z' not found, treating as empty.zComparing files (z paths)rµ   znew file (--existing))r­   rS   r   r®   r¯   r²   znew filezlocal newerzremote newer)rS   r­   r&  r'  r(  r)  r*  r+  r,  r-  r.  r´   znot in source (--delete))r­   rS   r   r®   r°   r³   )r­   rS   r   r®   r°   r±   )rS   r­   r&  r'  r(  r)  r*  r+  r,  r-  r.  r±   )'rÚ   r©   r�   r¸   r   Únowr   r"  r#  rR   rS   r  r   r   r€   r  r  rê   r&   r~   ÚdoneÚbucket_infor$   Ú	Exceptionr  r   ÚloggerÚdebugÚsetÚkeysÚsortedÚgetrÒ   rô   r«   r$  r9  r£   r  )%rM   rÖ   r  r´   r-  r,  r;  r.  r<  r=  Ú	is_uploadÚis_downloadÚplanÚremote_totalr  r‡   r„   r¥   Úlocal_filesr  r   r  Úremote_filesr  Ú	total_strÚ	all_pathsrS   Ú
local_infoÚremote_infoÚ
local_sizer¯   Úremote_sizer°   Úbucket_file_mapr±   Ú
local_filer  s%   &&&&&&&&&&                           r)   Ú_compute_sync_planrX  *  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/# ©r.   rL  rH   N©r¸   )r2   s   "r)   r4   r4   &  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Ž   ÚheaderrM   rÖ   r×   rÓ   Ú
Ú	operationr­   rS   r®   Nr   r¯   r°   )rM   rÖ   r×   rÓ   ÚwriteÚjsonÚdumpsrÒ   r­   rS   r®   r   r¯   r°   )rL  rö   r]  rÂ   Úop_dicts   &&   r)   Ú_write_planrd  &  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/# )r.   rL  Ú	plan_filerH   N)r¸   r/   )r2   s   "r)   r4   r4   C  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ó   rd  )rL  rf  rö   s   && r)   Ú
_save_planri  C  s(   € ä	ˆi˜×	Ô	 Ü�DÔ÷ 
×	×	Ò	ús   •+«<	c                ó0   € V ^8„  d   QhR\         R\        /# )r.   rf  rH   )r/   r¸   )r2   s   "r)   r4   r4   I  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 linerM   rÖ   r×   r?  rð   r_  r­   rS   r   r®   rs   r¯   r°   )r­   rS   r   r®   r¯   r°   )
ró   Ú	readlinesr�   ra  ÚloadsrI  r¸   rÒ   rô   r«   )rf  rö   Úlinesr]  rL  r÷   rc  s   &      r)   Ú
_load_planro  I  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/# )r.   rL  r  r   Úverboser=  NrH   )r¸   r0   r	   )r2   s   "r)   r4   r4   t  s<   € ÷ añ aœð a wð a¼ð aÌsÐUYÍzð aÐeiñ ar,   c                óì  € \        V P                  4      '       * ;'       d    \        V P                  4      p\        V P                  4      ;'       d    \        V P                  4      '       * p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                  WlP                  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                  WlP                  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                  WlP                  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                  P/                  V4      '       g   K*  \        P0                  ! V4       \        P                  P)                  V4      pVV8w  g   Kh   \        P2                  ! V4       \        P                  P)                  V4      pKA  	  R# R#   \4         d     K´  i ; i)zExecute a sync plan.r²   rw   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©   rM   rÖ   rR   rS   r  r   r   r€   rÒ   r­   r£   Úprintr®   rô   r~   rA  Ú
capitalizeÚbatch_bucket_filesÚmakedirsÚdirnamer±   Údownload_bucket_filesÚexistsÚremoveÚrmdirrý   )rL  r  rq  r=  rJ  rK  r  r‡   r„   r¥   Ú	add_filesÚdelete_pathsrÂ   rW  Úremote_pathr¤   Údownload_filesÚdelete_filesÚ	file_pathÚparents   &&&&                r)   Ú_execute_planr†  t  s‘  € ä# D§K¡KÓ0Ô0×OÐO´_ÀTÇYÁYÓ5O€IÜ! $§+¡+Ó.×QÐQ´ÀtÇyÁyÓ7QÔ3Q€Kç€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   Ø'5Y$Ù$Y3Ù2Y3c                ó(   € V ^8„  d   QhR\         RR/# rZ  r[  )r2   s   "r)   r4   r4   Ø  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Ó   rv  rM   rÖ   )rL  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´   r-  r,  r;  r.  ÚincludeÚexcludeÚfilter_fromrL  ÚapplyÚdry_runrq  Ú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\        /# )r.   rM   NrÖ   r  r   r´   r-  r,  r;  r.  rŠ  r‹  rŒ  rL  r�  rŽ  rq  r�  r�  rH   )r/   r0   rØ   r¸   )r2   s   "r)   r4   r4   ç  sÿ   € ÷ nñ nÜ�$�Jðnä
��*ðnð 
ð	nô
 ðnô ðnô ðnô ðnô ðnô ”#�Y˜Õðnô ”#�Y˜Õðnô �t•ðnô ��*ðnô ��:ðnô ðnô  ð!nô" ð#nô$ ”#�:˜Õð%nô& ñ'nr,   c               óÀ  € Ve   ^RI Hp V! V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\&        P(                  4       V# V'       d0   \+        VV4       V'       g   \        V4       \        RV 24       V# V'       g   \        V4       VP-                  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   )r�  z,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...)rq  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â   )
rM   rÖ   r  r´   r-  r,  r;  r.  r<  r=  zPlan saved to: rÌ   rÍ   rÎ   zNothing to sync.z
Syncing...)Úhf_apir   r�   ro  r   r‰  rv  r   r†  r   r©   rR   rS   r|  r  rø   rÚ   rX  rd  ÚsysÚstdoutri  rÓ   )rM   rÖ   r  r´   r-  r,  r;  r.  rŠ  r‹  rŒ  rL  r�  rŽ  rq  r�  r�  r   Ú	sync_planr=  Úsource_is_bucketÚdest_is_bucketrÞ   r<  rÓ   s   &&$$$$$$$$$$$$$$$        r)   Úsync_bucket_internalrš  ç  sl  € ðF ÒÝ!á˜%Ô ˆç€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   Ä?P0 Ï;Q Ð0QÑQ)FFFFFNN)FN)NN)Er;   rç   ra  rN   rR   rü   r•  rU   Úcollections.abcr   Údataclassesr   r   r   r   Úpathlibr   Útypingr   r	   r
   rs   r   r   Úerrorsr   Úutilsr   r   r   r   r   r   r   Úutils._hf_urisr   r”  r   Ú
get_loggerr7   rD  ÚBUCKET_PREFIXr1  r   rA   r^   rh   rm   rr   rŒ   r—   r   r©   r«   r¸   rÚ   rø   r  r  r  r$  r9  rX  rd  ri  ro  r†  r‰  rš  r!   r,   r)   Ú<module>r¤     s†  ðñó
 Û Û Û 	Û Û 
Û Ý $ß (ß 'Ý ß .Ñ .ç  Ý '÷÷ ñ õ /÷ Ýð 
×	Ò	˜HÓ	%€ð  €ØÐ ð ÷'ð 'ó ð'ð@ ÷
ð 
ó ð
ð* ÷-ð -ó ð-ð ÷ð ó ðñ �$Ô÷ð ó ðð  ÷$ð $ó ð$ðN ÷Pð Pó ðPð2 ÷
ð 
ó ð
õ6Cõ,(ð  ÷	*ð 	*ó ð	*ð ÷
ð 
ó ð
÷8.ñ .õbõ:*õ7õ,2õDPð
ESð #÷ES÷Ptõx,õ:õ#÷VaõH*ñnð
 ðnð ðnð ðnð ðnð "ðnð !%ðnð !%ðnð #ðnð ðnð ðnð ðnð  ð!nð" ð#nð$  $÷%nò nr,   