
    QЦiG7                        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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   \RB                  " \"5      r#\RH                  " S5      r%Sr&SSS.r'\ " S S5      5       r(\    S8S\\(   S\\)   S\)S\)S\\)   S\\)   S\\*\)\)4      S\\+\)      S\,\+\*   \+\*   \\)   4   4S jj5       r- " S S\5      r. " S  S!\5      r/   S9S"S#S$\*S\\)   S\\*\)\)4      S\\)   SS4S% jjr0S&\*4S' jr1S(\*4S) jr2S*\*4S+ jr3S"S#S,\)SS4S- jr4S"S#S.\*S/\5S,\)SS4
S0 jr6S.\*S1\(S/\5S\+\)   4S2 jr7S3\+\*   S4\)S\/4S5 jr8S"S#S6\+\)   S/\5S\+\*   4S7 jr9g):z.Git LFS related type definitions and utilities    N)	dataclass)ceil)getsize)TYPE_CHECKINGBinaryIOIterableOptional	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\	4S j5       r
\S\4S	 j5       r\S
\4S j5       rSrg)
UploadInfo6   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         R/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/huggingface_hub/lfs.py	from_pathUploadInfo.from_pathI   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&   r,   r(   s      r)   
from_bytesUploadInfo.from_bytesQ   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&   r3   r   r(   r   s        r)   from_fileobjUploadInfo.from_fileobjV   sV    c"Q$'"||~Q$88r2    N)__name__
__module____qualname____firstlineno____doc__bytes__annotations__intclassmethodstrr*   r0   r   r9   __static_attributes__r;   r2   r)   r   r   6   sj     M
IM9S 9 9 Be B B 98 9 9r2   r   upload_infostoken	repo_typerepo_idrevisionendpointheaders	transfersreturnc                 ,   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 )a  
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
    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   )	operationrN   objects	hash_algonameref)rH   POSTrM   jsonrY   zMalformed response from servertransfererror)r   ENDPOINTREPO_TYPES_URL_PREFIXESr   hexr   r   LFS_HEADERSr   r   r   r_   get
isinstancelist
ValueErrorrE   _validate_batch_actions_validate_batch_error)rG   rH   rI   rJ   rK   rL   rM   rN   
url_prefix	batch_urlrS   payloadresp
batch_inforY   chosen_transferobjs                    r)   post_lfs_batch_infors   `   s   X $/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)r<   r=   r>   r?   rC   rB   rE   rF   r;   r2   r)   ru   ru      s    O
Ir2   ru   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.rW   partsr;   N)
r<   r=   r>   r?   r@   rE   rB   rh   ru   rF   r;   r2   r)   rz   rz      s    I	Hr2   rz   rX   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)a  
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
    [`HfHubHTTPError`]
        If the upload resulted in an error
actionsNzContent of file z. is already present upstream - skipping uploadrS   verifyheader
chunk_sizehref)rL   zTMalformed response from LFS batch endpoint: `chunk_size` should be an integer. Got 'z'.)rX   r   r   
upload_url)rX   r   r]   )rH   rM   rV   r^   z: Upload successful)rj   rf   loggerdebugpath_in_repo_validate_lfs_actionr   rC   ri   	TypeError_upload_multi_part_upload_single_partr   r   upload_infor   rd   r   r   )rX   r}   rH   rM   rL   r   upload_actionverify_actionr   r   r   
verify_urlverify_resps                r)   
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
"$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)rg   rf   rE   dictri   )r   s    r)   r   r   
  sQ     	:>>&)3//^^H%-JNN8<TVZ1[1[=>>r2   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   rW   r   z)lfs_batch_actions is improperly formattedr   rS   r   )rg   rf   rE   rC   ri   r   )r   r   r   s      r)   rj   rj     s    (,,U3S99jIZI^I^_eIfhk>l>lDEE%)))R8<<XFM%)))R8<<XFM ]+ ]+r2   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   rW   r   z'lfs_batch_error is improperly formattedra   messagecode)rg   rf   rE   rC   ri   r   )r   
error_infos     r)   rk   rk   "  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r2   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   )rX   r   r3   responses       r)   r   r   0  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   )rX   sorted_parts_urlsr   r]   )r_   rM   N)	_get_sorted_parts_urlsr   _upload_parts_iterativelyr   _get_completion_payloadr   rd   re   r   )rX   r   r   r   r   response_headerscompletion_ress          r)   r   r   D  sg    
 /fJ_J_lvw 1Z "$%57L7L7S7S7W7W7YZ	N 'r2   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>d  s    !A$r2   )keyz0Invalid server response to upload large LFS file)sorteditemsisdigitr/   rC   r   r   ri   )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   rW   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.$ )Nrx   rQ   zInvalid etag (`z`) returned for part r   )rw   rx   )rW   r|   )	enumeraterf   ri   append)r   rW   r|   part_numberr   rx   s         r)   r   r   m  sx     "E()9:zz&!<42:tf4I+XY/IZ[\\)Ao	
	  ; ''r2   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   rM   )	rX   r   r   rM   r3   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):r@   r#   redataclassesr   mathr   os.pathr   typingr   r   r   r	   r
   urllib.parser   huggingface_hubr   utilsr   r   r   r   r   r   
utils._lfsr   	utils.shar   r   _commit_apir   
get_loggerr<   r   compile	OID_REGEXLFS_MULTIPART_UPLOAD_COMMANDre   r   rE   r   rh   tuplers   ru   rz   r   r   rj   rk   r   rC   r   r   r   r   r;   r2   r)   <module>r      s   5 	 	 !   I I   %  % * /			H	%JJ()	5  -2 &9 &9 &9R  #"(,%)S:&SC=S S 	S
 smS smS d38n%S S	"S 4:tDz8C=01S Sl9 
   (,"DA#DADA C=DA d38n%	DA
 smDA 
DANT t 4 &#7 &S &T &(("6 ( (RU (cf (ko (.#4 #j #c #VZ[^V_ #$(d4j (s (GY (#8<S	OR	$Zr2   