Ë
    -Œ:j¯(  ã            
       ó–  — d Z ddlZddlZddlmZ ddlmZmZ ddlZddl	m
Z
 ddlmZ ddlmZmZmZmZmZ dd	lmZmZ dd
lmZ g d¢Zed   Zd!dedz  fd„Zdedz  dededz  ddfd„Zdededz  dedz  ddfd„Zde
deddfd„Zde
dededz  ddfd„Zde
dededdfd„Z dededefd„Z!de
dedede"ddf
d„Z#de
dedee$z  deddf
d „Z%y)"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)Ú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           	      ó¼   ‡ — 	 	 d
dt         t        t        j                  d¬«      f   dt         t        dz  t        j                  d¬«      f   dt        ddfˆ fd	„}|S )zõBuild 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                 ó:   •— t        ‰| |«       t        | ||«       y)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      €úY/var/www/html/tokenscope/api/venv/lib/python3.12/site-packages/huggingface_hub/cli/_cp.pyÚcpzmake_cp.<locals>.cpB   s   ø€ ô& 	˜ # sÔ+Ü��S˜%Õ ó    )NN)r   ÚstrÚtyperÚArgumentr   )r   r   s   ` r   Úmake_cpr#   ;   sw   ø€ ð Øñ!ÜÜÜ�N‰NÐ aÔbðdñ
ð!ô
 Ü�$‰JÜ�N‰NÐ gÔhðjñ
ð!ô ð!ð 
õ!ð, €Ir   r   r   r   c                 óÚ   — | €y|�t        |«      r|n|}t        |«      sy| dk(  r t        |«      j                  rt        d«      ‚| dk(  r!t        |«      j                  st        d«      ‚yy)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   [   ss   € ð €Øà�_¬°3¬‰S¸c€FÜ�VÔØØ�'Òœl¨6Ó2×<Ò<ÜÐpÓqÐqØ�)Ò¤L°Ó$8×$BÒ$BÜÐpÓqÐqð %CÐr   r   c                 ó’  — t        |¬«      }| dk(  }|dk(  }t        | «      }|d uxr t        |«      }|r1|r/|€J ‚|j                  | |«       t        j                  d| |¬«       y |s.|s,|€t        j                  d«      ‚t        j                  d«      ‚|r|rt        || «       y t        || |«       y |€J ‚t        || ||¬«       y )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   Úresultr!   Ú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   o   sÝ   € Ü
˜5Ô
!€Cà˜#‘:€LØ˜3‘J€MÜ˜#“€IØ˜4�Ò2¤I¨c£N€Iñ ‘YØˆÐˆØ�‰�s˜CÔ Ü�
‰
�8 ¨#Õ.Øñ ™YØˆ;Ü×$Ñ$Ð%fÓgÐgÜ× Ñ Ødó
ð 	
ñ
 ÙÜ$ S¨#Ô.ØÜ  S¨#Ô.Øð ˆ?Ðˆ?Ü˜3  S°|ÖDr   r2   c                 óê  — t        |«      }t        ||«      }t        «       5  t        «       5 }t        j
                  j                  ||«      }t        | ||«       t        |d«      5 }|j                  d«      x}r=t        j                  j                  j                  |«       |j                  d«      x}rŒ=d d d «       d d d «       d d d «       y # 1 sw Y   ŒxY w# 1 sw Y   ŒxY w# 1 sw Y   y xY w)NÚrbi Hè)r   Ú_source_filenamer
   r	   ÚosÚpathÚjoinÚ_download_singleÚopenÚreadÚsysÚstdoutÚbufferÚwrite)r2   r   ÚuriÚfilenameÚtmp_dirÚtmp_pathÚfÚchunks           r   r/   r/   “   sØ   € Ü
�sÓ
€CÜ  SÓ)€Hä	Ó	 ñ 3Ü#Ó%ð 	3¨Ü—w‘w—|‘| G¨XÓ6ˆHÜ˜S # xÔ0Ü�h Ó%ð 3¨Ø Ÿv™v jÓ1Ð1�eÐ1Ü—J‘J×%Ñ%×+Ñ+¨EÔ2ð  !Ÿv™v jÓ1Ð1�eÑ1÷3÷	3÷3ð 3÷3ð 3ú÷	3ð 	3ú÷3ð 3ús;   ¢C)­:CÁ'ACÂ8CÃ C)ÃCÃCÃC&	Ã"C)Ã)C2c                 óÚ  — t        |«      }t        ||«      }|€|}nrt        j                  j	                  |«      s0|j                  t        j                  «      s|j                  d«      r!t        j                  j                  ||«      }n|}t        j                  j                  |«      }|rt        j                  |d¬«       t        | ||«       t        j                  d||¬«       y )Nú/T)Úexist_okÚ
Downloadedr*   )r   r8   r9   r:   ÚisdirÚendswithÚsepr;   ÚdirnameÚmakedirsr<   r   r-   )r2   r   r   rC   rD   Ú
local_pathÚ
parent_dirs          r   r0   r0       s¤   € Ü
�sÓ
€CÜ  SÓ)€Hà
€{Ø‰
Ü	�‰�‰�sÔ	˜sŸ|™|¬B¯F©FÔ3°s·|±|ÀCÔ7HÜ—W‘W—\‘\ # xÓ0‰
àˆ
ä—‘—‘ Ó,€JÙÜ
�‰�J¨Õ.ä�S˜#˜zÔ*Ü‡J�Jˆ| ¨*Ö5r   rC   rR   c                 ó¦  — |j                   r,| j                  |j                  |j                  |fgd¬«       yt        j
                  j                  |«      xs d}t        d|¬«      5 }| j                  |j                  |j                  |j                  |j                  |¬«      }t	        j                  ||«       ddd«       y# 1 sw Y   yxY w)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_typerD   ÚrevisionÚ	local_dirN)r%   Údownload_bucket_filesÚidÚpath_in_repor9   r:   rP   r	   Úhf_hub_downloadÚtyper[   r   )r2   rC   rR   rS   rE   Údownloaded_paths         r   r<   r<   ³   s³   € ð
 ‡}‚}Ø×!Ñ! #§&¡&¨C×,<Ñ,<¸jÐ+IÐ*JÐcgÐ!Õhô
 —W‘W—_‘_ ZÓ0Ò7°Cˆ
