
    RЦi                        % S r SSKrSSKrSSKrSSK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JrJrJrJrJr  SSKJr  SSK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*  \&RV                  " \,5      r-\" SS9 " S S5      5       r.\R^                  " S5      r0\R^                  " S5      r1S\\2\24   S\\.   4S jr3Sr4Sr5Sr6\R^                  " S\Rn                  S9r8\R^                  " S\Rn                  S9r9S\Rt                  SS4S  jr;S\Rt                  SS4S! jr<S"\Rz                  SS4S# jr>S\R~                  4S$ jr@S\R                  4S% jrB\/ \R~                  4   rC\/ \R                  4   rD\R                  " 5       rF\@qG\C\HS&'   \BqI\D\HS''   SqJ\\R~                     \HS('   S)\CSS4S* jrKS+\DSS4S, jrLS\R~                  4S- jrMS\R                  4S. jrNSVS/ jrO\R                  " \O5        \Q" \S05      (       a  \R                  " \OS19  \R                  \R                  4rU\V\W\X   S24   \HS3'   S4rY\V\ZS24   \HS5'   S6SS7\U\YS8S9.S:\*S;\2S<\ZS=\[S>\[S?\\W\X   \V\W\X   S24   4   S@\\Z\V\ZS24   4   SA\\S\\Rz                  SS4   4SB jjr]S6SS7\U\YSC.S:\*S;\2S<\ZS=\[S>\[S?\\W\X   \V\W\X   S24   4   S@\\Z\V\ZS24   4   S\Rz                  4SD jjr^\
S6SS7\U\YSC.S:\*S;\2S<\ZS=\[S>\[S?\\W\X   \V\W\X   S24   4   S@\\Z\V\ZS24   4   S\\Rz                  SS4   4SE jj5       r_S8SF.S:\*S;\2SG\\S\Rz                  4SH jjr`S;\2SI\\2   S\24SJ jraSWS"\Rz                  SK\\2   SS4SL jjrb\c" 5       rdS"\Rz                  SS4SM jreSN\W\"   SO\2S"\Rz                  S\"4SP jrfS\Rt                  S\24SQ jrg\R^                  " SR\R                  5      riSS\\2   ST\ZS\\2   4SU jrjg)Xz>Contains utilities to handle HTTP requests in huggingface_hub.    N)contextmanager)	dataclass)quote)AnyCallable	GeneratorMappingOptionalUnion)urlparse)OfflineModeIsEnabled   )	constants)BadRequestErrorBucketNotFoundErrorDisabledRepoErrorGatedRepoErrorHfHubHTTPErrorRemoteEntryNotFoundErrorRepositoryNotFoundErrorRevisionNotFoundError   )logging)SliceFileObj)HTTP_METHOD_TT)frozenc                   `    \ rS rSr% Sr\\S'   \\S'   \\S'   Sr\	\   \S'   Sr
\	\   \S'   S	rg)
RateLimitInfo6   a  
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.

resource_type	remainingreset_in_secondsNlimitwindow_seconds )__name__
__module____qualname____firstlineno____doc__str__annotations__intr#   r
   r$   __static_attributes__r%       Z/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/huggingface_hub/utils/_http.pyr   r   6   s6    
 NE8C=$(NHSM(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+)headersreturnc                    SnSnU  H+  nUR                  5       nUS:X  a  X   nM  US:X  d  M'  X   nM-     U(       d  g[        R                  U5      nU(       d  gUR                  S5      n[	        UR                  S5      5      n[	        UR                  S5      5      nSn	Sn
U(       aP  [
        R                  U5      nU(       a4  [	        UR                  S5      5      n	[	        UR                  S5      5      n
[        UUUU	U
S	9$ )
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   )r1   r4   policykey	lower_keymatchr    r!   r"   r#   r$   policy_matchs               r0   parse_ratelimit_headersrC   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/
    requestc           	      t   [         R                  " 5       (       a  [        SU R                   S35      e[        U R
                  ;  aU  U R
                  R                  [        5      =(       d    [        [        R                  " 5       5      U R
                  [        '   U R
                  R                  [        5      n[        R                  SUU R                  U R                  U R
                  R                  S5      SL5        [         R                  (       a  [        R                  S[        U 5      5        U$ )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   urlX_AMZN_TRACE_IDr1   getX_REQUEST_IDr+   uuiduuid4loggerdebugmethodHF_DEBUG_curlify)rE   
request_ids     r0   hf_request_event_hookrU      s       """GKK=  )J  K
 	

 goo-+2??+>+>|+L+aPSTXT^T^T`Pa($$_5J LL/O,D8 Z'!23r/   c                     #    [        U 5      $ 7f)z+
Async version of `hf_request_event_hook`.
)rU   )rE   s    r0   async_hf_request_event_hookrW      s      !))s   responsec                    #    U R                   S:  aJ  SU R                  ;   a9   [        U R                  S   5      nUS:  a  U R	                  5       I S h  vN   g g g g ! [         a     g f = f N7f)N  zContent-lengthi@B )status_coder1   r-   
ValueErroraread)rX   lengths     r0   async_hf_response_event_hookr_      s     s" x///X--.>?@ 	!nn&&& " 0 #   's3   !A0A A0A.A0
A+(A0*A++A0c                  <    [         R                  " S[        /0SSS9$ )zI
Factory function to create a `httpx.Client` with the default transport.
rE   TNevent_hooksfollow_redirectstimeout)httpxClientrU   r%   r/   r0   default_client_factoryrg      s'     <<!6 78 r/   c                  H    [         R                  " [        /[        /S.SSS9$ )zN
Factory function to create a `httpx.AsyncClient` with the default transport.
)rE   rX   TNra   )re   AsyncClientrW   r_   r%   r/   r0   default_async_client_factoryrj      s,     !< =LhKij r/   _GLOBAL_CLIENT_FACTORY_GLOBAL_ASYNC_CLIENT_FACTORY_GLOBAL_CLIENTclient_factoryc                 \    [            [        5         U qSSS5        g! , (       d  f       g= f)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_client`] 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_client`] to get a correctly configured `httpx.Client`.
N)_CLIENT_LOCKclose_sessionrk   )rn   s    r0   set_client_factoryrr     s     
!/ 
s   
+async_client_factoryc                     U q g)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rl   )rs   s    r0   set_async_client_factoryrv     s
      $8 r/   c                      [         c  [           [        5       q SSS5        [         $ [         $ ! , (       d  f       [         $ = f)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)rm   rp   rk   r%   r/   r0   get_sessionrx   &  s3     35N > \s	   -
A c                      [        5       $ )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>
ru   r%   r/   r0   get_async_sessionrz   5  s     ())r/   c                      [         n Sq U b   U R                  5         gg! [         a"  n[        R	                  SU 35         SnAgSnAff = f)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: )rm   close	ExceptionrO   warning)clientes     r0   rq   rq   E  sT     F N 	9LLN   	9NN3A3788	9s    
AAAregister_at_fork)after_in_child._DEFAULT_RETRY_ON_EXCEPTIONS)  i  i  i  i  _DEFAULT_RETRY_ON_STATUS_CODES      F)max_retriesbase_wait_timemax_wait_timeretry_on_exceptionsretry_on_status_codesstreamrQ   rI   r   r   r   r   r   r   c          	   +   N  ^ ^^^^^#    [        U[        5      (       a  U4n[        T[        5      (       a  T4mSmUn	SmSn
SU;   a;  [        US   [        R                  [
        45      (       a  US   R                  5       n
[        5       n TS-  mSm U
b  US   R                  U
5        S[        R                  S[        4UU UUUU4S jjnU(       a;  UR                  " ST TS.UD6 nU" U5      (       d  Uv    SSS5        g SSS5        O(UR                  " ST TS.UD6nU" U5      (       d  Uv   g Tb.  [%        T5      S-   n[        R                  SU ST ST S35        O!U	n[        R                  SU ST ST S35        [&        R(                  " U5        [+        XIS-  5      n	GM%  ! , (       d  f       N= f! U aY  n[        R                  S	U S
T  ST 35        [        U[        R                   5      (       a
  [#        5         TT:  a  Ue SnANSnAff = f7f)zfInternal implementation of HTTP backoff logic shared between `http_backoff` and `http_stream_backoff`.r   Ndatar   rX   r2   c                   > U R                   T;  a  g[        R                  SU R                    ST ST 35        TT:  a  [        U 5        gU R                   S:X  a$  [	        U R
                  5      nUb  UR                  mg)zNHandle response and return True if should retry, False if should return/yield.FzHTTP Error z thrown while requesting  r   T)r[   rO   r~   hf_raise_for_statusrC   r1   r"   )rX   ratelimit_infor   rQ   nb_triesratelimit_resetr   rI   s     r0   _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/   rQ   rI   'z' thrown while requesting r   zRate limited. Waiting zs before retry [Retry /z].zRetrying in z	s [Retry r   r%   )
isinstancetyper-   ioIOBaser   tellrx   seekre   Responseboolr   rE   rO   r~   ConnectErrorrq   floattimesleepmin)rQ   rI   r   r   r   r   r   r   kwargs
sleep_timeio_obj_initial_posr   r   rX   erractual_sleepr   r   s   ```   `         @@r0   _http_backoff_baser   d  s:     %t,,24'--!6 8HJ%)O
 Jvf~		<7PQQ#F^002]F
A0	 "-v##$67 4  . ]]D&cDVD(22& ED2 ED
 ">>KSKFK$X.."N / & 1A5LNN3L>AWX`Waabcnbooqrs%LNN\,y
!K=XZ[\

<  Q7
 D ED # 	NNQse#=fXQseLM#u1122+%	 &	so   BH%AG +F2>G H%G H%&G 7A;H%2
G <G ?H% G H"	AHH%H""H%)r   r   r   r   r   c                <    [        [        SU UUUUUUSS.UD65      $ )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).
FrQ   rI   r   r   r   r   r   r   r%   )nextr   rQ   rI   r   r   r   r   r   r   s           r0   http_backoffr     sA    B  
	
#)' 3"7
	
 
	
 r/   c             +   H   #    [        SU UUUUUUSS.UD6 Sh  vN   g N7f)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>
Tr   Nr%   )r   r   s           r0   http_stream_backoffr     sA     L " 
%#/3
 
 
 
s   " ")retry_on_errorsr   c                P   U(       a  0 OSSS.n [        SU US.UDSS0DUD6n[        U5        SUR                  s=::  a  S::  a_  O   U$ [        UR                  S   5      nUR
                  S	:X  a2  [        U5      R                  UR                  S
9R                  5       nM   U$ )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   r   r   rc   Fi,  i  Location )path)	r   r   r[   r   r1   netloc_replacer   geturl)rQ   rI   r   httpx_kwargsno_retry_kwargsrX   parsed_targets          r0   -_httpx_follow_relative_redirects_with_backoffr   h  s    0 2XZ#[   

 
 #	

 
 	H% (&&-#- 	O %X%5%5j%ABM##r)sm,,-2D2D,ELLN 	Or/   endpointc                    U(       a  UR                  S5      O[        R                  nU[        R                  [        R                  4;  a@  U R                  [        R                  U5      n U R                  [        R                  U5      n U $ )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.
r   )rstripr   ENDPOINT_HF_DEFAULT_ENDPOINT_HF_DEFAULT_STAGING_ENDPOINTreplace)rI   r   s     r0   fix_hf_endpoint_in_urlr     sf    
 (0xs#Y5G5GH	66	8^8^__kk)88(Ckk)@@(KJr/   endpoint_namec           	      F	    [        U 5         U R	                  5         g! [         a    [        R                  SSS9   N2f = f! [
        R                   GaH  nU R                  S-  S:X  a   SnAgU R                  R                  S5      nU R                  R                  S5      nUS	:X  a4  U R                   S
3S-   SU R                   S3-   n[        [        XP5      UeUS:X  a4  U R                   S
3S-   SU R                   S3-   n[        [        XP5      UeUS:X  a4  U R                   S
3S-   SU R                   S3-   n[        [        XP5      UeUS:X  a:  U R                   S
3S-   SU R                   S3-   S-   S-   n[        [        XP5      UeUS:X  a  U R                   b  U R                   R                  bm  ["        R%                  ['        U R                   R                  5      5      b:  U R                   S
3S-   SU R                   S3-   S-   S-   n[        [(        XP5      UeUS:X  dm  U R                  S:X  a  US:w  a  U R                   b  U R                   R                  bj  [*        R%                  ['        U R                   R                  5      5      b7  U R                   S
3S-   SU R                   S3-   S-   n[        [,        XP5      UeU R                  S:X  a  Ub  SU S3OS n[        [.        XP5      UeU R                  S!:X  a8  SU R                   S"U S3S#U R                   S3-   S$-   n[        [0        XP5      UeU R                  S%:X  a  [3        U R                  5      nUb  S&UR4                   S'3nUS(UR6                   S)3-  nUR8                  b;  UR:                  b.  US*UR<                   S+UR8                   S,UR:                   S-3-  nOUS-  nUS.U R                   S3-  nOS/U R                   S3n[        [0        XP5      UeU R                  S0:X  aZ  U R                   R                  R                  S15      nU S2U S3U R                  R                  S45       S3n[        [0        XP5      Ue[        [0        ['        U5      U 5      UeSnAff = f)5ad  
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_infod      NzX-Error-CodeX-Error-MessageRevisionNotFoundz Client Error.

zRevision Not Found for url: .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).z;
If the bucket is private, make sure you are authenticated.i  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. For more details, see https://huggingface.co/docs/huggingface_hub/authenticationrZ   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 (r   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-Range)_warn_on_warning_headersr}   rO   rP   raise_for_statusre   HTTPStatusErrorr[   r1   rK   rI   _formatr   r   r   r   rE   BUCKET_API_REGEXr;   r+   r   REPO_API_REGEXr   r   r   rC   r    r"   r#   r$   r!   )rX   r   r   
error_codeerror_messagemessager   range_headers           r0   r   r     sE   BG *
o?!!#  G6FG    m?3&!+%%)).9
 ((,,->?++!--.n=FKghphthtguuvIwwG/CJ?*!--.n=FKdemeqeqdrrsIttG2GFAM;&''(7&@EfgogsgsfttuCvv  .'<!CDD''(75hll^1EF  9	9  +W?QF .(  ,  $$0 ''H,<,<,@,@(ABN ''(7.x||nA>? ]] Q	Q  -wAqH>)  C'!NN  ,  $$0%%c(*:*:*>*>&?@L ''(728<<.BCNN  17E1L!!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>[m?s,    A A A R R0P+RR c                 F   U R                   R                  S5      nU H  nSU;   a  UR                  SS5      OSU4u  p4UR                  5       nU[        ;  d  M=  UR                  5       nU(       d  MV  [        R                  U5        [        R                  U5        M     g)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   r   N)r1   get_listsplitstrip_WARNED_TOPICSaddrO   r~   )rX   server_warningsserver_warningtopicr   s        r0   r   r   D  s     &&//?O)9<9N--c15UWYgTh&mmoGw""5)w' *r/   
error_typecustom_messagec                 8   / nUR                   R                  S5      nUb  UR                  U5          UR                  5       nUR                  S5      nUb8  [        U[        5      (       a  UR                  U5        OUR                  U5        UR                  S5      nUb%  U H  nSU;   d  M  UR                  US   5        M!     U V	s/ s H<  n	[        U	5      R                  5       (       d  M#  [        U	5      R                  5       PM>     nn	[        [         R#                  U5      5      nSR%                  U5      n
UnU
(       a9  U
R                  5       UR                  5       ;  a  S	U;   a	  USU
-   -  nOUS	U
-   -  nSnSn[&        S
4[(        S4[*        S44 H=  u  pUR                   R                  U5      nU(       d  M)  [        U5      nSU SU S3n  O   U(       aL  UR                  5       UR                  5       ;  a*  SU;   a   UR-                  S5      nUS U U-   UUS  -   nOX-  nU " UR                  5       X*=(       d    S S9$ ! [        R
                   a9     UR                  5         UR                  5       n GND! [         a    0 n  GNTf = ff = f! [        R                   a`    UR                   R                  SS5      nUR                  (       a/  SUR                  5       ;  a  UR                  UR                  5         GNJf = fs  sn	f )Nr   errorerrorsr   zContent-Typer   htmlr   r   z
Request IDzAmzn Trace IDz	Amz CF IDr   : ))rX   server_message)r1   rK   appendjsonre   ResponseNotReadreadRuntimeErrorr   listextendJSONDecodeErrortextr9   r+   r   dictfromkeysjoinrL   rJ   X_AMZ_CF_IDindex)r   r   rX   server_errorsfrom_headersr   r   r   content_typeliner   final_error_messagerT   request_id_messageheaderlabelvaluenewline_indexs                     r0   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 )//1HUkgkll[ $$ 
		}}  	
	8  0''++NB?==V<+=+=+??  /	0 Wsa   I A)J  1J  "L3LJ% JJ  JJJ  JJJ   A0LLc                    SSU R                   4/n[        U R                  R                  5       5       H(  u  p#UR	                  5       S:X  a  SnUSU SU 34/-  nM*     Sn U R
                  b1  U R
                  R                  SS	S
9n[        U5      S:  a  USS  S3nUb  USUR                  SS5      4/-  nUSU R                  4/-  n/ nU H[  u  p#U(       a#  UR                  [        [        U5      5      5        U(       d  M8  UR                  [        [        U5      5      5        M]     SR                  U5      $ ! [        R                   a    Sn Nf = f)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.
)curlNz-XrG   z<TOKEN>z-Hr   Nzutf-8ignore)r   i  z ... [truncated]z<streaming body>z-dr   r   r   )rQ   sortedr1   itemsr9   contentdecodelenre   RequestNotReadr   rI   r   r   r+   r   )rE   partskvbody
flat_partss         r0   rS   rS     sd    		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   #>E EEz%^\s*bytes\s*=\s*(\d*)\s*-\s*(\d*)\s*$original_rangeresume_sizec                    U (       d  SU S3$ SU ;   a  [        SU < S35      e[        R                  U 5      nU(       d  [        SU < S35      eUR	                  5       u  p4U(       dB  U(       d  [        SU < S35      e[        U5      U-
  nSU 3nUS	::  a  [        S
U< S35      eU$ [        U5      nX1-   nU(       a*  [        U5      nSU SU 3nXt:  a  [        S
U< S35      eU$ SU S3$ )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=-r   zEmpty new range - )r\   RANGE_REGEXrA   r   groupsr-   )r  r  rA   startend
new_suffix	new_range	new_starts           r0   _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/   )r2   N)N)kr*   atexitr   r   osre	threadingr   rM   
contextlibr   dataclassesr   shlexr   typingr   r   r   r	   r
   r   urllib.parser   re   huggingface_hub.errorsr   r   r   r   r   r   r   r   r   r   r   r   r   _lfsr   _typingr   
get_loggerr&   rO   r   compiler:   r=   r+   rC   rL   rJ   r  VERBOSEr   r   RequestrU   rW   r   r_   rf   rg   ri   rj   CLIENT_FACTORY_TASYNC_CLIENT_FACTORY_TLockrp   rk   r,   rl   rm   rr   rv   rx   rz   rq   registerhasattrr   TimeoutExceptionNetworkErrorr   tupler   r}   r   r-   r   r   r   r   r   r   r   r   setr   r   r   rS   
IGNORECASEr   r'  r%   r/   r0   <module>rB     s   E  	  	 	    % !  E E !  7 	 	 	   " 
		H	% $) ) ), ::mn **%OP 8WS#X%6 88M;R 8z #
 ** :: ** 5== T B*u}} * *' 'D ' e&7&7  B,- !"e&7&7"78 ~~+A ( A7S 4 S)-& -0'7 0D 0"83I 8d 8&U\\ *5,, * 9,  
2!""}5 >C=S=SUZUgUg<h eDOS$89 h2K c3h K Ok9W^8^8	^8 	^8
 ^8 ^8 tId9os6J0KKL^8 !eCHo!56^8 ^8 u~~tT)*^8J Ok9WMM	M 	M
 M M tId9os6J0KKLM !eCHo!56M ^^M` 
 Ok9WOO	O 	O
 O O tId9os6J0KKLO !eCHo!56O u~~tT)*O Of AF00 #09=0
^^0f
 
x} 
 
V?%.. V?# V?Z^ V?r (u~~ ($ (0Zm^, Zmc ZmU^^ Zm`n Zmz& emm &  & T jjA2==Q"!# "!S "!XVY] "!r/   