
    Cj@                        S 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JrJrJrJrJr  S	SKJr  S	SKJrJr  \
(       a  S	SKJr  \R>                  " \ 5      r!\RD                  " S5      r#Sr$SSS.r% " S S5      r&\    S8S\\&   S\'S-  S\'S\'S\'S-  S\'S-  S\(\'\'4   S-  S\)\'   S-  S\*\)\(   \)\(   \'S-  4   4S jj5       r+ " S S\5      r, " S  S!\5      r-   S9S"S#S$\(S\'S-  S\(\'\'4   S-  S\'S-  SS4S% jjr.S&\(4S' jr/S(\(4S) jr0S*\(4S+ jr1S"S#S,\'SS4S- jr2S"S#S.\(S/\3S,\'SS4
S0 jr4S.\(S1\&S/\3S\)\'   4S2 jr5S3\)\(   S4\'S\-4S5 jr6S"S#S6\)\'   S/\3S\)\(   4S7 jr7g):z.Git LFS related type definitions and utilities    N)Iterable)ceil)getsize)TYPE_CHECKINGBinaryIO	TypedDict)unquote)	constants   )build_hf_headersfix_hf_endpoint_in_urlhf_raise_for_statushttp_backoffloggingvalidate_hf_hub_args)SliceFileObj)sha256sha_fileobj)CommitOperationAddz^[0-9a-f]{40}$zlfs-multipart-uploadzapplication/vnd.git-lfs+json)AcceptzContent-Typec            
           \ rS rSrSr  SS\S\S\S-  S\S-  4S jjr\	S	\4S
 j5       r
\
R                  S\S	S4S j5       r
\	S	\4S j5       rS	\4S jr\S\4S j5       r\S\4S j5       r\S\4S j5       rSrg)
UploadInfo5   av  
Data structure holding required information to determine whether a blob
should be uploaded to the hub using the LFS protocol or the regular protocol.

The SHA256 of the blob is computed lazily: creating an `UploadInfo` from a local path only reads
the first 512 bytes of the file. The full file is read (and hashed) only if `sha256` is accessed
before it has been set. When a file is uploaded through the Xet protocol, the SHA256 is computed
during upload (single read pass) and set afterwards.

Args:
    size (`int`):
        Size in bytes of the blob
    sample (`bytes`):
        First 512 bytes of the blob
    sha256 (`bytes`, *optional*):
        SHA256 hash of the blob, if already known. Otherwise computed lazily from `source_path`.
    source_path (`str`, *optional*):
        Path to the local file the blob comes from. Required to lazily compute `sha256` if not provided.
