+
    ~j                       a  RW th0 t R t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
HtHtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIt^ RIHt ^R	IHt ^R
IHtH t H!t!H"t"H#t#H$t$H%t%H&t& ^RIH't' ^RI(H)t) ^RI*H+t+ ]'PX                  ! ]-4      t.]! RR7       ! R R4      4       t/]P`                  ! R4      t1]P`                  ! R4      t2R R lt3Rt4Rt5Rt6]P`                  ! R]Pn                  R7      t8]P`                  ! R]Pn                  R7      t9]P`                  ! R4      t:]P`                  ! R4      t;0 RXmt<R R lt=R  R! lt>R" R# lt?R$ R% lt@R& R' ltAR( R) ltBR* R+ ltC]. ]P                  3,          tE]. ]P                  3,          tG]P                  ! 4       tI]BsJ] ^ k ]CsK] ^k RsL] ^k R, R- ltMR. R/ ltNR0 R1 ltOR2 R3 ltPR4 R5 ltQ]P                  ! ]Q4       ]S! ]R64      '       d   ]P                  ! ]QR77       ]P                  ]P                  3tW] ^k RYtX] ^k R8^R9^R:^R;]WR<]XR=R>/R? R@ lltYR8^R9^R:^R;]WR<]X/RA RB lltZ]R8^R9^R:^R;]WR<]X/RC RD ll4       t[RER>/RF RG llt\RH RI lt]RZRJ RK llt^]_! 4       t`RL RM lta]! RN]#RO7      tbRP RQ ltcRR RS ltd]P`                  ! RT]P                  4      tfRU RV ltgR# )[z>Contains utilities to handle HTTP requests in huggingface_hub.N)Callable	GeneratorMapping)contextmanager)	dataclass)quote)AnyTypeVar)urlparse)OfflineModeIsEnabled)	constants)BadRequestErrorBucketNotFoundErrorDisabledRepoErrorGatedRepoErrorHfHubHTTPErrorRemoteEntryNotFoundErrorRepositoryNotFoundErrorRevisionNotFoundError)logging)SliceFileObj)HTTP_METHOD_TT)frozenc                   8   a  ] tR t^6t o RtRtRtV 3R ltRtV t	R# )RateLimitInfoa  
Parsed rate limit information from HTTP response headers.

Attributes:
    resource_type (`str`): The type of resource being rate limited.
    remaining (`int`): The number of requests remaining in the current window.
    reset_in_seconds (`int`): The number of seconds until the rate limit resets.
    limit (`int`, *optional*): The maximum number of requests allowed in the current window.
    window_seconds (`int`, *optional*): The number of seconds in the current window.

Nc                r   < V ^8  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[R,          ;R&   S[R,          ;R&   # )   resource_type	remainingreset_in_secondsNlimitwindow_secondsstrint)format__classdict__s   "p/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/huggingface_hub/utils/_http.py__annotate__RateLimitInfo.__annotate__6   sM        N   ! " :# $ $J%%      )
__name__
__module____qualname____firstlineno____doc__r    r!   __annotate_func____static_attributes____classdictcell__)r&   s   @r'   r   r   6   s     
 E!%N%  r*   r   zL\"(?P<resource_type>\w+)\"\s*;\s*r\s*=\s*(?P<r>\d+)\s*;\s*t\s*=\s*(?P<t>\d+)z'q\s*=\s*(?P<q>\d+).*?w\s*=\s*(?P<w>\d+)c                `    V ^8  d   QhR\         \        \        3,          R\        R,          /# )r   headersreturnN)r   r#   r   )r%   s   "r'   r(   r(   R   s(     8 8WS#X%6 8=4;O 8r*   c                6   RpRpV  F5  pVP                  4       pVR8X  d   W,          pK$  VR8X  g   K-  W,          pK7  	  V'       g   R# \        P                  V4      pV'       g   R# VP                  R4      p\	        VP                  R4      4      p\	        VP                  R4      4      pRp	Rp
V'       dR   \
        P                  V4      pV'       d5   \	        VP                  R4      4      p	\	        VP                  R4      4      p
\        VVVV	V
R	7      # )
a  Parse rate limit information from HTTP response headers.

Follows IETF draft: https://www.ietf.org/archive/id/draft-ietf-httpapi-ratelimit-headers-09.html
Only a subset is implemented.

Example:
```python
>>> from huggingface_hub.utils import parse_ratelimit_headers
>>> headers = {
...     "ratelimit": '"api";r=0;t=55',
...     "ratelimit-policy": '"fixed window";"api";q=500;w=300',
... }
>>> info = parse_ratelimit_headers(headers)
>>> info.remaining
0
>>> info.reset_in_seconds
55
```
N	ratelimitzratelimit-policyr   rtqw)r   r   r   r    r!   )lower_RATELIMIT_REGEXsearchgroupr$   _RATELIMIT_POLICY_REGEXr   )r5   r8   policykey	lower_keymatchr   r   r   r    r!   policy_matchs   &           r'   parse_ratelimit_headersrG   R   s    * !IFIIK	#I,,\F  ##I.EKK0MEKK$%I5;;s+,E!%N.55f=**3/0E !3!3C!89N#)% r*   zx-request-idzX-Amzn-Trace-Idzx-amz-cf-ida  
        # staging or production endpoint
        ^https://[^/]+
        (
            # on /api/repo_type/repo_id
            /api/(models|datasets|spaces)/(.+)
            |
            # or /repo_id/resolve/revision/...
            /(.+)/resolve/(.+)
        )
    )flagszz
        # staging or production endpoint
        ^https?://[^/]+
        # on /api/buckets/...
        /api/buckets/
    zA^https?://[^/]+/api/(models|datasets|spaces)/([^/]+)(?:/([^/]+))?z)^https?://[^/]+/api/buckets/([^/]+/[^/]+)c                n    V ^8  d   QhR\         R\        \         R,          \         R,          3,          /# r   urlr6   N)r#   tuple)r%   s   "r'   r(   r(      s,      3 5tS4Z1G+H r*   c                "   \         P                  V 4      pV'       g   R# \        P                  P	                  VP                  ^4      4      pVP                  ^4      VP                  ^4      rCV'       d   V\        9  d   V RV 2pW%3# TpW%3# )a  Extract (repo_type, repo_id) from an API URL.

