+
    &j                     h   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! ]'       d   ^R
I"H#t# ]PH                  ! ]%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       t.] ! R R4      4       t/] ! R R4      4       t0R R  lt1R! R" lt2] ! R# R$4      4       t3] ! R% R&4      4       t4 ! R' R(4      t5R) R* lt6R+ R, lt7R- R. lt8R/ R0 lt9R1 R2 lt:R3R/R4 R5 llt;RSR7 R8 llt<R9 R: lt=R; R< lt>R= R> lt?RTR? R@ llt@RA RB ltARURCR6RDR6RER6RFR6RGR6RHRRIRRJRRKRRLRRMR6RNR6ROR6RPR/RQ RR llltBR# )VzzShared 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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   &,p/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/huggingface_hub/_buckets.py__init__BucketInfo.__init__U   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__r2   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    )r1   r2   s   "r(   r3   _BucketAddFile.__annotate__h   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destinationr0   bytesospathgetmtimetimemtimer&   s   &r(   __post_init___BucketAddFile.__post_init__h   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-   rL   rO   Nxet_hashr   rU   rJ   )r.   r   rP   r0   )r1   r2   s   "r(   r3   rH   ^   sf     $J   
 Dj.  **  "  *0 r+   rJ   rU   )r6   r7   r8   r9   r   rZ   r   rU   rJ   rW   r;   r<   r=   r>   s   @r(   r@   r@   ^   s@     
 !.HT*DE"E$%0L	
 	
  r+   r@   c                   t   a  ] tR t^tt 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# )	_BucketCopyFileNrA   FrC   c                   < V ^8  d   QhRR/# rF   r    )r1   r2   s   "r(   r3   _BucketCopyFile.__annotate__~   s     - -t -r+   c                    \         P                  ! V P                  4      ^ ,          V n        \	        \
        P
                  ! 4       R,          4      V n        R# )    r   N)rM   rN   rO   rJ   r0   rT   rU   rV   s   &r(   rW   _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-   rO   rZ   source_repo_typesource_repo_idNr   rU   rJ   )r.   r0   )r1   r2   s   "r(   r3   r_   t   se       M  	 
   **  "  *0 r+   r[   )r6   r7   r8   r9   r   r   rU   rJ   rW   r;   r<   r=   r>   s   @r(   r]   r]   t   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-   rR   )r.   )r1   r2   s   "r(   r3   _BucketDeleteFile.__annotate__   s     
I r+   r    N)r6   r7   r8   r9   r;   r<   r=   r>   s   @r(   rg   rg      s      r+   rg   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)r0   r   )r1   r2   s   "r(   r3   BucketFileMetadata.__annotate__   s      I   r+   r    N)r6   r7   r8   r9   r:   r;   r<   r=   r>   s   @r(   rl   rl      s     	  r+   rl   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>.
 FrC   c                   < V ^8  d   QhRR/# rF   r    )r1   r2   s   "r(   r3   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# )rr   /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(   rW   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-   ry   rw   r   r   r   r.   r   )r1   r2   s   "r(   r3   rt      sE     $ 
H% & ' ( &) * &+ , 
"- r+   )r   rw   r   r   N)r6   r7   r8   r9   r:   rw   r   r   r   r   rW   r;   r<   r=   r>   s   @r(   rq   rq      s@     " H&I&IE"C 1  r+   rq   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# )typerR   r   xetHashrU   N
uploadedAt)r!   r   rR   r   rZ   r   rU   uploaded_at)r&   r'   rU   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   rR   r   rZ   NrU   r   )r
   r.   r0   r   )r1   r2   s   "r(   r3   BucketFile.__annotate__   s\      &/  I  I  M  d?  D  r+   )rU   rR   r   r   r   rZ   Nr5   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   rR   r   Nr   )r!   r   rR   rK   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   rR   Nr   )r
   r.   r   )r1   r2   s   "r(   r3   BucketFolder.__annotate__   s4      +
  I  D  r+   )rR   r   r   Nr5   r>   s   @r(   r   r      s     
  r+   r   c                0    V ^8  d   QhR\         R\        /# r-   rR   rG   r   )r1   s   "r(   r3   r3      s     C CC CE Cr+   c                   V P                  \        P                  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 both `hf://buckets/namespace/name(/path/in/repo)` and plain `namespace/name(/path/in/repo)`.
zInvalid bucket path: z*. Must be a bucket URI (hf://buckets/...).rv   zInvalid bucket path: 'z)'. Expected format: namespace/bucket_name:r-   NNbucket)r   r   r   )
r|   r   HF_PROTOCOLr   	is_bucketr   r   r}   joinr   )rR   r   partsr   prefixs   &    r(   r~   r~      s    
 y,,--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.   r/   )r1   s   "r(   r3   r3   	  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   )rR   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.Nrr   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-   actionrR   Nr   reasonlocal_mtimeremote_mtimebucket_file)uploaddownloaddeleteskip)r
   r.   r0   r   )r1   r2   s   "r(   r3   SyncOperation.__annotate__  sv      :;;	 
 I  *    t"  *#  d") r+   r    )r6   r7   r8   r9   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-   rG   )dictr.   r0   )r1   r2   s   "r(   r3   SyncPlan.__annotate__/  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>0       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   1  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   2  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   3  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   4  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.summary/  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-   rL   dest	timestampr   )r.   listr   )r1   r2   s   "r(   r3   r   &  s;      K	 
 I  N  ]#A r+   r    N)r6   r7   r8   r9   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# )
