
    HTh	A                     L   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  SSKJrJrJrJrJr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 J!r!J"r"  S
SK#J$r$  S
SK%J&r&J'r'  S
SK(J)r)  \(       a  S
SK*J+r+  \ RX                  " \-5      r.\R^                  " S5      r0Sr1SSS.r2\ " S S5      5       r3\"   S:S\\3   S\\4   S\4S\4S\\4   S\\4   S\\\4\44      S\\\5   \\5   4   4S jj5       r6 " S S \5      r7 " S! S"\5      r8   S:S#S$S%\S\\4   S\\\4\44      S\\4   SS4S& jjr9S'\54S( jr:S)\54S* jr;S+\54S, jr<S#S$S-\4SS4S. jr=S#S$S/\S0\>S-\4SS4
S1 jr?S/\S2\3S0\>S\\4   4S3 jr@S4\\   S5\4S\84S6 jrAS#S$S7\\4   S0\>S\\   4S8 jrBS#S$S7\\4   S0\>S\\   4S9 jrCg);z.Git LFS related type definitions and utilities    N)	dataclass)ceil)getsize)Path)TYPE_CHECKINGBinaryIODictIterableListOptionalTuple	TypedDict)unquote)	constants   )build_hf_headersfix_hf_endpoint_in_urlget_sessionhf_raise_for_statushttp_backoffloggingtqdmvalidate_hf_hub_args)SliceFileObj)sha256sha_fileobj)is_tqdm_disabled)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\	4S j5       r
\S\4S	 j5       r\S
\4S j5       rSrg)
UploadInfo<   a<  
Dataclass holding required information to determine whether a blob
should be uploaded to the hub using the LFS protocol or the regular protocol

Args:
    sha256 (`bytes`):
        SHA256 hash of the blob
    size (`int`):
        Size in bytes of the blob
    sample (`bytes`):
        First 512 bytes of the blob
