
    Y j+7                        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
  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   \RB                  " \"5      r#\RH                  " S5      r%Sr&SSS.r'\ " S S5      5       r(\    S9S\\(   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/   S:S#S$S%\*S\)S-  S\*\)\)4   S-  S\)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/\*S0\5S-\)SS4
S1 jr6S/\*S2\(S0\5S\+\)   4S3 jr7S4\+\*   S5\)S\/4S6 jr8S#S$S7\+\)   S0\5S\+\*   4S8 jr9g);z.Git LFS related type definitions and utilities    N)Iterable)	dataclass)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\	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[        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   openpeekr   )clsr   r   filer   shas         d/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/huggingface_hub/lfs.py	from_pathUploadInfo.from_pathI   sT    t}$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seekioSEEK_SETr   tell)r$   r1   r   r&   r   s        r'   from_fileobjUploadInfo.from_fileobjV   sV    c"Q$'"||~Q$88r0    N)__name__
__module____qualname____firstlineno____doc__bytes__annotations__intclassmethodstrr(   r.   r   r8   __static_attributes__r:   r0   r'   r   r   6   sj     M
IM9S 9 9 Be B B 98 9 9r0   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   )	operationrM   objects	hash_algonameref)rG   POSTrL   jsonrX   zMalformed response from servertransfererror)r   ENDPOINTREPO_TYPES_URL_PREFIXESr   hexr   r
   LFS_HEADERSr   r   r   r^   get
isinstancelist
ValueErrorrD   _validate_batch_actions_validate_batch_error)rF   rG   rH   rI   rJ   rK   rL   rM   
url_prefix	batch_urlrR   payloadresp
batch_inforX   chosen_transferobjs                    r'   post_lfs_batch_inforr   `   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>   rB   rA   rD   rE   r:   r0   r'   rt   rt      s    O
Ir0   rt   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.rV   partsr:   N)
r;   r<   r=   r>   r?   rD   rA   rg   rt   rE   r:   r0   r'   ry   ry      s    I	Hr0   ry   rW   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 uploadrR   verifyheader
chunk_sizehref)rK   zTMalformed response from LFS batch endpoint: `chunk_size` should be an integer. Got 'z'.)rW   r   r   
upload_url)rW   r   r\   )rG   rL   rU   r]   z: Upload successful)ri   re   loggerdebugpath_in_repo_validate_lfs_actionr   rB   rh   	TypeError_upload_multi_part_upload_single_partr   r   upload_infor   rc   r   r   )rW   r|   rG   rL   rK   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)rf   re   rD   dictrh   )r   s    r'   r   r   
  sQ     	:>>&)3//^^H%-JNN8<TVZ1[1[=>>r0   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   rV   r   z)lfs_batch_actions is improperly formattedr~   rR   r   )rf   re   rD   rB   rh   r   )r   r   r   s      r'   ri   ri     s    (,,U3S99jIZI^I^_eIfhk>l>lDEE%)))R8<<XFM%)))R8<<XFM ]+ ]+r0   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   rV   r   z'lfs_batch_error is improperly formattedr`   messagecode)rf   re   rD   rB   rh   r   )r   
error_infos     r'   rj   rj   "  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r0   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   )rW   r   r1   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   )rW   sorted_parts_urlsr   r\   )r^   rL   N)	_get_sorted_parts_urlsr   _upload_parts_iterativelyr   _get_completion_payloadr   rc   rd   r   )rW   r   r   r   r   response_headerscompletion_ress          r'   r   r   D  sg    
 /fJ_J_lvw 1Z "$%57L7L7S7S7W7W7YZ	N 'r0   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$r0   )keyz0Invalid server response to upload large LFS file)sorteditemsisdigitr-   rB   r   r   rh   )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   rV   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.$ )Nrw   rP   zInvalid etag (`z`) returned for part r   )rv   rw   )rV   r{   )	enumeratere   rh   append)r   rV   r{   part_numberr   rw   s         r'   r   r   m  sx     "E()9:zz&!<42:tf4I+XY/IZ[\\)Ao	
	  ; ''r0   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   rL   )	rW   r   r   rL   r1   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?   r5   recollections.abcr   dataclassesr   mathr   os.pathr   typingr   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_COMMANDrd   r   rD   r   rg   tuplerr   rt   ry   r   r   ri   rj   r   rB   r   r   r   r   r:   r0   r'   <module>r      s   5 	 	 $ !   5 5   %  % * /			H	%JJ()	5  -2 &9 &9 &9R   %)"&S:&S:S S 	S
 DjS DjS #s(^d"S Cy4S 4:tDz3:-.S Sl9 
  %)DA#DADA :DA #s(^d"	DA
 Dj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r0   