+
    Pj                     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   &,q/Users/ahmed/devFolder/Ultron/claude-voice/gateway/.venv/lib/python3.14/site-packages/huggingface_hub/_buckets.py__init__BucketInfo.__init__V   sm    **T"zz),(K)@AJJv&	!::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     dkkC;// ) 4 4T[[ A! DD$ ) 4 4T5E5E Fq ID8B4;;PU8V8VBGGT[[)D0\`\e\e\gjn\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   
 Dj.  **  "  *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$%0L	
 	
  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1A1AB1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$%0L- -  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    ;;);); 88##DMM26<<SAz**J 12H"8,;DHH: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    JJv&	JJv&	JJv&	

9-

7D).3^E*
jj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    JJv&	JJv&	jjt4WW

=RV8W  '{H==[ 	CQR]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      # )	zParse 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,,--1CD1I1Id#4TF:deffJJsAE
5zA~U1XXU1XX1$7`abb8*AeAhZ(IXXeBi Fh9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                  # )zCheck 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!     
 
c39n- 
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/BYY(5Jaa/   #
#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     OObyyJ7NOr   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"993FAA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"99PfCf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ODOO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&AJ
 
  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# )zInitialize 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 6B 0 6 6B(..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# )zCheck 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     "..MD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sCx,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)zParse 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##c48>>#345%%c48>>#345 c4[)  
 L 
	 Ls   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 *eCJ/$6 *r,   c                     \         P                  ! V 4      p\        P                  ! TP                  4      '       d   R# TP
                  TP                  R,          3#   \         d     R# i ; i)zStat 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    WWT] ||BJJ::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c5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77==$$;J<HII''*-HT4I#I.I wwy=H''4HaL)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 2G 2 2S 2XeTWY\^cehThNiEj 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)zList 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dL))yy v|,,Fa 1269Tk4;;sA.r2t H48JJJ4::'')D0A		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/hll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 $Fh4FLJWO$6X3EZ<X 	(	#K kFk3[k_jkk+L -1EEL rr7IrWbrfqrr$37KKJ.8*lK RR{RkRR	 nn~nS^nbmnn RR{RkRR<'3^9KF ffvf;fZeff RR{Rk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Li ; i  \2         d    \4        P7                  R
T R24        ELUi ; i  \.         d     ELi ; 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0EI!&)GG/$2G.GK[vww,,x||,668D  $LyWW__V,
"4("IIv':':6	ww}}Z((;J<HII (9*(E$HdH%%h//)-x(8H%v :3{;K:LGTU	 )F
 KK4S5E4FgNO"y9EE		P/A#yRX/Y+$!!))(33.2H-=L*66B6N!L> 2TVIMM$<S=N<OPY{Za"bc 0Z KK23|3D2EWMN ((*+c,2C2C2E.FF	KK+C	N+;7CD9%D$.J&**40K+OO**%#)!%!+A#:(5jm(D OO**%#+!%!+A#-(5jm(D *4'
K,7)\&&+!'$.%0"-#/+8)7%1%1(7  ZKKFF&&!'!(^9%2;q>%Ba &V K_ #6*"IIv':':6	WW__T*
 *,"y9EE 6HYX^5_1HdHk%%h//*.)9X&,7)v2>2Ja~.PR	 8\9J8KI;V]^_ 6` KK23|3D2EWMN77==$$0A*0M,HdH%--h7715x0@H-v(B3{CSBTT[&\]	 1N !-H!#j(!CJ +J 7I ( ,5K)v(B3{CSBTT[&\] !- KK4S5E4FgNO ))+,s;3C3C3E/FF	KK+C	N+;7CD9%D&**40K$.J:OO**%#)!%!,Q#:)6{1~)F OO**%#-!%!,Q#-)6{1~)F(7(;(;D(A	 ,7)\*4'
K&&+!)$/%1",#.+9)6%1%1(7$3$7$7$=  ![ZZFF&&!'!']9$1*Q-$@e &x K}   # 	PLL8I;.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 GGDJJv%& ooKbiiBGGbii	#
 77 ggGFO>>%%'^^GM"??&&(ooGN#	

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 
 ,YK899 ZZa!Fzz&X%KLLhF^%D b		**T";;v+-x(V_[[({{8R0#KK6$[[8		
	  KC 
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sUYz 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                  W3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                  W3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   #DKK00OO_TYY5OI!$++.QQtyy7Q3QKyWW__T[[1
"499-"IIv':':6 ;=	"$//B))!#j''!BJ;AVHAbggY"7rwwKbggYb1EF$$j%>?;A6VHAbggY"7rwwKRWWIR		{!DE ''4VwwL	BII;a@A "" LL:c)n-=V!DELL9S->,?v!FGDIIe,779:""%%#++t #  % 
"4;;/"IIv':':6WW__TYY/
 	J. EG"$//ByyJ&WW\\*gg>
BGGOOJ7$GOBGG9BryykCD>>-"))2>>:*FG;AVHAbggY"7rwwK"));*CDh&WW\\*gg>
L	BII;a@A##J/f$RWWIR		{!<=' ", ~"l3~+>*?vFG%%i@ lKK)C$5#6lCD%Iww~~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~    llnG	K}D
45	K	*+
,-	M'+./
01	K	*+
,-	Igg&'
()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     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   )rx   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...)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   rx   r  r  r  r  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    s   F !\\))//~~KK
 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 77>>$d(;(;@GHHww}}V$$EfXNOO L)+6"  !N E	 9 9'k:F"!!'%I Iszz*9d#	*OD6*+ I&!GyQ7;#71#<ASWXAX$%l#ifE " G $& z  " s   6Q' 2Q? 'Q<?R)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,2DP
ES #ESPtx,:#VaH*u
 u u u u "u !%u !%u #u u u u  !u" #u$  $%u ur,   