
    9i6                        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Jr  S	SKJr  S	SKJrJr  \
(       a  S	SK J!r!  \RD                  " \#5      r$\RJ                  " 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      r0   S9S"S#S$\+S\\*   S\\+\*\*4      S\\*   SS4S% jjr1S&\+4S' jr2S(\+4S) jr3S*\+4S+ jr4S"S#S,\*SS4S- jr5S"S#S.\+S/\6S,\*SS4
S0 jr7S.\+S1\)S/\6S\,\*   4S2 jr8S3\,\+   S4\*S\04S5 jr9S"S#S6\,\*   S/\6S\,\+   4S7 jr:g):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get_session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)
UploadInfo7   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         S/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/huggingface_hub/lfs.py	from_pathUploadInfo.from_pathJ   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_bytesR   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'   r4   r   r)   r   s        r*   from_fileobjUploadInfo.from_fileobjW   sV    c"Q$'"||~Q$88r3    N)__name__
__module____qualname____firstlineno____doc__bytes__annotations__intclassmethodstrr+   r1   r   r:   __static_attributes__r<   r3   r*   r   r   7   sj     M
IM9S 9 9 Be B B 98 9 9r3   r   upload_infostoken	repo_typerepo_idrevisionendpointheaders	transfersreturnc                 F   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[        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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   )	operationrO   objects	hash_algonameref)rI   rN   jsonrZ   zMalformed response from servertransfererror)r   ENDPOINTREPO_TYPES_URL_PREFIXESr   hexr   r   LFS_HEADERSr   r   postr   r_   get
isinstancelist
ValueErrorrF   _validate_batch_actions_validate_batch_error)rH   rI   rJ   rK   rL   rM   rN   rO   
url_prefix	batch_urlrT   payloadresp
batch_inforZ   chosen_transferobjs                    r*   post_lfs_batch_infort   a   s   X $/xY5G5GHJI55566yA
*Aj\'2MNI"+"7Yg{=S '

 ' }}((* '
 G  '("34


' =bG
 =iwGD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2
F Fc                   *    \ rS rSr% \\S'   \\S'   Srg)PayloadPartT   
partNumberetagr<   N)r=   r>   r?   r@   rD   rC   rF   rG   r<   r3   r*   rv   rv      s    O
Ir3   rv   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.rX   partsr<   N)
r=   r>   r?   r@   rA   rF   rC   ri   rv   rG   r<   r3   r*   r{   r{      s    I	Hr3   r{   rY   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)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 uploadrT   verifyheader
chunk_sizehref)rM   zTMalformed response from LFS batch endpoint: `chunk_size` should be an integer. Got 'z'.)rY   r   r   
upload_url)rY   r   )rI   rN   rW   r^   z: Upload successful)rk   rg   loggerdebugpath_in_repo_validate_lfs_actionr   rD   rj   	TypeError_upload_multi_part_upload_single_partr   rf   r   upload_infor   rd   r   r   )rY   r~   rI   rN   rM   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
!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)rh   rg   rF   dictrj   )r   s    r*   r   r   
  sQ     	:>>&)3//^^H%-JNN8<TVZ1[1[=>>r3   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   rX   r   z)lfs_batch_actions is improperly formattedr   rT   r   )rh   rg   rF   rD   rj   r   )r   r   r   s      r*   rk   rk     s    (,,U3S99jIZI^I^_eIfhk>l>lDEE%)))R8<<XFM%)))R8<<XFM ]+ ]+r3   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   rX   r   z'lfs_batch_error is improperly formattedra   messagecode)rh   rg   rF   rD   rj   r   )r   
error_infos     r*   rl   rl   "  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r3   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   )rY   r   r4   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[        5       R	                  U[        XPR                  R                  R                  5       5      [        S9n[        U5        g)z8
Uploads file using HF multipart LFS transfer protocol.
)r   r   r   )rY   sorted_parts_urlsr   )r_   rN   N)
_get_sorted_parts_urlsr   _upload_parts_iterativelyr   rf   _get_completion_payloadr   rd   re   r   )rY   r   r   r   r   response_headerscompletion_ress          r*   r   r   D  sq    
 /fJ_J_lvw 1Z
 !]''$%57L7L7S7S7W7W7YZ ( N
 'r3   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>b  s    !A$r3   )keyz0Invalid server response to upload large LFS file)sorteditemsisdigitr0   rD   r   r   rj   )r   r   r   part_numr   _sorted_part_upload_urls	num_partss           r*   r   r   Y  s     $ -3LLN,:(H##% 0*-h-!*; 0Xr"J/,:
 


MA 	
  
 +,ID))J677KLL""
s   B+
B+
	B+
&B1r   rX   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.$ )Nry   rR   zInvalid etag (`z`) returned for part r   )rx   ry   )rX   r}   )	enumeraterg   rj   append)r   rX   r}   part_numberr   ry   s         r*   r   r   k  sx     "E()9:zz&!<42:tf4I+XY/IZ[\\)Ao	
	  ; ''r3   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   rN   )	rY   r   r   rN   r4   part_idxpart_upload_urlfileobj_slicepart_upload_ress	            r*   r   r   z  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);rA   r$   redataclassesr   mathr   os.pathr   typingr   r   r   r	   r
   urllib.parser   huggingface_hubr   utilsr   r   r   r   r   r   r   
utils._lfsr   	utils.shar   r   _commit_apir   
get_loggerr=   r   compile	OID_REGEXLFS_MULTIPART_UPLOAD_COMMANDre   r   rF   r   ri   tuplert   rv   r{   r   r   rk   rl   r   rD   r   r   r   r   r<   r3   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 
   (,"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 (*#4 #j #c #VZ[^V_ #$(d4j (s (GY (#8<S	OR	$Zr3   