
    5pj0                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
  SSKJrJrJr  SSKJr  S	S
KJr  S	SKJr  \R*                  " \5      rS\\\" SS94   SS4S jrS\4S jrS\S-  4S jrSS jrg)a  
Implementation of a custom transfer agent for the transfer type "multipart" for
git-lfs.

Inspired by:
github.com/cbartz/git-lfs-swift-transfer-agent/blob/master/git_lfs_swift_transfer.py

Spec is: github.com/git-lfs/git-lfs/blob/master/docs/custom-transfers.md


To launch debugger while developing:

``` [lfs "customtransfer.multipart"]
path = /path/to/huggingface_hub/.venv/bin/python args = -m debugpy --listen 5678
--wait-for-client
/path/to/huggingface_hub/src/huggingface_hub/commands/huggingface_cli.py
lfs-multipart-upload ```    N)	Annotated)CLIError)LFS_MULTIPART_UPLOAD_COMMAND   )get_sessionhf_raise_for_statuslogging)SliceFileObj   )Argument)outpathz/Local path to repository you want to configure.)helpreturnc                 h   [         R                  R                  U 5      n[         R                  R                  U5      (       d  [	        S5      e[
        R                  " SR                  5       SUS9  [
        R                  " S[         3R                  5       SUS9  [        R                  " SUS9  g)	z
Configure your repository to enable upload of files > 5GB.

This command sets up git-lfs to use the custom multipart transfer agent
which enables efficient uploading of large files in chunks.
z)This does not look like a valid git repo.z/git config lfs.customtransfer.multipart.path hfT)checkcwdz-git config lfs.customtransfer.multipart.args z Local repo set up for largefiles)r   N)osr   abspathisdirr   
subprocessrunsplitr   r   result)r   
local_paths     S/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/huggingface_hub/cli/lfs.pylfs_enable_largefilesr   %   s     &J77==$$BCCNN9??A
 NN
78T7UV\\^
 JJ1
C    msgc                     [         R                  " U 5      S-   n[        R                  R	                  U5        [        R                  R                  5         g)z-Write out the message in Line delimited JSON.
N)jsondumpssysstdoutwriteflush)r   msg_strs     r   	write_msgr)   C   s6    jjo$GJJWJJr   c                  T   [         R                  " [        R                  R	                  5       R                  5       5      n SU R                  S5      U R                  S5      4;   a  gU R                  S5      S;  a+  [        R                  S5        [        R                  " S5        U $ )z$Read Line delimited JSON from stdin.	terminatetypeeventN)downloaduploadzReceived unexpected messager   )
r"   loadsr$   stdinreadlinestripgetloggercriticalexit)r   s    r   read_msgr8   J   sv    
**SYY'')//1
2Cswwv(899
www5556Jr   c            
      @   [         R                  " [        R                  R	                  5       R                  5       5      n U R                  S5      S:X  a  U R                  S5      S:X  d&  [        SSSS.05        [        R                  " S	5        [        0 5         [        5       nUc  [        R                  " S5        US   nUS   nUS   S   nUS   S   n[        UR                  S5      5      n[        UR                  5       5      n[        SUS	SS.5        / n[        US5       n	[        U5       H  u  p[!        U	X-  US9 n[#        5       R%                  XS9n['        U5        UR)                  UR*                  R                  S5      U
S	-   S.5        [        SUU
S	-   U-  US.5        S
S
S
5        M     S
S
S
5        [#        5       R-                  UUUS.S9n['        U5        [        SUS.5        GM`  ! , (       d  f       M  = f! , (       d  f       NW= f)zInternal git-lfs custom transfer agent for multipart uploads.

This function implements the custom transfer protocol for git-lfs multipart uploads.
Handles chunked uploads of large files to Hugging Face Hub.
r-   init	operationr/   error    zWrong lfs init operation)codemessager   Nr   oidr   actionhrefheader
chunk_sizeprogress)r-   r@   
bytesSoFarbytesSinceLastrb)	seek_from
read_limit)dataetag)rL   
partNumber)r@   parts)r"   complete)r-   r@   )r"   r0   r$   r1   r2   r3   r4   r)   r7   r8   intpoplistvaluesopen	enumerater
   r   putr   appendheaderspost)init_msgr   r@   filepathcompletion_urlrC   rD   presigned_urlsrN   fileipresigned_urlrK   rs                 r   lfs_multipart_uploadrb   Y   s    zz#)),,.4467HLL!V+[0IX0U7R4NOPQ bM j;
 HHQK%jv;Xv.Xx(L12
$($9
 	#"#		
 (D!T$-n$= !n) #))-)CA'*LL$%IIMM&$9*+a% %/#&+,q5J*>.8	  %> "4 M  
 	AJs34A >  "!s%   +H	A)G=2H=
HH
H)r   N)__doc__r"   r   r   r$   typingr   huggingface_hub.errorsr   huggingface_hub.lfsr   utilsr   r   r	   
utils._lfsr
   
_frameworkr   _outputr   
get_logger__name__r5   strr   dictr)   r8   rb    r   r   <module>rp      s   $  	  
  + < = = %    
		H	%D
B	
	D 
D<4 $+ V5r   