Nsizesampler   source_pathc                 V    Uc  Uc  [        S5      eXl        X l        X0l        X@l        g )Nz2Either `sha256` or `source_path` must be provided.)
ValueErrorr   r   _sha256_source_path)selfr   r   r   r   s        e/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/huggingface_hub/lfs.py__init__UploadInfo.__init__J   s/     >k1QRR	'    returnc                     U R                   cJ  U R                  c   e[        U R                  S5       n[        U5      U l         SSS5        U R                   $ U R                   $ ! , (       d  f       U R                   $ = f)zZSHA256 of the blob. If not set yet, reads the whole file from `source_path` to compute it.Nrb)r   r    openr   )r!   files     r"   r   UploadInfo.sha256X   si     <<$$000d''.$*40 /||t|| /.||s   A$$
A=valuec                     Xl         g )Nr   )r!   r,   s     r"   r   r+   a   s    r%   c                     U R                   SL$ )zVWhether the SHA256 is already known (accessing `sha256` will not trigger a file read).Nr.   )r!   s    r"   	is_hashedUploadInfo.is_hashede   s     ||4''r%   c                 z    U R                   b  U R                   R                  5       OSnSU R                   SU S3$ )Nz<not computed>zUploadInfo(size=z	, sha256=))r   hexr   )r!   shas     r"   __repr__UploadInfo.__repr__j   s9    $(LL$<dll BR!$))IcU!<<r%   pathc                     [        U5      n[        US5       nUR                  S5      S S nS S S 5        U " UWUS9$ ! , (       d  f       N= f)Nr(      )r   r   r   )r   r)   peek)clsr8   r   r*   r   s        r"   	from_pathUploadInfo.from_pathn   sH    t}$YYs^DS)F V>> s	   =
Adatac                 \    [        U5      R                  5       nU " [        U5      US S US9$ )Nr:   )r   r   r   )r   digestlen)r<   r?   r5   s      r"   
from_bytesUploadInfo.from_bytesu   s-    Tl!!#D	$t*SAAr%   fileobjc                     UR                  S5      nUR                  S[        R                  5        [	        U5      nUR                  5       nUR                  S[        R                  5        U " XCUS9$ )Nr:   r   )r   r   r   )readseekioSEEK_SETr   tell)r<   rE   r   r5   r   s        r"   from_fileobjUploadInfo.from_fileobjz   sV    c"Q$'"||~Q$88r%   )r   r    r   r   )NN)__name__
__module____qualname____firstlineno____doc__intbytesstrr#   propertyr   setterboolr0   r6   classmethodr=   rC   r   rL   __static_attributes__ r%   r"   r   r   5   s    0  $"&(( ( 	(
 4Z(    ]]E d   (4 ( (=# = ?S ? ? Be B B 98 9 9r%   r   upload_infostoken	repo_typerepo_idrevisionendpointheaders	transfersr&   c                 ,   Ub  UO[         R                  nSnU[         R                  ;   a  [         R                  U   nU SU U S3n	SUb  UOSS/U  V
s/ s H*  n
U
R                  R	                  5       U
R
                  S.PM,     sn
S	S
.nUb  S[        U5      0US'   0 [        E[        US9EU=(       d    0 En[        SXUS9n[        U5        UR                  5       nUR                  SS5      n[        U[        5      (       d  [        S5      eUR                  S5      n[        U[         5      (       a  UOSnU Vs/ s H  nSU;  d  M  [#        U5      PM     snU Vs/ s H  nSU;   d  M  [%        U5      PM     snU4$ s  sn
f s  snf s  snf )aa  
Requests the LFS batch endpoint to retrieve upload instructions

Learn more: https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md

Args:
    upload_infos (`Iterable` of `UploadInfo`):
        `UploadInfo` for the files that are being uploaded, typically obtained
        from `CommitOperationAdd.upload_info`
    token (`str` or `None`):
        An authentication token (see https://huggingface.co/settings/token).
        Pass `None` to fall back to the local cached token (or no token if unauthenticated).
    repo_type (`str`):
        Type of the repo to upload to: `"model"`, `"dataset"` or `"space"`.
    repo_id (`str`):
        A namespace (user or an organization) and a repo name separated
        by a `/`.
    revision (`str`, *optional*):
        The git revision to upload to.
    endpoint (`str`, *optional*):
        The Hub endpoint to send the request to. Defaults to the value of `HF_ENDPOINT`.
    headers (`dict`, *optional*):
        Additional headers to include in the request
    transfers (`list`, *optional*):
        List of transfer methods to use. Defaults to ["basic", "multipart"].

Returns:
    `LfsBatchInfo`: 3-tuple:
        - First element is the list of upload instructions from the server
        - Second element is a list of errors, if any
        - Third element is the chosen transfer adapter if provided by the server (e.g. "basic", "multipart", "xet")

Raises:
    [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
        If an argument is invalid or the server response is malformed.
    [`HfHubHTTPError`]
        If the server returned an error.
N /z.git/info/lfs/objects/batchuploadbasic	multipartoidr   r   )	operationrc   objects	hash_algonameref)r]   POSTrb   jsonrm   zMalformed response from servertransfererror)r
   ENDPOINTREPO_TYPES_URL_PREFIXESr   r4   r   r	   LFS_HEADERSr   r   r   rs   get
isinstancelistr   rU   _validate_batch_actions_validate_batch_error)r\   r]   r^   r_   r`   ra   rb   rc   
url_prefix	batch_urlrg   payloadresp
batch_inform   chosen_transferobjs                    r"   post_lfs_batch_infor      s   b $/xY5G5GHJI55566yA
*Aj\'2MNI"+"7Yg{=S '

 ' }}((* '
 G  '("34


' =bG
 	IDJnnY-Ggt$$9:: nnZ0O)3OS)I)IotO 29O#G3<N	%	 	%O/6Iw'S.	#	s	#wI 9
: 	PIs   1F
FF%
F3Fc                   *    \ rS rSr% \\S'   \\S'   Srg)PayloadPartT   
partNumberetagr[   N)rN   rO   rP   rQ   rS   __annotations__rU   rZ   r[   r%   r"   r   r      s    O
Ir%   r   c                   4    \ rS rSr% Sr\\S'   \\   \S'   Sr	g)CompletionPayloadT   z?Payload that will be sent to the Hub when uploading multi-part.rk   partsr[   N)
rN   rO   rP   rQ   rR   rU   r   r{   r   rZ   r[   r%   r"   r   r      s    I	Hr%   r   rl   r   lfs_batch_actionc           	         [        U5        UR                  S5      nUc$  [        R                  SU R                   S35        gUS   S   n[        U5        US   R                  S5      nUb  [        U5        UR                  S0 5      nUR                  S5      n	[        US	   US
9n
U	b   [        U	5      n	[        XXS9  O	[        X
S9  Ubq  [        U5        [        US	   U5      n[        SU[        X#S9U R                  R                  R!                  5       U R                  R"                  S.S9n[%        U5        [        R                  U R                   S35        g! [        [        4 a    [        SU	 S35      ef = f)ae  
Handles uploading a given object to the Hub with the LFS protocol.

Can be a No-op if the content of the file is already present on the hub large file storage.

Args:
    operation (`CommitOperationAdd`):
        The add operation triggering this upload.
    lfs_batch_action (`dict`):
        Upload instructions from the LFS batch endpoint for this object. See [`~utils.lfs.post_lfs_batch_info`] for
        more details.
    token (`str`, *optional*):
        An authentication token (see https://huggingface.co/settings/token). Used to call the
        optional LFS verify step at the end of the upload. If `None`, falls back to the local
        cached token.
    headers (`dict`, *optional*):
        Headers to include in the request, including authentication and user agent headers.
    endpoint (`str`, *optional*):
        The Hub endpoint to send the request to. Defaults to the value of `HF_ENDPOINT`.

Raises:
    [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
        If `lfs_batch_action` is improperly formatted
    [`HfHubHTTPError`]
        If the upload resulted in an error
actionsNzContent of file z. is already present upstream - skipping uploadrg   verifyheader
chunk_sizehref)ra   zTMalformed response from LFS batch endpoint: `chunk_size` should be an integer. Got 'z'.)rl   r   r   
upload_url)rl   r   rq   )r]   rb   rj   rr   z: Upload successful)r|   ry   loggerdebugpath_in_repo_validate_lfs_actionr   rS   r   	TypeError_upload_multi_part_upload_single_partr   r   upload_infor   r4   r   r   )rl   r   r]   rb   ra   r   upload_actionverify_actionr   r   r   
verify_urlverify_resps                r"   
lfs_uploadr      s   D ,-""9-G'	(>(>'??mno %Y/9M'$Y/33H=M ]+ x,FL)J'f(=QJ	ZJ
 	Y*liG  ]++M&,A8L
"$5B"..5599;YEZEZE_E_`	
 	K(
LLI**++>?@' I& 	fgqfrrtu 	s   -E# # F
lfs_actionc                     [        U R                  S5      [        5      (       a6  U R                  S5      b/  [        U R                  S5      [        5      (       d  [	        S5      eU $ ).validates response from the LFS batch endpointr   r   z"lfs_action is improperly formatted)rz   ry   rU   dictr   )r   s    r"   r   r   9  sQ     	:>>&)3//^^H%-JNN8<TVZ1[1[=>>r%   lfs_batch_actionsc                 h   [        U R                  S5      [        5      (       a$  [        U R                  S5      [        5      (       d  [	        S5      eU R                  S0 5      R                  S5      nU R                  S0 5      R                  S5      nUb  [        U5        Ub  [        U5        U $ )r   rk   r   z)lfs_batch_actions is improperly formattedr   rg   r   )rz   ry   rU   rS   r   r   )r   r   r   s      r"   r|   r|   C  s    (,,U3S99jIZI^I^_eIfhk>l>lDEE%)))R8<<XFM%)))R8<<XFM ]+ ]+r%   lfs_batch_errorc                    [        U R                  S5      [        5      (       a$  [        U R                  S5      [        5      (       d  [	        S5      eU R                  S5      n[        U[
        5      (       aH  [        UR                  S5      [        5      (       a$  [        UR                  S5      [        5      (       d  [	        S5      eU $ )r   rk   r   z'lfs_batch_error is improperly formattedru   messagecode)rz   ry   rU   rS   r   r   )r   
error_infos     r"   r}   r}   Q  s    **51377JGZGZ[aGbdg<h<hBCC $$W-J:t$$z~~i0#66z~~f-s33BCCr%   r   c                     U R                  SS9 n[        SXS9n[        U5        SSS5        g! , (       d  f       g= f)a#  
Uploads `fileobj` as a single PUT HTTP request (basic LFS transfer protocol)

Args:
    upload_url (`str`):
        The URL to PUT the file to.
    fileobj:
        The file-like object holding the data to upload.

Raises:
    [`HfHubHTTPError`]
        If the upload resulted in an error.
T	with_tqdmPUTr?   N)as_filer   r   )rl   r   rE   responses       r"   r   r   _  s7     
		T		*gz@H% 
+	*	*s   /
=r   r   c           	          [        XR                  US9n[        XUS9n[        SU[	        XPR                  R
                  R                  5       5      [        S9n[        U5        g)z8
Uploads file using HF multipart LFS transfer protocol.
)r   r   r   )rl   sorted_parts_urlsr   rq   )rs   rb   N)	_get_sorted_parts_urlsr   _upload_parts_iterativelyr   _get_completion_payloadr   r4   rx   r   )rl   r   r   r   r   response_headerscompletion_ress          r"   r   r   s  sg    
 /fJ_J_lvw 1Z "$%57L7L7S7S7W7W7YZ	N 'r%   r   c           
      n   [        U R                  5        VVs/ s H;  u  p4UR                  5       (       d  M  [        U5      S:  d  M-  [	        US5      U4PM=     snnS S9 VVs/ s H  u  pTUPM	     nnn[        U5      nU[        UR                  U-  5      :w  a  [        S5      eU$ s  snnf s  snnf )Nr   
   c                     U S   $ )Nr   r[   )ts    r"   <lambda>(_get_sorted_parts_urls.<locals>.<lambda>  s    !A$r%   )keyz0Invalid server response to upload large LFS file)sorteditemsisdigitrB   rS   r   r   r   )r   r   r   part_numr   _sorted_part_upload_urls	num_partss           r"   r   r     s     $ -3LLN,:(H##% 0*-h-!*; 0Xr"J/,:
 


MA 	
  
 +,ID))J677KLL""
s   B+
B+
	B+
&B1r   rk   c                     / n[        U 5       HJ  u  p4UR                  S5      nUb  US:X  a  [        SU SUS-    35      eUR                  US-   US.5        ML     XS.$ )Nr   re   zInvalid etag (`z`) returned for part r   )r   r   )rk   r   )	enumeratery   r   append)r   rk   r   part_numberr   r   s         r"   r   r     sx     "E()9:zz&!<42:tf4I+XY/IZ[\\)Ao	
	  ; ''r%   r   c           	      6   / nU R                  SS9 n[        U5       HK  u  pV[        UX%-  US9 n[        SXgS9n[	        U5        UR                  UR                  5        S S S 5        MM     S S S 5        U$ ! , (       d  f       Mh  = f! , (       d  f       U$ = f)NTr   )	seek_from
read_limitr   r   )r   r   r   r   r   r   rb   )	rl   r   r   rb   rE   part_idxpart_upload_urlfileobj_slicepart_upload_ress	            r"   r   r     s     G			T		*g)23D)E%H$/% ".uo"Z#O4667  *F 
+ N  
+	* Ns"   B	1A7!B	7
BB		
B)NNNN)NNN)8rR   rI   recollections.abcr   mathr   os.pathr   typingr   r   r   urllib.parser	   huggingface_hubr
   utilsr   r   r   r   r   r   
utils._lfsr   	utils.shar   r   _commit_apir   
get_loggerrN   r   compile	OID_REGEXLFS_MULTIPART_UPLOAD_COMMANDrx   r   rU   r   r{   tupler   r   r   r   r   r|   r}   r   rS   r   r   r   r   r[   r%   r"   <module>r      s   5 	 	 $   5 5   %  % * /			H	%JJ()	5  -2L9 L9^   %)"&X:&X:X X 	X
 DjX DjX #s(^d"X Cy4X 4:tDz3:-.X Xv9 
  %)JA#JAJA :JA #s(^d"	JA
 DjJA 
JAZT t 4 &#7 &S &T &(("6 ( (RU (cf (ko (.#4 #j #c #VZ[^V_ #$(d4j (s (GY (#8<S	OR	$Zr%   