FilterMatcheriC  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)r1   r2   s   "r(   r3   FilterMatcher.__annotate__F  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__F  s4     !1 6 6B 0 6 6B(..Br+   c                &   < V ^8  d   QhRS[ RS[/# r   r   )r1   r2   s   "r(   r3   r   W  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&   rR   signpatterns   &&  r(   matchesFilterMatcher.matchesW  s     "..MDt--s{" /
 ,,Gt-- - ,,Gt-- -
     r+   )r   r   r   )NNN)	r6   r7   r8   r9   r:   r)   r   r<   r=   r>   s   @r(   r   r   C  s     >/ /" r+   r   c                h    V ^8  d   QhR\         R\        \        \         \         3,          ,          /# )r-   filter_filerG   )r.   r   r   )r1   s   "r(   r3   r3   t  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   t  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-   rR   rG   N)r.   r   r0   float)r1   s   "r(   r3   r3     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   )rQ   statOSErrorS_ISDIRst_modest_sizest_mtime)rR   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_pathrG   )r.   r   r   r0   r   )r1   s   "r(   r3   r3     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: Nrv   )rQ   rR   abspathisdirr   walkr   r  relpathrz   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   rG   )r.   r   r   r0   r   r	   )r1   s   "r(   r3   r3     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   	recursiverv   r   )
list_bucket_treerK   r   rR   r|   r}   rsplitrU   r   r   )r  r   r   itemrR   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  rG   )r   r.   )r1   s   "r(   r3   r3     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-   rR   r   source_sizesource_mtime	dest_size
dest_mtimesource_newer_labeldest_newer_labelignore_sizesignore_timesignore_existingr   NrG   r   )r.   r
   r0   r   r/   r	   r   )r1   s   "r(   r3   r3     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   rR   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)rR   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_syncr8    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-   rL   r   r  r   r   r,  r+  existingr-  filter_matcherNstatusrG   )r.   r/   r   r	   r   )r1   s   "r(   r3   r3   %  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.rL   r   r   NzSource must be a directory: zScanning local directory (z files)rv   rr   zScanning remote bucket (zBucket 'z' not found, treating as empty.zComparing files (z paths)r   znew file (--existing))r   rR   r   r   r   r   znew filezlocal newerzremote newer)rR   r   r%  r&  r'  r(  r)  r*  r+  r,  r-  r   znot in source (--delete))r   rR   r   r   r   r   )r   rR   r   r   r   r   )rR   r   r%  r&  r'  r(  r)  r*  r+  r,  r-  r   )'r   r   r   r   r   nowr   r!  r"  rQ   rR   r  r~   r   r   r  r  r   r%   r}   donebucket_infor#   	Exceptionr  r   loggerdebugsetkeyssortedgetr   r   r   r#  r8  r   r  )%rL   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_pathsrR   
local_inforemote_info
local_sizer   remote_sizer   bucket_file_mapr   
local_filer  s%   &&&&&&&&&&                           r(   _compute_sync_planrW  %  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-   rK  rG   Nr   )r1   s   "r(   r3   r3   !  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   headerrL   r   r   r   
	operationr   rR   r   Nr   r   r   )rL   r   r   r   writejsondumpsr   r   rR   r   r   r   r   )rK  r   r\  r   op_dicts   &&   r(   _write_planrc  !  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-   rK  	plan_filerG   N)r   r.   )r1   s   "r(   r3   r3   >  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   rc  )rK  re  r   s   && r(   
_save_planrh  >  s(    	i		D 
			s   +<	c                0    V ^8  d   QhR\         R\        /# )r-   re  rG   )r.   r   )r1   s   "r(   r3   r3   D  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 linerL   r   r   r>  r   r^  r   rR   r   r   rr   r   r   )r   rR   r   r   r   r   )
r   	readlinesr   r`  loadsrH  r   r   r   r   )re  r   linesr\  rK  r   rb  s   &      r(   
_load_planrn  D  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-   rK  r  r   verboser<  NrG   )r   r/   r	   )r1   s   "r(   r3   r3   o  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   rv   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   rL   r   rQ   rR   r  r~   r   r   r   r   r   printr   r   r}   r@  
capitalizebatch_bucket_filesmakedirsdirnamer   download_bucket_filesexistsremovermdirr   )rK  r  rp  r<  rI  rJ  r  r   r   r   	add_filesdelete_pathsr   rV  remote_pathr   download_filesdelete_files	file_pathparents   &&&&                r(   _execute_planr  o  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/# rY  rZ  )r1   s   "r(   r3   r3     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   ru  rL   r   )rK  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_fromrK  applydry_runrp  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-   rL   Nr   r  r   r   r,  r+  r:  r-  r  r  r  rK  r  r  rp  r  r  rG   )r.   r/   r   r   )r1   s   "r(   r3   r3     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...)rp  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   )
rL   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   rn  r   r  ru  r   r  r   r   rQ   rR   r{  r  r   r   rW  rc  sysstdoutrh  r   )rL   r   r  r   r,  r+  r:  r-  r  r  r  rK  r  r  rp  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 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   ?P0 ;Q 0QQ)FFFFFNN)FN)NN)Cr:   r   r`  rM   rQ   r   r  rT   collections.abcr   dataclassesr   r   r   r   pathlibr   typingr   r	   r
   rr   r   r   errorsr   utilsr   r   r   r   r   r   r   r  r   
get_loggerr6   rC  BUCKET_PREFIXr0  r   r@   r]   rg   rl   rq   r   r   r~   r   r   r   r   r   r  r  r  r#  r8  rW  rc  rh  rn  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*n
 n n n n "n !%n !%n #n n n n  !n" #n$  $%n nr+   