Returns canonical repo_type values: "model", "dataset", "space" (or None).

Examples:
    >>> _parse_repo_info_from_url("https://huggingface.co/api/models/user/repo")
    ("model", "user/repo")
    >>> _parse_repo_info_from_url("https://huggingface.co/api/datasets/user/repo/resolve/main/data.csv")
    ("dataset", "user/repo")
    >>> _parse_repo_info_from_url("https://huggingface.co/api/models/bert-base-cased/resolve/main/config.json")
    ("model", "bert-base-cased")
/NN)_REPO_ID_FROM_URL_REGEXr?   r   REPO_TYPES_MAPPINGgetr@   _REPO_URL_SUBPATHS)rK   rE   	repo_typefirstsecondrepo_ids   &     r'   _parse_repo_info_from_urlrX      s     $**3/E,,00Q@IKKNEKKN6& 22G1VH%  r*   c                >    V ^8  d   QhR\         R\         R,          /# rJ   r#   )r%   s   "r'   r(   r(      s     - -3 -3: -r*   c                b    \         P                  V 4      pV'       d   VP                  ^4      # R# )z9Extract bucket_id (namespace/name) from a bucket API URL.N)_BUCKET_ID_FROM_URL_REGEXr?   r@   )rK   rE   s   & r'   _parse_bucket_id_from_urlr]      s'    %,,S1E"5;;q>,,r*   c                <    V ^8  d   QhR\         P                  RR/# r   requestr6   NhttpxRequest)r%   s   "r'   r(   r(      s      5== T r*   c           	     |   \         P                  ! 4       '       d   \        RV P                   R24      h\        V P
                  9  dW   V P
                  P                  \        4      ;'       g    \        \        P                  ! 4       4      V P
                  \        &   V P
                  P                  \        4      p\        P                  RVV P                  V P                  V P
                  P                  R4      RJ4       \         P                  '       d    \        P                  R\        V 4      4       V# )z
Event hook that will be used to make HTTP requests to the Hugging Face Hub.

What it does:
- Block requests if offline mode is enabled
- Add a request ID to the request headers
- Log the request if debug mode is enabled
zCannot reach za: offline mode is enabled. To disable it, please unset the `HF_HUB_OFFLINE` environment variable.z%Request %s: %s %s (authenticated: %s)authorizationNzSend: %s)r   is_offline_moder   rK   X_AMZN_TRACE_IDr5   rR   X_REQUEST_IDr#   uuiduuid4loggerdebugmethodHF_DEBUG_curlify)r`   
request_ids   & r'   hf_request_event_hookrq      s       """GKK=  )J  K
 	

 goo-+2??+>+>|+L+a+aPSTXT^T^T`Pa($$_5J LL/O,D8 Z'!23r*   c                <    V ^8  d   QhR\         P                  RR/# r_   ra   )r%   s   "r'   r(   r(      s     * *u}} * *r*   c                    "   \        V 4      # 5i)z+
Async version of `hf_request_event_hook`.
)rq   )r`   s   &r'   async_hf_request_event_hookrt      s      !))s   c                <    V ^8  d   QhR\         P                  RR/# r   responser6   Nrb   Response)r%   s   "r'   r(   r(      s     ' ' 'D 'r*   c                    "   V P                   R 8  dT   RV P                  9   dA    \        V P                  R,          4      pTR8  d   T P	                  4       G Rj  xL
  R# R# R# R#   \         d     R# i ; i L5i)  zContent-lengthNi@B )status_coder5   r$   
ValueErroraread)rw   lengths   & r'   async_hf_response_event_hookr      s     s" x///X--.>?@ 	!nn&&& " 0 #   's4   #A=A) A=A;A=)A84A=7A88A=c                8    V ^8  d   QhR\         P                  /# r   r6   rb   Client)r%   s   "r'   r(   r(     s       r*   c                 B    \         P                  ! R\        ./RRR7      # )zI
Factory function to create a `httpx.Client` with the default transport.
r`   TNevent_hooksfollow_redirectstimeout)rb   r   rq   r+   r*   r'   default_client_factoryr     s'     <<!6 78 r*   c                8    V ^8  d   QhR\         P                  /# r   rb   AsyncClient)r%   s   "r'   r(   r(     s      e&7&7 r*   c                 P    \         P                  ! R\        .R\        ./RRR7      # )zN
Factory function to create a `httpx.AsyncClient` with the default transport.
r`   rw   TNr   )rb   r   rt   r   r+   r*   r'   default_async_client_factoryr     s1     !< =zLhKij r*   c                (    V ^8  d   QhR\         RR/# )r   client_factoryr6   N)CLIENT_FACTORY_T)r%   s   "r'   r(   r(   +  s     0 0'7 0D 0r*   c                t    \         ;_uu_ 4        \        4        V sRRR4       R#   + '       g   i     R# ; i)a  
Set the HTTP client factory to be used by `huggingface_hub`.

The client factory is a method that returns a `httpx.Client` object. On the first call to [`get_session`] the client factory
will be used to create a new `httpx.Client` object that will be shared between all calls made by `huggingface_hub`.

This can be useful if you are running your scripts in a specific environment requiring custom configuration (e.g. custom proxy or certifications).

Use [`get_session`] to get a correctly configured `httpx.Client`.
N)_CLIENT_LOCKclose_session_GLOBAL_CLIENT_FACTORY)r   s   &r'   set_client_factoryr   +  s      
!/ 
s   &7	c                (    V ^8  d   QhR\         RR/# )r   async_client_factoryr6   N)ASYNC_CLIENT_FACTORY_T)r%   s   "r'   r(   r(   <  s     8 83I 8d 8r*   c                
    V s R# )a  
Set the HTTP async client factory to be used by `huggingface_hub`.

The async client factory is a method that returns a `httpx.AsyncClient` object.
This can be useful if you are running your scripts in a specific environment requiring custom configuration (e.g. custom proxy or certifications).
Use [`get_async_client`] to get a correctly configured `httpx.AsyncClient`.

<Tip warning={true}>

Contrary to the `httpx.Client` that is shared between all calls made by `huggingface_hub`, the `httpx.AsyncClient` is not shared.
It is recommended to use an async context manager to ensure the client is properly closed when the context is exited.

</Tip>
N_GLOBAL_ASYNC_CLIENT_FACTORY)r   s   &r'   set_async_client_factoryr   <  s
      $8 r*   c                8    V ^8  d   QhR\         P                  /# r   r   )r%   s   "r'   r(   r(   O  s      U\\ r*   c                     \         f(   \        ;_uu_ 4        \        4       s RRR4       \         # \         #   + '       g   i     \         # ; i)z
Get a `httpx.Client` object, using the transport factory from the user.

This client is shared between all calls made by `huggingface_hub`. Therefore you should not close it manually.

Use [`set_client_factory`] to customize the `httpx.Client`.
N)_GLOBAL_CLIENTr   r   r+   r*   r'   get_sessionr   O  s5     \35N > \s	   6A	c                8    V ^8  d   QhR\         P                  /# r   r   )r%   s   "r'   r(   r(   ^  s     * *5,, *r*   c                     \        4       # )a  
Return a `httpx.AsyncClient` object, using the transport factory from the user.

Use [`set_async_client_factory`] to customize the `httpx.AsyncClient`.

<Tip warning={true}>

Contrary to the `httpx.Client` that is shared between all calls made by `huggingface_hub`, the `httpx.AsyncClient` is not shared.
It is recommended to use an async context manager to ensure the client is properly closed when the context is exited.

</Tip>
r   r+   r*   r'   get_async_sessionr   ^  s     ())r*   c                    V ^8  d   QhRR/# )r   r6   Nr+   )r%   s   "r'   r(   r(   n  s     9 9t 9r*   c                     \         p Rs V e    V P                  4        R# R#   \         d$   p\        P	                  RT 24        Rp?R# Rp?ii ; i)z
Close the global `httpx.Client` used by `huggingface_hub`.

If a Client is closed, it will be recreated on the next call to [`get_session`].

Can be useful if e.g. an SSL certificate has been updated.
NzError closing client: )r   close	Exceptionrk   warning)clientes     r'   r   r   n  sT     F N 	9LLN   	9NN3A3788	9s   " AAAregister_at_fork)after_in_childmax_retriesbase_wait_timemax_wait_timeretry_on_exceptionsretry_on_status_codesstreamFc                @   V ^8  d   QhR\         R\        R\        R\        R\        R\        \
        ,          \        \        \
        ,          R3,          ,          R\        \        \        R3,          ,          R	\        R
\        \        P                  RR3,          /	# )r   rm   rK   r   r   r   r   .r   r   r6   N)r   r#   r$   floattyper   rL   boolr   rb   ry   )r%   s   "r'   r(   r(     s     ^8 ^8^8	^8 	^8
 ^8 ^8 i5i#1E+FF^8 sCx0^8 ^8 u~~tT)*^8r*   c          	   +    a aaaaa"   \        V\        4      '       d   V3p\        S\        4      '       d   S3o^ oTp	RoRp
RV9   dE   \        VR,          \        P                  \
        34      '       d   VR,          P                  4       p
\        4       p S^,          oRo V
e   VR,          P                  V
4       R VV VVVV3R llpV'       dG   VP                  ! RRS RS/VB ;_uu_ 4       pV! V4      '       g   Vx   RRR4       R#  RRR4       M+VP                  ! RRS RS/VB pV! V4      '       g   Vx  R#  Se3   \!        S4      ^,           p\        P                  R
V RS RS R24       M!T	p\        P                  RV RS RS R24       \"        P$                  ! V4       \'        WI^,          4      p	EK2    + '       g   i     L; i  T d\   p\        P                  RT RS  R	S 24       \        T\        P                  4      '       d   \        4        SS8  d   Th Rp?LRp?ii ; i5i)zfInternal implementation of HTTP backoff logic shared between `http_backoff` and `http_stream_backoff`.Ndatac                D    V ^8  d   QhR\         P                  R\        /# )r   rw   r6   )rb   ry   r   )r%   s   "r'   r(   (_http_backoff_base.<locals>.__annotate__  s       4 r*   c                  < V P                   S9  d   R# \        P                  RV P                    RS RS 24       SS8  d   \        V 4       R# V P                   R8X  d&   \	        V P
                  4      pVe   VP                  oR# )zNHandle response and return True if should retry, False if should return/yield.FzHTTP Error z thrown while requesting    T)r|   rk   r   hf_raise_for_statusrG   r5   r   )rw   ratelimit_infor   rm   nb_triesratelimit_resetr   rK   s   & r'   _should_retry)_http_backoff_base.<locals>._should_retry  s     ''/DD  X-A-A,BB[\b[ccdehdijkk)'1 ! ''3.%<X=M=M%NN%1*8*I*Ir*   rm   rK   'z' thrown while requesting r   zRate limited. Waiting zs before retry [Retry rN   z].zRetrying in z	s [Retry r+   )
isinstancer   r$   ioIOBaser   tellr   seekr   r`   rk   r   rb   ConnectErrorr   r   timesleepmin)rm   rK   r   r   r   r   r   r   kwargs
sleep_timeio_obj_initial_posr   r   rw   erractual_sleepr   r   s   ffd$$$d$,       @@r'   _http_backoff_baser     s*     %t,,24'--!6 8HJ"&O
 Jvf~		<7PQQ#F^002]F
A0	 "-v##$67 . ]]D&DcDVDD(22& ED2 ED
 ">>KKSKFK$X.."N / & 1A5LNN3L>AWX`Waabcnbooqrs%LNN\,y
!K=XZ[\

<  Q7
; ED # 	NNQse#=fXQseLM#u1122+%	 &	sz   BI%1G G 5G
	G IG I#G G BI
G	G IG H?$AH:5I:H??Ic                   V ^8  d   QhR\         R\        R\        R\        R\        R\        \
        ,          \        \        \
        ,          R3,          ,          R\        \        \        R3,          ,          R	\        P                  /# )
r   rm   rK   r   r   r   r   .r   r6   )	r   r#   r$   r   r   r   rL   rb   ry   )r%   s   "r'   r(   r(     s     M MM	M 	M
 M M i5i#1E+FFM sCx0M ^^Mr*   c               J    \        \        R
RV RVRVRVRVRVRVRR	/VB 4      # )ax
  Wrapper around httpx to retry calls on an endpoint, with exponential backoff.

Endpoint call is retried on exceptions (ex: connection timeout, proxy error,...)
and/or on specific status codes (ex: service unavailable). If the call failed more
than `max_retries`, the exception is thrown or `raise_for_status` is called on the
response object.

Re-implement mechanisms from the `backoff` library to avoid adding an external
dependencies to `hugging_face_hub`. See https://github.com/litl/backoff.

Args:
    method (`Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"]`):
        HTTP method to perform.
    url (`str`):
        The URL of the resource to fetch.
    max_retries (`int`, *optional*, defaults to `5`):
        Maximum number of retries, defaults to 5 (no retries).
    base_wait_time (`float`, *optional*, defaults to `1`):
        Duration (in seconds) to wait before retrying the first time.
        Wait time between retries then grows exponentially, capped by
        `max_wait_time`.
    max_wait_time (`float`, *optional*, defaults to `8`):
        Maximum duration (in seconds) to wait before retrying.
    retry_on_exceptions (`type[Exception]` or `tuple[type[Exception]]`, *optional*):
        Define which exceptions must be caught to retry the request. Can be a single type or a tuple of types.
        By default, retry on `httpx.TimeoutException` and `httpx.NetworkError`.
    retry_on_status_codes (`int` or `tuple[int]`, *optional*, defaults to `(429, 500, 502, 503, 504)`):
        Define on which status codes the request must be retried. By default, retries
        on rate limit (429) and server errors (5xx).
    **kwargs (`dict`, *optional*):
        kwargs to pass to `httpx.request`.

Example:
```
>>> from huggingface_hub.utils import http_backoff

# Same usage as "httpx.request".
>>> response = http_backoff("GET", "https://www.google.com")
>>> response.raise_for_status()

# If you expect a Gateway Timeout from time to time
>>> http_backoff("PUT", upload_url, data=data, retry_on_status_codes=504)
>>> response.raise_for_status()
```

> [!WARNING]
> When using `requests` it is possible to stream data by passing an iterator to the
> `data` argument. On http backoff this is a problem as the iterator is not reset
> after a failed call. This issue is mitigated for file objects or any IO streams
> by saving the initial position of the cursor (with `data.tell()`) and resetting the
> cursor between each call (with `data.seek()`). For arbitrary iterators, http backoff
> will fail. If this is a hard constraint for you, please let us know by opening an
> issue on [Github](https://github.com/huggingface/huggingface_hub).
rm   rK   r   r   r   r   r   r   Fr+   )nextr   rm   rK   r   r   r   r   r   r   s   &&$$$$$,r'   http_backoffr     sp    B  
	

	

	
 $
	
 *	
	

 (
	
 !4
	
 #8
	
 
	
 
	
 r*   c                4   V ^8  d   QhR\         R\        R\        R\        R\        R\        \
        ,          \        \        \
        ,          R3,          ,          R\        \        \        R3,          ,          R	\        \        P                  R
R
3,          /# )r   rm   rK   r   r   r   r   .r   r6   N)
r   r#   r$   r   r   r   rL   r   rb   ry   )r%   s   "r'   r(   r(   ?  s     O OO	O 	O
 O O i5i#1E+FFO sCx0O u~~tT)*Or*   c             +  X   "   \        RRV RVRVRVRVRVRVRR	/VB  R
j  xL
  R
#  L5i)a
  Wrapper around httpx to retry calls on an endpoint, with exponential backoff.

Endpoint call is retried on exceptions (ex: connection timeout, proxy error,...)
and/or on specific status codes (ex: service unavailable). If the call failed more
than `max_retries`, the exception is thrown or `raise_for_status` is called on the
response object.

Re-implement mechanisms from the `backoff` library to avoid adding an external
dependencies to `hugging_face_hub`. See https://github.com/litl/backoff.

Args:
    method (`Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"]`):
        HTTP method to perform.
    url (`str`):
        The URL of the resource to fetch.
    max_retries (`int`, *optional*, defaults to `5`):
        Maximum number of retries, defaults to 5 (no retries).
    base_wait_time (`float`, *optional*, defaults to `1`):
        Duration (in seconds) to wait before retrying the first time.
        Wait time between retries then grows exponentially, capped by
        `max_wait_time`.
    max_wait_time (`float`, *optional*, defaults to `8`):
        Maximum duration (in seconds) to wait before retrying.
    retry_on_exceptions (`type[Exception]` or `tuple[type[Exception]]`, *optional*):
        Define which exceptions must be caught to retry the request. Can be a single type or a tuple of types.
        By default, retry on `httpx.TimeoutException` and `httpx.NetworkError`.
    retry_on_status_codes (`int` or `tuple[int]`, *optional*, defaults to `(429, 500, 502, 503, 504)`):
        Define on which status codes the request must be retried. By default, retries
        on rate limit (429) and server errors (5xx).
    **kwargs (`dict`, *optional*):
        kwargs to pass to `httpx.request`.

Example:
```
>>> from huggingface_hub.utils import http_stream_backoff

# Same usage as "httpx.stream".
>>> with http_stream_backoff("GET", "https://www.google.com") as response:
...     for chunk in response.iter_bytes():
...         print(chunk)

# If you expect a Gateway Timeout from time to time
>>> with http_stream_backoff("PUT", upload_url, data=data, retry_on_status_codes=504) as response:
...     response.raise_for_status()
```

<Tip warning={true}>

When using `httpx` it is possible to stream data by passing an iterator to the
`data` argument. On http backoff this is a problem as the iterator is not reset
after a failed call. This issue is mitigated for file objects or any IO streams
by saving the initial position of the cursor (with `data.tell()`) and resetting the
cursor between each call (with `data.seek()`). For arbitrary iterators, http backoff
will fail. If this is a hard constraint for you, please let us know by opening an
issue on [Github](https://github.com/huggingface/huggingface_hub).

</Tip>
rm   rK   r   r   r   r   r   r   TNr+   )r   r   s   &&$$$$$,r'   http_stream_backoffr   >  sp     L " 


  
 &	

 $
 0
 4
 
 
 
 
s   *(*retry_on_errorsc                \    V ^8  d   QhR\         R\        R\        R\        P                  /# )r   rm   rK   r   r6   )r   r#   r   rb   ry   )r%   s   "r'   r(   r(     s0     0 00 #09=0
^^0r*   c               j   V'       d   / MRRRR/p \        RRV RV/VBRR/BVB p\        V4       RVP                  u;8:  d   R8:  dh   M  V# \        VP                  R	,          4      pVP
                  R
8X  d6   \        V4      P                  VP                  R7      P                  4       pK   V# )a  Perform an HTTP request with backoff and follow relative redirects only.

Used to fetch HEAD /resolve on repo or bucket files.

This is useful to follow a redirection to a renamed repository without following redirection to a CDN.

A backoff mechanism retries the HTTP call on errors (429, 5xx, timeout, network errors).

Args:
    method (`str`):
        HTTP method, such as 'GET' or 'HEAD'.
    url (`str`):
        The URL of the resource to fetch.
    retry_on_errors (`bool`, *optional*, defaults to `False`):
        Whether to retry on errors. If False, no retry is performed (fast fallback to local cache).
        If True, uses default retry behavior (429, 5xx, timeout, network errors).
    **httpx_kwargs (`dict`, *optional*):
        Params to pass to `httpx.request`.
r   r   rm   rK   r   Fi,  i  Location )pathr+   )	r   r   r|   r
   r5   netloc_replacer   geturl)rm   rK   r   httpx_kwargsno_retry_kwargsrw   parsed_targets   &&$,   r'   -_httpx_follow_relative_redirects_with_backoffr     s    0 $92?VXZ#[   


 
 #	

 
 	H% (&&-#- 	O %X%5%5j%ABM##r)sm,,-2D2D,ELLN 	Or*   c                J    V ^8  d   QhR\         R\         R,          R\         /# )r   rK   endpointNr6   rZ   )r%   s   "r'   r(   r(     s%     
 
 
sTz 
c 
r*   c                "   V'       d   VP                  R4      M\        P                  pV\        P                  \        P                  39  dA   V P                  \        P                  V4      p V P                  \        P                  V4      p V # )zReplace the default endpoint in a URL by a custom one.

This is useful when using a proxy and the Hugging Face Hub returns a URL with the default endpoint.
rN   )rstripr   ENDPOINT_HF_DEFAULT_ENDPOINT_HF_DEFAULT_STAGING_ENDPOINTreplace)rK   r   s   &&r'   fix_hf_endpoint_in_urlr     sf    
 (0xs#Y5G5GH	66	8^8^__kk)88(Ckk)@@(KJr*   c                V    V ^8  d   QhR\         P                  R\        R,          RR/# )r   rw   endpoint_nameNr6   )rb   ry   r#   )r%   s   "r'   r(   r(     s/     \? \?%.. \?t \?W[ \?r*   c           	     6
    \        V 4        V P	                  4        R#   \         d    \        P                  RRR7        L7i ; i  \
        P                   Ed   pT P                  ^d,          ^8X  d    Rp?R# T P                  P                  R4      pT P                  P                  R4      pT P                  e8   T P                  P                  e    \        T P                  P                  4      MRpT'       d   \        T4      MR6w  rgTR8X  d?   T P                   R2R	,           R
T P                   R2,           p\        \        YYgR7      ThTR8X  d?   T P                   R2R	,           RT P                   R2,           p\        \         YYgR7      ThTR8X  d?   T P                   R2R	,           RT P                   R2,           p\        \"        YYgR7      ThTR8X  dK   T P                   R2R	,           RT P                   R2,           R,           R,           p\        \$        Y4      ThTR8X  dq   Tem   \&        P)                  T4      eV   T P                   R2R	,           RT P                   R2,           R,           R,           p\        \*        Y\-        T4      R7      ThTR8X  g4   T P                  R8X  do   TR8w  dh   Ted   \.        P)                  T4      eM   T P                   R2R	,           RT P                   R2,           R,           R,           p\        \0        YYgR7      ThT P                  R8X  d   Te   RT R 2MR!p\        \2        Y4      ThT P                  R"8X  dA   R	T P                   R#T R2R$T P                   R2,           R%,           p\        \4        Y4      ThT P                  R&8X  d   \7        T P                  4      p	T	e   R'T	P8                   R(2pTR)T	P:                   R*2,          pT	P<                  eA   T	P>                  e3   TR+T	P@                   R,T	P<                   R-T	P>                   R.2,          pM	TR,          pTR/T P                   R2,          pMR0T P                   R2p\        \4        Y4      ThT P                  R18X  d[   T P                  P                  P                  R24      p
T R3T
 R4T P                  P                  R54       R2p\        \4        Y4      Th\        \4        \        T4      T 4      ThRp?ii ; i)7ad  
Internal version of `response.raise_for_status()` that will refine a potential HTTPError.
Raised exception will be an instance of [`~errors.HfHubHTTPError`].

This helper is meant to be the unique method to raise_for_status when making a call to the Hugging Face Hub.

Args:
    response (`Response`):
        Response from the server.
    endpoint_name (`str`, *optional*):
        Name of the endpoint that has been called. If provided, the error message will be more complete.

> [!WARNING]
> Raises when the request has failed:
>
>     - [`~utils.RepositoryNotFoundError`]
>         If the repository to download from cannot be found. This may be because it
>         doesn't exist, because `repo_type` is not set correctly, or because the repo
>         is `private` and you do not have access.
>     - [`~utils.GatedRepoError`]
>         If the repository exists but is gated and the user is not on the authorized
>         list.
>     - [`~utils.RevisionNotFoundError`]
>         If the repository exists but the revision couldn't be found.
>     - [`~utils.EntryNotFoundError`]
>         If the repository exists but the entry (e.g. the requested file) couldn't be
>         find.
>     - [`~utils.BadRequestError`]
>         If request failed with a HTTP 400 BadRequest error.
>     - [`~utils.HfHubHTTPError`]
>         If request failed for a reason not listed above.
zFailed to parse warning headersT)exc_infoNzX-Error-CodeX-Error-MessageRevisionNotFoundz Client Error.

