
    5pj(              
          S r SSKrSSKrSSKJr  SSKJrJr  SSKrSSK	J
r
  SSKJr  SSKJrJrJrJrJr  SS	KJrJr  SS
KJr  SSKJr  / SQr\S   rS"S\S-  4S jjrS\S-  S\S\S-  SS4S jrS\S\S-  S\S-  SS4S jrS\
S\SS4S jr S\
S\S\S-  SS4S jr!S\
S\S\SS4S jr"S\S\S\4S jr#S\
S\S\S\$SS4
S jr%S\
S\S\\&-  S \SS4
S! jr'g)#a  Shared ``cp`` command to copy files between local paths, repositories and buckets.

This single command backs three identical CLI entry points: ``hf cp`` (top-level),
``hf repos cp`` and ``hf buckets cp``. It supports any source/destination combination
of local file, repo/bucket ``hf://`` URI, and ``-`` (stdin/stdout), with two exceptions:
- bucket-to-repo copies are not supported (server limitation), and
- local-to-local copies (use a regular ``cp`` for that).
    N)replace)	AnnotatedLiteral)HfApi)CLIError)HfUriSoftTemporaryDirectorydisable_progress_bars	is_hf_uriparse_hf_uri   )TokenOpt
get_hf_api)Argument)out)
z(hf cp hf://username/my-model/config.jsonz6hf cp hf://username/my-model/config.json ./config.jsonz8hf cp hf://datasets/username/my-dataset/data.csv ./data/z3hf cp hf://buckets/username/my-bucket/config.json -zBhf cp ./model.safetensors hf://username/my-model/model.safetensorsz9hf cp ./config.json hf://buckets/username/my-bucket/logs/z3hf cp - hf://buckets/username/my-bucket/config.jsonz;hf cp hf://username/source-model/ hf://username/dest-model/z]hf cp hf://datasets/username/my-dataset/processed/ hf://buckets/username/my-bucket/processed/zihf cp hf://buckets/username/my-bucket/logs/ hf://buckets/username/archive-bucket/  # copies contents only)reposbucketscontextc           
         ^    S
S[         [        [        SS94   S[         [        S-  [        SS94   S[        SS4U 4S	 jjjnU$ )zBuild the ``cp`` command function for a given alias.

The three entry points (`hf cp`, `hf repos cp`, `hf buckets cp`) share the exact same logic;
'context' only adds a guardrail on the remote endpoint type (see `_enforce_context`).
Nsrcz?Source: local file, hf:// URI (repo or bucket), or - for stdin.)helpdstzEDestination: local path, hf:// URI (repo or bucket), or - for stdout.tokenreturnc                 6   > [        TX5        [        XU5        g)a  Copy files between local paths, repositories, and buckets.

Handles uploads (local/stdin -> repo/bucket), downloads (repo/bucket -> local/stdout) and
remote-to-remote copies (repo/bucket -> repo/bucket). Bucket-to-repo and local-to-local
copies are not supported. For directories, use `hf upload`/`hf download` (repos) or
`hf buckets sync` (buckets). Remote-to-remote copies only work within the same storage
region (https://huggingface.co/docs/hub/storage-regions).
N)_enforce_context_run_cp)r   r   r   r   s      S/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/huggingface_hub/cli/_cp.pycpmake_cp.<locals>.cpC   s    & 	#+%     )NN)r   strr   r   )r   r   s   ` r   make_cpr#   <   st     ![\^
!
 $Jabd
! ! 
! !, Ir!   r   r   r   c                 
   U c  gUb  [        U5      (       a  UOUn[        U5      (       d  gU S:X  a%  [        U5      R                  (       a  [        S5      eU S:X  a&  [        U5      R                  (       d  [        S5      egg)a  Guardrail for the `hf repos cp` / `hf buckets cp` aliases.

These aliases are exact duplicates of `hf cp`, so a bare `hf repos cp` could otherwise touch a
bucket (and vice versa). We validate the type of the remote side: the destination for uploads and
remote-to-remote copies, or the source when downloading to a local path / stdout. The top-level
`hf cp` (i.e. 'context' is None) accepts any combination.
Nr   zW`hf repos cp` only works with repositories. Use `hf cp` or `hf buckets cp` for buckets.r   zW`hf buckets cp` only works with buckets. Use `hf cp` or `hf repos cp` for repositories.)r   r   	is_bucketr   )r   r   r   remotes       r   r   r   \   sx     _3ScFV'l62<<pqq)L$8$B$Bpqq %Cr!   r   c                    [        US9nU S:H  nUS:H  n[        U 5      nUS L=(       a    [        U5      nU(       a3  U(       a,  Uc   eUR                  X5        [        R                  " SXS9  g U(       d6  U(       d/  Uc  [
        R                  " S5      e[
        R                  " S5      eU(       a   U(       a  [        X05        g [        X0U5        g Uc   e[        X0XS9  g )N)r   -Copiedr   r   z?Missing destination. Provide a repo or bucket hf:// URI as DST.zVOne of SRC or DST must be a repo (hf://username/...) or bucket (hf://buckets/...) URI.)src_is_stdin)
r   r   
copy_filesr   resultclickBadParameter_download_file_to_stdout_download_file_to_local_upload_file_to_remote)r   r   r   apir+   dst_is_stdout	src_is_hf	dst_is_hfs           r   r   r   p   s    
5
!C#:L3JM#I42IcNI Ys 

8. Y;$$%fgg  d
 	

 $S.#. ??3SDr!   r3   c                    [        U5      n[        X!5      n[        5          [        5        n[        R
                  R                  XC5      n[        XU5        [        US5       nUR                  S5      =n(       aC  [        R                  R                  R                  U5        UR                  S5      =n(       a  MC  S S S 5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       N(= f! , (       d  f       g = f)Nrbi H)r   _source_filenamer
   r	   ospathjoin_download_singleopenreadsysstdoutbufferwrite)r3   r   urifilenametmp_dirtmp_pathfchunks           r   r0   r0      s    
s
C)H		 #%ww||G6HSx0h% vvj11e1JJ%%++E2  !vvj11e1 & & 
!	  &% &% 
!	 s;   C;8C*$AC C*C;
C'#C**
C8	4C;;
D	c                    [        U5      n[        X15      nUc  UnO[        R                  R	                  U5      (       d:  UR                  [        R                  5      (       d  UR                  S5      (       a   [        R                  R                  X$5      nOUn[        R                  R                  U5      nU(       a  [        R                  " USS9  [        XU5        [        R                  " SXS9  g )N/T)exist_ok
Downloadedr*   )r   r9   r:   r;   isdirendswithsepr<   dirnamemakedirsr=   r   r-   )r3   r   r   rD   rE   
local_path
parent_dirs          r   r1   r1      s    
s
C)H
{
	s		s||BFF33s||C7H7HWW\\#0

,J
J.Sz*JJ|5r!   rD   rS   c           	         UR                   (       a)  U R                  UR                  UR                  U4/SS9  g[        R
                  R                  U5      =(       d    Sn[        SUS9 nU R                  UR                  UR                  UR                  UR                  US9n[        R                  " XR5        SSS5        g! , (       d  f       g= f)z~Download a single file (repo or bucket) to ``local_path``.

Used by `_download_file_to_local` and `_download_file_to_stdout`.
T)raise_on_missing_files.z.tmp)prefixdir)repo_id	repo_typerE   revision	local_dirN)r%   download_bucket_filesidpath_in_repor:   r;   rQ   r	   hf_hub_downloadtyper\   r   )r3   rD   rS   rT   rF   downloaded_paths         r   r=   r=      s    
 }}!!#&&C,<,<j+I*Jcg!h
 WW__Z07C
#6zBg!11(())! 2 O JJ3 CBBs   -AC
Cc                     U R                   S:X  d  UR                  S5      (       a  [        R                  " S5      eU R                   R	                  SS5      S   $ )N rK   zSource path must include a file name, not just a repo/bucket or directory path. Use `hf download` or `hf buckets sync` to copy directories.r   )r`   rO   r.   r/   rsplit)rD   r   s     r   r9   r9      sW    
2c!2!2  K
 	
 ""3*2..r!   r+   c          	         [        U5      nU(       a  UR                  S:X  d  UR                  S5      (       a  [        R                  " S5      e[
        R                  R                  R                  5       n[        XXTR                  5        [        R                  " SSUR                  5       S9  g [        R                  R                  U5      (       a  [        R                  " S5      e[        R                  R!                  U5      (       d  [        R                  " SU 35      eUR                  nUS:X  a   [        R                  R#                  U5      nO>UR                  S5      (       a&  US-   [        R                  R#                  U5      -   nOUn[        XX5        [        R                  " SU[%        XGS	9R                  5       S9  g )
Nre   rK   zAStdin upload requires a full destination path including filename.Uploadedstdinr*   z]Source must be a file, not a directory. Use `hf upload` or `hf buckets sync` for directories.zSource file not found: )r`   )r   r`   rO   r.   r/   r@   rj   rB   r?   _upload_singler   r-   to_urir:   r;   rN   isfilebasenamer   )r3   r   r   r+   rD   datarX   remote_paths           r   r2   r2      sT   
s
Cr!S\\#%6%6$$%hiiyy$$&s'7'78

:7

=	ww}}S  k
 	
 77>>#  #:3%!@AAF|gg&&s+	c		slRWW%5%5c%::3S.JJzs(N(U(U(WXr!   sourcerp   c                     UR                   (       a  U R                  UR                  X#4/S9  gU R                  UUUR                  UR                  UR
                  S9  g)z4Upload a single file or bytes (to a repo or bucket).)add)path_or_fileobjr`   rZ   r[   r\   N)r%   batch_bucket_filesr_   upload_filerb   r\   )r3   rD   rq   rp   s       r   rk   rk      sR    
}}svvV,A+BC"$FFhh\\ 	 	
r!   )N)(__doc__r:   r@   dataclassesr   typingr   r   r.   huggingface_hubr   huggingface_hub.errorsr   huggingface_hub.utilsr   r	   r
   r   r   
_cli_utilsr   r   
_frameworkr   _outputr   CP_EXAMPLES	CpContextr#   r"   r   r   r0   r1   r=   r9   boolr2   bytesrk    r!   r   <module>r      s   
 
  %  ! + o o ,   $ &'	Y% @ri$. rS rsTz rd r(!E !E3: !EcDj !ET !EH
3% 
3c 
3d 
36 6S 6sTz 6d 6&4% 4e 4 4 4./% /c /c /Y YC Yc YD YUY Y<
 
E 
3; 
S 
UY 
r!   