r   sizesamplepathc                     [        U5      n[        R                  " US5       nUR                  S5      S S n[	        U5      nS S S 5        U " UWWS9$ ! , (       d  f       N= f)Nrb   r#   r   r$   )r   ioopenpeekr   )clsr%   r#   filer$   shas         K/var/www/auris/envauris/lib/python3.13/site-packages/huggingface_hub/lfs.py	from_pathUploadInfo.from_pathO   sX    t}WWT4 DYYs^DS)Fd#C ! S88 ! s    A
A!datac                 \    [        U5      R                  5       nU " [        U5      US S US9$ )Nr(   )r#   r$   r   )r   digestlen)r-   r3   r/   s      r0   
from_bytesUploadInfo.from_bytesW   s-    Tl!!#D	$t*SAA    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)   )readseekr*   SEEK_SETr   tell)r-   r:   r$   r/   r#   s        r0   from_fileobjUploadInfo.from_fileobj\   sV    c"Q$'"||~Q$88r9    N)__name__
__module____qualname____firstlineno____doc__bytes__annotations__intclassmethodstrr1   r7   r   r@   __static_attributes__rB   r9   r0   r!   r!   <   sj     M
IM9S 9 9 Be B B 98 9 9r9   r!   upload_infostoken	repo_typerepo_idrevisionendpointheadersreturnc                    Ub  UO[         R                  nSnU[         R                  ;   a  [         R                  U   nU SU U S3nS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[        5       R                  XU
S9n[        U5        UR                  5       nUR                  SS5      n[        U[        5      (       d  [!        S5      e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4$ s  sn	f s  snf s  snf )ay  
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`
    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.
    headers (`dict`, *optional*):
        Additional headers to include in the request

Returns:
    `LfsBatchInfo`: 2-tuple:
        - First element is the list of upload instructions from the server
        - Second element is an list of errors, if any

Raises:
    [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
        If an argument is invalid or the server response is malformed.
    [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
        If the server returned an error.
N /z.git/info/lfs/objects/batchuploadbasic	multipartoidr#   r   )	operation	transfersobjects	hash_algonameref)rO   rT   jsonr`   zMalformed response from servererror)r   ENDPOINTREPO_TYPES_URL_PREFIXESr   hexr#   r   LFS_HEADERSr   r   postr   re   get
isinstancelist
ValueError_validate_batch_actions_validate_batch_error)rN   rO   rP   rQ   rR   rS   rT   
url_prefix	batch_urlrY   payloadresp
batch_infor`   objs                  r0   post_lfs_batch_inforx   f   s   P $/xY5G5GHJI55566yA
*Aj\'2MNI{+ '

 ' }}((* '
 G  '("34


' =bG
 =iwGDJnnY-Ggt$$9:: 29O#G3<N	%	 	%O/6Iw'S.	#	s	#wI 3
4 	PIs   1E$ 
E).E)
E.E.c                   *    \ rS rSr% \\S'   \\S'   Srg)PayloadPartT   
partNumberetagrB   N)rC   rD   rE   rF   rJ   rI   rL   rM   rB   r9   r0   rz   rz      s    O
Ir9   rz   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.r]   partsrB   N)
rC   rD   rE   rF   rG   rL   rI   r   rz   rM   rB   r9   r0   r   r      s    I	Hr9   r   r^   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b~  [        U5        [        US	   U5      n[        5       R                  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)a7  
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.
    headers (`dict`, *optional*):
        Headers to include in the request, including authentication and user agent headers.

Raises:
    [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
        If `lfs_batch_action` is improperly formatted
    [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
        If the upload resulted in an error
actionsNzContent of file z. is already present upstream - skipping uploadrY   verifyheader
chunk_sizehref)rS   zTMalformed response from LFS batch endpoint: `chunk_size` should be an integer. Got 'z'.)r^   r   r   
upload_url)r^   r   )rO   rT   r\   rd   z: Upload successful)rp   rl   loggerdebugpath_in_repo_validate_lfs_actionr   rJ   ro   	TypeError_upload_multi_part_upload_single_partr   rk   r   upload_infor   ri   r#   r   )r^   r   rO   rT   rS   r   upload_actionverify_actionr   r   r   
verify_urlverify_resps                r0   
lfs_uploadr      s   8 ,-""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
!m(($5B"..5599;YEZEZE_E_` ) 

 	K(
LLI**++>?@% I& 	fgqfrrtu 	s   -E0 0 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)rm   rl   rL   dictro   )r   s    r0   r   r     sQ     	:>>&)3//^^H%-JNN8<TVZ1[1[=>>r9   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   r]   r#   z)lfs_batch_actions is improperly formattedr   rY   r   )rm   rl   rL   rJ   ro   r   )r   r   r   s      r0   rp   rp     s    (,,U3S99jIZI^I^_eIfhk>l>lDEE%)))R8<<XFM%)))R8<<XFM ]+ ]+r9   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   r]   r#   z'lfs_batch_error is improperly formattedrf   messagecode)rm   rl   rL   rJ   ro   r   )r   
error_infos     r0   rq   rq     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r9   r   c                     U R                  SS9 n[        SXSS9n[        U5        SSS5        g! , (       d  f       g= f)ax  
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.

Returns: `requests.Response`

Raises:
 [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)
    If the upload resulted in an error.
T	with_tqdmPUTi  i  i  i  r3   retry_on_status_codesN)as_filer   r   )r^   r   r:   responses       r0   r   r   -  s:      
		T		*gzWklH% 
+	*	*s   0
>r   r   c                    [        XR                  US9n[        R                  n[        R                  (       aV  [	        U R
                  [        5      (       d7  [	        U R
                  [        5      (       d  [        R                  " S5        SnU(       a
  [        XUS9O	[        XUS9n[        5       R                  U[        X`R                  R                  R!                  5       5      ["        S9n[%        U5        g)z8
Uploads file using HF multipart LFS transfer protocol.
)r   r   r   zlhf_transfer is enabled but does not support uploading from bytes or BinaryIO, falling back to regular uploadF)r^   sorted_parts_urlsr   )re   rT   N)_get_sorted_parts_urlsr   r   HF_HUB_ENABLE_HF_TRANSFERrm   path_or_fileobjrL   r   warningswarn_upload_parts_hf_transfer_upload_parts_iterativelyr   rk   _get_completion_payloadr   ri   rj   r   )r^   r   r   r   r   use_hf_transferresponse_headerscompletion_ress           r0   r   r   C  s    
 /fJ_J_lvw  99O++944c::944d;;	
    	"Igqr&lvw  !]''$%57L7L7S7S7W7W7YZ ( N
 'r9   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   rB   )ts    r0   <lambda>(_get_sorted_parts_urls.<locals>.<lambda>o  s    !A$r9   )keyz0Invalid server response to upload large LFS file)sorteditemsisdigitr6   rJ   r   r#   ro   )r   r   r   part_numr   _sorted_part_upload_urls	num_partss           r0   r   r   f  s     $ -3LLN,:(H##% 0*-h-!*; 0Xr"J/,:
 


MA 	
  
 +,ID))J677KLL""
s   B+
B+
	B+
&B1r   r]   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}   rW   zInvalid etag (`z`) returned for part r   )r|   r}   )r]   r   )	enumeraterl   ro   append)r   r]   r   part_numberr   r}   s         r0   r   r   x  sx     "E()9:zz&!<42:tf4I+XY/IZ[\\)Ao	
	  ; ''r9   r   c           
      8   / nU R                  SS9 n[        U5       HL  u  pV[        UX%-  US9 n[        SXgSS9n[	        U5        UR                  UR                  5        S S S 5        MN     S S S 5        U$ ! , (       d  f       Mi  = f! , (       d  f       U$ = f)NTr   )	seek_from
read_limitr   r   r   )r   r   r   r   r   r   rT   )	r^   r   r   rT   r:   part_idxpart_upload_urlfileobj_slicepart_upload_ress	            r0   r   r     s     G			T		*g)23D)E%H$/% ".?Vj# $O4667  *F 
+ N  
+	* Ns"   B
2A8"B
8
BB


Bc                     SSK Jn  S[        R
                  " U5      R                  ;   nU(       d  [        R                  " S5        U R                  R                  nU R                  n[        U5      S:  a  SUSS   3n[        S	S
USU[        [        R!                  5       5      SS9 n U" SU R"                  UUSSSS.U(       a  SUR$                  0O0 D6nU(       d  UR%                  U5        UsS S S 5        $ ! [         a    [        S5      ef = f! [&         a  n	[)        S5      U	eS n	A	ff = f! , (       d  f       g = f)Nr   )multipart_uploadzFast uploading using 'hf_transfer' is enabled (HF_HUB_ENABLE_HF_TRANSFER=1) but 'hf_transfer' package is not available in your environment. Try `pip install hf_transfer`.callbackzYou are using an outdated version of `hf_transfer`. Consider upgrading to latest version to enable progress bars using `pip install -U hf_transfer`.(   u   (…)iBTzhuggingface_hub.lfs_upload)unit
unit_scaletotalinitialdescdisablerb            )	file_path
parts_urlsr   	max_filesparallel_failuresmax_retriesz~An error occurred while uploading using `hf_transfer`. Consider disabling HF_HUB_ENABLE_HF_TRANSFER for better error handling.rB   )hf_transferr   ImportErrorro   inspect	signature
parametersr   r   r   r#   r   r6   r   r   r   getEffectiveLevelr   update	ExceptionRuntimeError)
r^   r   r   r   supports_callbackr   r   progressoutputes
             r0   r   r     sc   
0 #g&7&78H&I&T&TT c	
 !!&&E!!D
4y2~tCDzl#	 !9!9!;<)
 
	% #33,%"% 5FJ02F !OOE"5
 
#  
Q
 	

H  	* 	'
 
s;   C> +D5-.DD5>D
D2!D--D22D55
E)NNN)DrG   r   r*   rer   dataclassesr   mathr   os.pathr   pathlibr   typingr   r   r	   r
   r   r   r   r   urllib.parser   huggingface_hubr   utilsr   r   r   r   r   r   r   r   
utils._lfsr   	utils.shar   r   
utils.tqdmr   _commit_apir   
get_loggerrC   r   compile	OID_REGEXLFS_MULTIPART_UPLOAD_COMMANDrj   r!   rL   r   rx   rz   r   r   r   rp   rq   r   rJ   r   r   r   r   r   rB   r9   r0   <module>r     s   5  	 	  !    \ \ \   %	 	 	 % * ( /			H	%JJ()	5  -2 &9 &9 &9R  #"(,K:&KC=K K 	K
 smK smK d38n%K 4:tDz!"K K\9 
   (,"CA#CACA C=CA d38n%	CA
 smCA 
CALT t 4 &#7 &S &T &, ("6  (  (RU  (cf  (ko  (F#4 #j #c #VZ[^V_ #$(d4j (s (GY (#8<S	OR	$Z(1#18<S	1OR1	$Z1r9   