zRevision Not Found for url: .)rT   rW   EntryNotFoundzEntry Not Found for url: 	GatedRepoz!Cannot access gated repo for url z$Access to this resource is disabled.z!Cannot access repository for url 
RepoNotFoundzBucket Not Found for url: zG
Please make sure you specified the correct bucket id (namespace/name).zg
If the bucket is private, make sure you are authenticated and your token has the required permissions.)	bucket_idi  z+Invalid credentials in Authorization headerzRepository Not Found for url: z
Please make sure you specified the correct `repo_id` and `repo_type`.
If you are trying to access a private or gated repo, make sure you are authenticated and your token has the required permissions.zQ
For more details, see https://huggingface.co/docs/huggingface_hub/authenticationr{   z

Bad request for z
 endpoint:z

Bad request:i  z Forbidden: z
Cannot access content at: z2
Make sure your token has the correct permissions.r   z0

429 Too Many Requests: you have reached your 'z' rate limit.z
Retry after z seconds (rN   z requests remaining in current z
s window).z
Url: z!

429 Too Many Requests for url: i  Rangez. Requested range: z. Content-Range: zContent-RangerO   )!_warn_on_warning_headersr   rk   rl   raise_for_statusrb   HTTPStatusErrorr|   r5   rR   r`   rK   r#   rX   _formatr   r   r   r   BUCKET_API_REGEXr?   r   r]   REPO_API_REGEXr   r   r   rG   r   r   r    r!   r   )rw   r   r   
error_codeerror_messagerequest_urlrT   rW   messager   range_headers   &&         r'   r   r     sn   BG *
u?!!#  G6FG    s?3&!+%%)).9
 ((,,->? *2)9)9)E(JZJZJ^J^JjC  $$%pt 	 HS6{CXd	++!--.n=FKghphthtguuvIwwG/iiopp?*!--.n=FKdemeqeqdrrsIttG2GQZlrss;&''(7&@EfgogsgsfttuCvv  .'ybhiiDD''(75hll^1EF  9	9  +W?QF .(' ''4@ ''(7.x||nA>? ]] }	}  #WB[\gBh >)  C'!NN'%%k2> ''(728<<.BC`` gg  17PYkqrr!!S(DQD]&}oZ@cu  /7=1D!!S(x++,LqI0a@AGH 
 .'<!C!!S(4X5E5EFN)HIeIeHffst  ^N,K,K+LHUU!''38U8U8a^556a8L8L7M N''5'D'D&EZQG
 sNGWX\\N!44?~QO.'<!C!!S(#++3377@L.|n<MhN^N^NbNbcrNsMttuvG.'<!C nc!fh7Q>gs?s4     A "AATT<BTPTTc                <    V ^8  d   QhR\         P                  RR/# rv   rx   )r%   s   "r'   r(   r(   s  s     ( (u~~ ($ (r*   c                N   V P                   P                  R4      pV F  pRV9   d   VP                  R^4      MRV3w  r4VP                  4       pV\        9  g   K?  VP                  4       pV'       g   KY  \        P                  V4       \        P                  V4       K  	  R# )a}  
Emit warnings if warning headers are present in the HTTP response.

Expected header format: 'X-HF-Warning: topic; message'

Only the first warning for each topic will be shown. Topic is optional and can be empty. Note that several warning
headers can be present in a single response.

Args:
    response (`httpx.Response`):
        The HTTP response to check for warning headers.
zX-HF-Warning;r   N)r5   get_listsplitstrip_WARNED_TOPICSaddrk   r   )rw   server_warningsserver_warningtopicr  s   &    r'   r  r  s  s     &&//?O)9<9N--c15UWYgTh&mmoGw""5)w' *r*   _HfHubHTTPErrorT)boundc          
      ~    V ^8  d   QhR\         \        ,          R\        R\        P                  R\
        R\        /# )r   
error_typecustom_messagerw   attrsr6   )r   r  r#   rb   ry   r   )r%   s   "r'   r(   r(     sE     _ _%&_8;_GL~~_`c__r*   c                    . pVP                   P                  R 4      pVe   VP                  V4         VP                  4       pTP                  R4      pTe:   \        T\        4      '       d   TP                  T4       MTP                  T4       TP                  R4      pTe+   T F$  pRT9   g   K  TP                  TR,          4       K&  	  T U
u. uF=  p
\        T
4      P                  4       '       g   K$  \        T
4      P                  4       NK?  	  pp
\        \         P#                  T4      4      pRP%                  T4      pTpT'       dL   TP                  4       TP                  4       9  d)   R	T9   d   TRT,           ,          pMTR	T,           ,          pRpRp\&        R
3\(        R3\*        R33 F?  w  ppTP                   P                  T4      pT'       g   K+  \        T4      pRT RT R2p M	  T'       d[   TP                  4       TP                  4       9  d8   RT9   d)   TP-                  R4      pTRT T,           TTR ,           pMY,          pT ! TP                  4       Y+;'       g    RR7      pTP/                  4        F  w  pp\1        TTT4       K  	  T#   \        P
                   d;     TP                  4        TP                  4       p EL  \         d    / p  ELi ; ii ; i  \        P                   dc    TP                   P                  RR4      p	TP                  '       d1   RT	P                  4       9  d   TP                  TP                  4        ELi ; iu up
i )r   Nerrorerrorsr  zContent-Typer   htmlr   r   z
Request IDzAmzn Trace IDz	Amz CF IDr  : ))rw   server_message)r5   rR   appendjsonrb   ResponseNotReadreadRuntimeErrorr   listextendJSONDecodeErrortextr=   r#   r  dictfromkeysjoinrh   rg   X_AMZ_CF_IDindexitemssetattr)r  r  rw   r  server_errorsfrom_headersr   r   r!  content_typeliner%  final_error_messagerp   request_id_messageheaderlabelvaluenewline_indexr   kvs   &&&,                  r'   r  r    s.    M ##''(9:L\*$0	==?D !%&&$$U+ $$U+(#%!((y)9:   4AV=4CIOODU&SY__&=MV }56M YY}-N )...08L8L8NN^#4.#886N#:: J	|$	/*	k"
   $$V,5UJ#%eWBugQ!7 j&&(0C0I0I0KK&&/55d;M#N]36HHK^_l_mKnn    5 (..08TjTjfj