Ü#¨6°zÔBð 	4ÀgØ!×1Ñ1ØŸ™ØŸ(™(Ø×)Ñ)ØŸ™Ø!ð 2ó ˆOô �J‰J�¨
Ô3÷	4÷ 	4ñ 	4ús   Á)ACÃCc                 óª   — | j                   dk(  s|j                  d«      rt        j                  d«      ‚| j                   j	                  dd«      d   S )NÚ rJ   z‹Source 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_   rN   r!   r.   Úrsplit)rC   r   s     r   r8   r8   Ê   sT   € Ø
×Ñ˜2Ò §¡¨cÔ!2Ü× Ñ ðKó
ð 	
ð ×Ñ×"Ñ" 3¨Ó*¨2Ñ.Ð.r   r+   c                ó~  — t        |«      }|rœ|j                  dk(  s|j                  d«      rt        j                  d«      ‚t
        j                  j                  j                  «       }t        | |||j                  «       t        j                  dd|j                  «       ¬«       y t        j                  j                  |«      rt        j                  d«      ‚t        j                  j!                  |«      st        j                  d|› �«      ‚|j                  }|dk(  r t        j                  j#                  |«      }n9|j                  d«      r&|dz   t        j                  j#                  |«      z   }n|}t        | |||«       t        j                  d|t%        ||¬	«      j                  «       ¬«       y )
Nrd   rJ   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_   rN   r!   r.   r?   ri   rA   r>   Ú_upload_singler   r-   Úto_urir9   r:   rM   ÚisfileÚbasenamer   )r2   r   r   r+   rC   ÚdatarW   Úremote_paths           r   r1   r1   Ó   sR  € Ü
�sÓ
€CáØ×Ñ˜rÒ! S§\¡\°#Ô%6Ü×$Ñ$Ð%hÓiÐiÜ�y‰y×Ñ×$Ñ$Ó&ˆÜ�s˜C  s×'7Ñ'7Ô8Ü�
‰
�: 7°·
±
³Õ=Øä	‡w�w‡}�}�SÔÜ× Ñ Økó
ð 	
ô �7‰7�>‰>˜#ÔÜ× Ñ Ð#:¸3¸%Ð!@ÓAÐAà×Ñ€FØ�‚|Ü—g‘g×&Ñ& sÓ+‰Ø	�‰�cÔ	Ø˜s‘l¤R§W¡W×%5Ñ%5°cÓ%:Ñ:‰àˆä�3˜˜S +Ô.Ü‡J�Jˆz˜s¬°À+Ô(N×(UÑ(UÓ(WÖXr   Úsourcero   c                 óÆ   — |j                   r!| j                  |j                  ||fg¬«       y| j                  |||j                  |j                  |j
                  ¬«       y)z4Upload a single file or bytes (to a repo or bucket).)Úadd)Úpath_or_fileobjr_   rY   rZ   r[   N)r%   Úbatch_bucket_filesr^   Úupload_filera   r[   )r2   rC   rp   ro   s       r   rj   rj   ñ   sT   € à
‡}‚}Ø×Ñ˜sŸv™v¨V°[Ð,AÐ+BÐÕCà�‰Ø"Ø$Ø—F‘FØ—h‘hØ—\‘\ð 	õ 	
r   )N)&Ú__doc__r9   r?   Údataclassesr   Útypingr   r   r!   Úhuggingface_hubr   Úhuggingface_hub.errorsr   Úhuggingface_hub.utilsr   r	   r
   r   r   Ú
_cli_utilsr   r   Ú_outputr   ÚCP_EXAMPLESÚ	CpContextr#   r    r   r   r/   r0   r<   r8   Úboolr1   Úbytesrj   © r   r   ú<module>rƒ      s‡  ðñó 
Û 
Ý ß %ã å !Ý +ß oÕ oç ,Ý ò€ð$ Ð&Ñ'€	ñ�Y Ñ%ó ð@r˜i¨$Ñ.ð r°Sð r¸sÀT¹zð rÈdó rð(!E�ð !E˜3 ™:ð !E¨c°D©jð !E¸Tó !EðH
3 %ð 
3¨cð 
3°dó 
3ð6 ð 6¨Sð 6°s¸T±zð 6Àdó 6ð&4˜%ð 4 eð 4¸ð 4Àó 4ð./˜%ð / cð /¨có /ðY ð Y¨Cð Y°cð YÈDð YÐUYó Yð<
˜ð 
 Eð 
°3¸±;ð 
ÈSð 
ÐUYô 
r   