kC1Q Ja $$ 
		}}  	
	8  0''++NB?===V<+=+=+??  /	0 Wsg   J* A,K< 6K< !M6<M6*K9  K# K< #K50K91K< 4K55K99K< <AM3?0M32M3c                D    V ^8  d   QhR\         P                  R\        /# )r   r`   r6   )rb   rc   r#   )r%   s   "r'   r(   r(     s     &  & emm &  & r*   c                   RRV P                   3.p\        V P                  P                  4       4       F-  w  r#VP	                  4       R8X  d   RpVRV RV 23.,          pK/  	  Rp V P
                  e:   V P
                  P                  RRR	7      p\        V4      R
8  d   VR,           R2pTe   TRTP                  RR4      3.,          pTRT P                  3.,          p. pT F]  w  r#T'       d$   TP                  \        \        T4      4      4       T'       g   K:  TP                  \        \        T4      4      4       K_  	  RP                  T4      #   \        P                   d    Rp Li ; i)zConvert a `httpx.Request` into a curl command (str).

Used for debug purposes only.

Implementation vendored from https://github.com/ofw/curlify/blob/master/curlify.py.
MIT License Copyright (c) 2016 Egor.
Nz-Xre   z<TOKEN>z-Hr#  zutf-8ignore)r!  i  :Ni  Nz ... [truncated]z<streaming body>z-dr   r   r   )curlN)rm   sortedr5   r4  r=   contentdecodelenrb   RequestNotReadr   rK   r&  r   r#   r1  )r`   partsr@  rA  body
flat_partss   &     r'   ro   ro     sb    		w~~$E
 w,,./779'A4A3b%&& 0
 D"??&??))'()CD4y4u+&67 4dB/011	tW[[!""EJeCFm,1eCFm,	  88J  "!"s   (AE E54E5z%^\s*bytes\s*=\s*(\d*)\s*-\s*(\d*)\s*$c                X    V ^8  d   QhR\         R,          R\        R\         R,          /# )r   original_rangeNresume_sizer6   r"   )r%   s   "r'   r(   r(     s*     "! "!t "!# "!#PT* "!r*   c                   V '       g   RV R2# RV 9   d   \        RV : R24      h\        P                  V 4      pV'       g   \        RV : R24      hVP	                  4       w  r4V'       gI   V'       g   \        RV : R24      h\        V4      V,
          pRV 2pV^ 8:  d   \        R	V: R24      hV# \        V4      pW1,           pV'       d,   \        V4      pRV RV 2pWt8  d   \        R	V: R24      hV# RV R2# )
z:
Adjust HTTP Range header to account for resume position.
zbytes=-,zMultiple ranges detected - z, not supported yet.zInvalid range format - r   zbytes=-zEmpty new range - )r}   RANGE_REGEXrE   r*  groupsr$   )rO  rP  rE   startend
new_suffix	new_range	new_starts   &&      r'   _adjust_range_headerr[    s!    }A&&
n6~6HH\]^^n-E4^4FaHIIJE!88J!LMMX+
j\*	?!3I=BCCJE#I
#hYKq.	?!3I=BCCI;a  r*   c                L   V ^8  d   Qh/ ^ \         9   d
   \        ;R&   ^\         9   d
   \        ;R&   ^\         9   d   \        P                  R,          ;R&   ^\         9   d"   \
        \        \        ,          R3,          ;R&   ^\         9   d   \
        \        R3,          ;R&   # )r   r   r   Nr   ._DEFAULT_RETRY_ON_EXCEPTIONS_DEFAULT_RETRY_ON_STATUS_CODES)	__conditional_annotations__r   r   rb   r   rL   r   r   r$   )r%   s   "r'   r(   r(      s     D Dp B A( Aq Er T S4 Ss Et + *t# *u Ev i heDOS$89 hw Ex L Kc3h Ky Er*   >	   rawblobrefstreecommitresolverevisionsettingsdiscussions)r   i  i  i  i  )N)ir_  r0   atexitr   r'  osre	threadingr   ri   collections.abcr   r   r   
contextlibr   dataclassesr   shlexr   typingr   r	   urllib.parser
   rb   huggingface_hub.errorsr   r   r   r!  r   r   r   r   r   r   r   r   r   _lfsr   _typingr   
get_loggerr,   rk   r   compiler>   rA   rG   rh   rg   r2  VERBOSEr  r  rP   r\   rS   rX   r]   rq   rt   r   r   r   r   r   r   r   Lockr   r   r   r   r   r   r   r   r   registerhasattrr   TimeoutExceptionNetworkErrorr]  r^  r   r   r   r   r   r   setr  r  r  r  ro   
IGNORECASErT  r[  r(   )r_  s   @r'   <module>r     sL   E  	  	 	    8 8 % !   !  7 	 	 	   " 
		H	% $& & &, ::mn **%OP 8z #
 ** :: **  **%ij  JJ'ST  q 2-B*' B,- !"e&7&7"78 ~~+A  A7S  S&* *0"8&* 9,  
2!""}5 >C=S=SUZUgUg<h  h2K  K^8 	^8
 ^8 ^8 Jf^8 4R^8 ^8BM 	M
 M M JfM 4RM` O 	O
 O O JfO 4RO Od0@E0f
\?~ (0 -^D _D& T jjA2==Q"!r*   