Ë
    ÂÓ^j¾³  ã                   óp	  — U d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZ ddlmZ ddlmZ ddlmZ ddlmZmZ ddlmZ ddlZdd	lmZ d
dlmZ d
dlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& ddlm'Z' ddl(m)Z) ddl*m+Z+  e'jX                  e-«      Z. ed¬«       G d„ d«      «       Z/ ej`                  d«      Z1 ej`                  d«      Z2dee3e3f   de/dz  fd„Z4dee3e3f   de5dz  fd„Z6dZ7dZ8dZ9 ej`                  dejt                  ¬«      Z; ej`                  d ejt                  ¬«      Z< ej`                  d!«      Z= ej`                  d"«      Z> ej`                  d#«      Z?h d$£Z@d%e3deAe3dz  e3dz  f   fd&„ZBd%e3de3dz  fd'„ZCd%e3de3dz  fd(„ZDd)ejŠ                  ddfd*„ZFd)ejŠ                  ddfd+„ZGd,ej�                  ddfd-„ZIdej”                  fd.„ZKdej˜                  fd/„ZMe
g ej”                  f   ZNe
g ej˜                  f   ZO ej                   «       ZQeKaReNeSd0<   eMaTeOeSd1<   daUej”                  dz  eSd2<   d3eNddfd4„ZVd5eOddfd6„ZWdej”                  fd7„ZXdej˜                  fd8„ZYdkd9„ZZ ej¶                  eZ«        e\ed:«      r ejº                  eZ¬;«       ej¼                  ej¾                  ejÀ                  fZaeAebec   d<f   eSd=<   d>ZdeAe5d<f   eSd?<   d@ddAeaeddBdCœdDe+d%e3dEe5dFeedGeedHebec   eAebec   d<f   z  dIe5eAe5d<f   z  dJefdeej�                  ddf   fdK„Zgd@ddAeaeddLœdDe+d%e3dEe5dFeedGeedHebec   eAebec   d<f   z  dIe5eAe5d<f   z  dej�                  fdM„Zhed@ddAeaeddLœdDe+d%e3dEe5dFeedGeedHebec   eAebec   d<f   z  dIe5eAe5d<f   z  deej�                  ddf   fdN„«       ZidBdOœdDe+d%e3dPefdej�                  fdQ„Zjd%e3dRe3dz  de3fdS„Zkdld,ej�                  dTe3dz  ddfdU„Zl em«       Znd,ej�                  ddfdV„Zo edWe"¬X«      ZpdYebep   dZe3d,ej�                  d[edepf
d\„Zqd]ZrerD � �cg c]9  }  ej`                  d^| › d_�«      d`f ej`                  da| › db�«      dcffD ]  }|‘Œ Œ; c}} Zsdde3de3fde„Ztd)ejŠ                  de3fdf„Zu ej`                  dgejì                  «      Zwdhe3dz  die5de3dz  fdj„Zxyc c}} w )mz>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ÚJobNotFoundErrorÚRemoteEntryNotFoundErrorÚRepositoryNotFoundErrorÚRevisionNotFoundErroré   )Úlogging)ÚSliceFileObj)ÚHTTP_METHOD_TT)Úfrozenc                   óX   — e Zd ZU dZeed<   eed<   eed<   dZedz  ed<   dZedz  ed<   y)Ú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.

    Úresource_typeÚ	remainingÚreset_in_secondsNÚlimitÚwindow_seconds)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__Úintr"   r#   © ó    úf/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/huggingface_hub/utils/_http.pyr   r   7   s6   … ñ
ð ÓØƒNØÓØ€Eˆ3�‰:ÓØ!%€N�C˜$‘JÔ%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                 óæ  — d}d}| D ](  }|j                  «       }|dk(  r| |   }Œ|dk(  sŒ$| |   }Œ* |syt        j                  |«      }|sy|j                  d«      }t	        |j                  d«      «      }t	        |j                  d«      «      }d}	d}
|rKt
        j                  |«      }|r4t	        |j                  d«      «      }	t	        |j                  d«      «      }
t        ||||	|
¬	«      S )
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   )r.   r1   ÚpolicyÚkeyÚ	lower_keyÚmatchr   r    r!   r"   r#   Úpolicy_matchs               r-   Úparse_ratelimit_headersr@   S   s  € ð* !€IØ€FØò "ˆØ—I‘I“Kˆ	Ø˜Ò#Ø ™‰IØÐ,Ó,Ø˜S‘\‰Fð"ñ Øä×#Ñ# IÓ.€EÙØà—K‘K Ó0€MÜ�E—K‘K Ó$Ó%€IÜ˜5Ÿ;™; sÓ+Ó,Ðà€EØ!%€NáÜ.×5Ñ5°fÓ=ˆÙÜ˜×*Ñ*¨3Ó/Ó0ˆEÜ  ×!3Ñ!3°CÓ!8Ó9ˆNäØ#ØØ)ØØ%ôð r,   c                 ó¬   — d}| D ]  }|j                  «       dk(  sŒ| |   } n |€y|j                  «       }|sy|j                  «       rt        |«      S y)a[  Parse the standard `Retry-After` HTTP header into a number of seconds to wait.

    The `Retry-After` header can be either a non-negative number of seconds (delay-seconds)
    or an HTTP-date after which to retry. We handle only the delay-seconds case.

    See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Retry-After.
    Nzretry-after)r6   ÚstripÚisdigitr*   )r.   Úvaluer<   s      r-   Ú_parse_retry_afterrE   Ž   sc   € ð €EØò ˆØ�9‰9‹;˜-Ó'Ø˜C‘LˆEÙðð
 €}ØØ�K‰K‹M€EÙØà‡}�}„Ü�5‹zÐØ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/
    z:^https?://[^/]+/api/(?:scheduled-jobs|jobs)/[^/]+/([^/?]+)zA^https?://[^/]+/api/(models|datasets|spaces)/([^/]+)(?:/([^/]+))?z)^https?://[^/]+/api/buckets/([^/]+/[^/]+)>	   ÚrawÚblobÚrefsÚtreeÚcommitÚresolveÚrevisionÚsettingsÚdiscussionsÚurlc                 ó  — t         j                  | «      }|syt        j                  j	                  |j                  d«      «      }|j                  d«      |j                  d«      }}|r|t        vr|› d|› �}||fS |}||fS )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")
    ©NNr   r   é   ú/)Ú_REPO_ID_FROM_URL_REGEXr8   r   ÚREPO_TYPES_MAPPINGÚgetr9   Ú_REPO_URL_SUBPATHS)rP   r>   Ú	repo_typeÚfirstÚsecondÚrepo_ids         r-   Ú_parse_repo_info_from_urlr]   Õ   s‹   € ô $×*Ñ*¨3Ó/€EÙØÜ×,Ñ,×0Ñ0°·±¸Q³Ó@€IØ—K‘K “N E§K¡K°£Nˆ6€EÙ�&Ô 2Ñ2Ø�G˜1˜V˜HÐ%ˆð �gÐÐð ˆØ�gÐÐr,   c                 óV   — t         j                  | «      }|r|j                  d«      S dS )z9Extract bucket_id (namespace/name) from a bucket API URL.r   N)Ú_BUCKET_ID_FROM_URL_REGEXr8   r9   ©rP   r>   s     r-   Ú_parse_bucket_id_from_urlra   î   s'   € ä%×,Ñ,¨SÓ1€EÙ"ˆ5�;‰;�q‹>Ð,¨Ð,r,   c                 óV   — t         j                  | «      }|r|j                  d«      S dS )z>Extract the job_id from a (scheduled) job API URL, if present.r   N)Ú_JOB_ID_FROM_URL_REGEXr8   r9   r`   s     r-   Ú_parse_job_id_from_urlrd   ô   s'   € ä"×)Ñ)¨#Ó.€EÙ"ˆ5�;‰;�q‹>Ð,¨Ð,r,   Úrequestc           	      óN  — t        j                  «       rt        d| j                  › d�«      ‚t        | j
                  vrO| j
                  j                  t        «      xs t        t        j                  «       «      | j
                  t        <   | j
                  j                  t        «      }t        j                  d|| j                  | j                  | j
                  j                  d«      du«       t         j                  rt        j                  dt        | «      «       |S )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   rP   ÚX_AMZN_TRACE_IDr.   rW   ÚX_REQUEST_IDr(   ÚuuidÚuuid4ÚloggerÚdebugÚmethodÚHF_DEBUGÚ_curlify)re   Ú
request_ids     r-   Úhf_request_event_hookrs   ú   så   € ô × Ñ Ô"Ü"Ø˜GŸK™K˜=ð  )Jð  Kó
ð 	
ô
 ˜gŸo™oÑ-Ø+2¯?©?×+>Ñ+>¼|Ó+LÒ+aÔPSÔTX×T^ÑT^ÓT`ÓPaˆ�‰œÑ(Ø—‘×$Ñ$¤_Ó5€Jô ‡L�LØ/ØØ�‰Ø�‰Ø�‰×Ñ˜OÓ,°DÐ8ôô ×ÒÜ�‰�Z¤¨'Ó!2Ô3àÐr,   c              ƒ   ó    K  — t        | «      S ­w)z3
    Async version of `hf_request_event_hook`.
    )rs   )re   s    r-   Úasync_hf_request_event_hookru     s   è ø€ ô ! Ó)Ð)ùs   ‚Úresponsec              ƒ   óÚ   K  — | j                   dk\  rGd| j                  v r8	 t        | j                  d   «      }|dk  r| j	                  «       ƒ d {  –—†  y y y y # t        $ r Y y w xY w7 Œ­w)Né�  zContent-lengthi@B )Ústatus_coder.   r*   Ú
ValueErrorÚaread)rv   Úlengths     r-   Úasync_hf_response_event_hookr}   "  s�   è ø€ Ø×Ñ˜sÒ"ð ˜x×/Ñ/Ñ/ðÜ˜X×-Ñ-Ð.>Ñ?Ó@�ð ˜	Ò!Ø—n‘nÓ&×&Ñ&ð "ð 0ð #øô ò Ùðúð 'ús3   ‚A+¡A ¹A+ÁA)ÁA+Á	A&Á#A+Á%A&Á&A+c                  ó@   — t        j                  dt        gidd¬«      S )zQ
    Factory function to create a `httpx.Client` with the default transport.
    re   TN©Úevent_hooksÚfollow_redirectsÚtimeout)ÚhttpxÚClientrs   r+   r,   r-   Údefault_client_factoryr…   0  s'   € ô �<‰<ØÔ!6Ð 7Ð8ØØôð r,   c                  óL   — t        j                  t        gt        gdœdd¬«      S )zV
    Factory function to create a `httpx.AsyncClient` with the default transport.
    )re   rv   TNr   )rƒ   ÚAsyncClientru   r}   r+   r,   r-   Údefault_async_client_factoryrˆ   ;  s,   € ô ×ÑÜ!<Ð =ÔLhÐKiÑjØØôð r,   Ú_GLOBAL_CLIENT_FACTORYÚ_GLOBAL_ASYNC_CLIENT_FACTORYÚ_GLOBAL_CLIENTÚclient_factoryc                 óR   — t         5  t        «        | addd«       y# 1 sw Y   yxY w)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_sessionr‰   )rŒ   s    r-   Úset_client_factoryr�   O  s'   € ô 
ñ 0ÜŒØ!/Ð÷0÷ 0ñ 0ús   ‡�&Úasync_client_factoryc                 ó   — | a y)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`.

    > [!WARNING]
    > 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.
    N©rŠ   )r‘   s    r-   Úset_async_client_factoryr”   `  s
   € ð $8Ñ r,   c                  óz   — t         €t        5  t        «       a ddd«       t         S t         S # 1 sw Y   t         S xY w)a  
    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)r‹   rŽ   r‰   r+   r,   r-   Úget_sessionr–   p  s6   € ô ÐÜñ 	6Ü3Ó5ˆN÷	6äÐŒ>Ð÷	6äÐús   �,¬:c                  ó   — t        «       S )a»  
    Return a `httpx.AsyncClient` object, using the transport factory from the user.

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

    > [!WARNING]
    > 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.
    r“   r+   r,   r-   Úget_async_sessionr˜     s   € ô (Ó)Ð)r,   c                  ó˜   — t         } da | �	 | j                  «        yy# t        $ r"}t        j	                  d|› �«       Y d}~yd}~ww xY w)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Ú	Exceptionrm   Úwarning)ÚclientÚes     r-   r�   r�   Œ  sT   € ô €Fð €Nð Ðð	9Ø�L‰L�Nð øô ò 	9Ü�N‰NÐ3°A°3Ð7×8Ñ8ûð	9ús   Œ ž	A	§AÁA	Úregister_at_fork)Úafter_in_child.Ú_DEFAULT_RETRY_ON_EXCEPTIONS)i˜  é­  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Ústreamro   r¦   r§   r¨   r©   rª   r«   c          	   +   óê  ‡ ‡‡‡‡‡K  — t        |t        «      r|f}t        ‰t        «      r‰fŠdŠ|}	dŠd}
d|v r6t        |d   t        j                  t
        f«      r|d   j                  «       }
t        «       }	 ‰dz  ŠdŠ	 |
�|d   j                  |
«       dt        j                  dt        fˆˆ ˆˆˆˆfd„}|r6 |j                  d‰ ‰dœ|¤Ž5 } ||«      s|–— 	 ddd«       y	 ddd«       n" |j                  d‰ ‰dœ|¤Ž} ||«      s|–— y‰�.t%        ‰«      dz   }t        j                  d|› d‰› d‰› d�«       n!|	}t        j                  d|› d‰› d‰› d�«       t'        j(                  |«       t+        ||	dz  «      }	�Œ# 1 sw Y   Œ€xY w# |$ rS}t        j                  d	|› d
‰ › d‰› �«       t        |t        j                   «      r
t#        «        ‰‰kD  r|‚Y d}~ŒÖd}~ww xY w­w)zfInternal implementation of HTTP backoff logic shared between `http_backoff` and `http_stream_backoff`.r   NÚdatar   rv   r/   c                 ó.  •— | j                   ‰vryt        j                  d| j                   › d‰› d‰› �«       ‰‰kD  rt        | «       y| j                   dk(  r$t	        | j
                  «      x}�|j                  Šyt        | j
                  «      x}�|Šy)zNHandle response and return True if should retry, False if should return/yield.FzHTTP Error z thrown while requesting ú r¢   T)ry   rm   rœ   Úhf_raise_for_statusr@   r.   r!   rE   )	rv   Úratelimit_infoÚretry_afterr¦   ro   Únb_triesÚratelimit_resetrª   rP   s	      €€€€€€r-   Ú_should_retryz)_http_backoff_base.<locals>._should_retryØ  s°   ø€ ð ×'Ñ'Ð/DÑDØ ô —‘ ¨X×-AÑ-AÐ,BÐB[Ð\bÐ[cÐcdÐehÐdiÐjÔkØ˜kÒ)Ü'¨Ô1ð !ð ×(Ñ(¨CÒ/Ü+BÀ8×CSÑCSÓ+TÐT˜Ðaà&4×&EÑ&E�Oð ô &8¸×8HÑ8HÓ%IÐI�kÐVØ&1�Oàr,   ©ro   rP   ú'z' thrown while requesting r¯   zRate limited. Waiting zs before retry [Retry rT   z].zRetrying in z	s [Retry r   r+   )Ú
isinstanceÚtyper*   ÚioÚIOBaser   Útellr–   Úseekrƒ   ÚResponseÚboolr«   re   rm   rœ   ÚConnectErrorr�   ÚfloatÚtimeÚsleepÚmin)ro   rP   r¦   r§   r¨   r©   rª   r«   ÚkwargsÚ
sleep_timeÚio_obj_initial_posr�   rµ   rv   ÚerrÚactual_sleepr³   r´   s   ```   `         @@r-   Ú_http_backoff_baserÊ   ¯  s2  ýè ø€ ô Ð%¤tÔ,Ø2Ð4ÐäÐ'¬Ô-Ø!6Ð 8Ðà€HØ€JØ"&€Oð
 ÐØ�ÑœJ v¨f¡~¼¿	¹	Ä<Ð7PÔQØ# F™^×0Ñ0Ó2Ðä‹]€FØ
Ø�A‰ˆØˆð3	ð "Ð-Ø�v‘×#Ñ#Ð$6Ô7ð¬¯©ð ¼4÷ ò ñ4 Ø"�V—]‘]ÐD¨&°cÑD¸VÑDð ÈÙ(¨Ô2Ø&šØ÷ð Ø2÷ð ð
 *˜6Ÿ>™>ÐK°¸SÑKÀFÑK�Ù$ XÔ.Ø"’NØð Ð&Ü  Ó1°AÑ5ˆLÜ�N‰NÐ3°L°>ÐAWÐX`ÐWaÐabÐcnÐboÐoqÐrÕsà%ˆLÜ�N‰N˜\¨,¨°yÀÀ
È!ÈKÈ=ÐXZÐ[Ô\ä�
‰
�<Ô ô ˜¨
°Q©Ó7ˆ
ñE ÷Jð ûð #ò 	Ü�N‰N˜Q˜s˜eÐ#=¸f¸XÀQÀsÀeÐLÔMä˜#œu×1Ñ1Ô2Ü”à˜+Ò%Ø�	ô &ûð	üsW   ˆA;G3ÂAF ÃFÃ F Ã(G3Ã**F ÄA8G3ÆFÆF ÆG0ÆA	G+Ç&G3Ç+G0Ç0G3)r¦   r§   r¨   r©   rª   c                ó<   — t        t        d| ||||||ddœ|¤Ž«      S )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. Set to `0` to disable 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`, `httpx.NetworkError` and `httpx.RemoteProtocolError`.
        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©ro   rP   r¦   r§   r¨   r©   rª   r«   r+   )ÚnextrÊ   ©ro   rP   r¦   r§   r¨   r©   rª   rÅ   s           r-   Úhttp_backoffrÏ     sA   € ôB Üð 
	
ØØØ#Ø)Ø'Ø 3Ø"7Øñ
	
ð ñ
	
óð r,   c             +   óH   K  — t        d| ||||||ddœ|¤ŽE d{  –—†  y7 Œ­w)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. Set to `0` to disable 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`, `httpx.NetworkError` and `httpx.RemoteProtocolError`.
        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()
    ```

    > [!WARNING]
    > 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).
    TrÌ   Nr+   )rÊ   rÎ   s           r-   Úhttp_stream_backoffrÑ   c  sB   è ø€ ôF "ð 
ØØØØ%Ø#Ø/Ø3Øñ
ð ñ
÷ 
ò 
ús   ‚"š ›")Úretry_on_errorsrÒ   c                óD  — |ri ndddœ}	 t        d| |dœ|¤ddi¤|¤Ž}t        |«       d|j                  cxk  rdk  r`n 	 |S t        |j                  d   «      }|j
                  d	k(  r4t        |«      j                  |j                  ¬
«      j                  «       }Œ•	 |S )aF  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¶   r�   Fi,  i�  ÚLocationÚ )Úpath)	rÏ   r°   ry   r   r.   ÚnetlocÚ_replacerÖ   Úgeturl)ro   rP   rÒ   Úhttpx_kwargsÚno_retry_kwargsrv   Úparsed_targets          r-   Ú-_httpx_follow_relative_redirects_with_backoffrÝ   ³  sÏ   € ñ0 ‰¸2ÐXZÑ#[ð ð Üð 
ØØñ
ð ñ
ð #ñ	
ð
 ñ
ˆô 	˜HÔ%ð �(×&Ñ&Ô-¨#Ô-ð 	à€Oô % X×%5Ñ%5°jÑ%AÓBˆMØ×#Ñ# rÒ)ä˜s“m×,Ñ,°-×2DÑ2DÐ,ÓE×LÑLÓN�Øð 	à€Or,   Úendpointc                 ó  — |r|j                  d«      nt        j                  }|t        j                  t        j                  fvr@| j                  t        j                  |«      } | j                  t        j                  |«      } | S )z¤Replace 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.
    rT   )Úrstripr   ÚENDPOINTÚ_HF_DEFAULT_ENDPOINTÚ_HF_DEFAULT_STAGING_ENDPOINTÚreplace)rP   rÞ   s     r-   Úfix_hf_endpoint_in_urlrå   æ  sf   € ñ
 (0ˆx�‰˜sÔ#´Y×5GÑ5G€Hàœ	×6Ñ6¼	×8^Ñ8^Ð_Ñ_Ø�k‰kœ)×8Ñ8¸(ÓCˆØ�k‰kœ)×@Ñ@À(ÓKˆØ€Jr,   Úendpoint_namec           	      óÈ	  — 	 t        | «       	 | j	                  «        y# t        $ r t        j                  dd¬«       Y Œ4w xY w# t
        j                  $ �rˆ}| j                  dz  dk(  rY d}~y| j                  j                  d«      }| j                  j                  d«      }| j                  �5| j                  j                  �t        | j                  j                  «      nd}|rt        |«      nd	\  }}|d
k(  r8| j                  › d�dz   d| j                  › d�z   }t        t        || ||¬«      |‚|dk(  r8| j                  › d�dz   d| j                  › d�z   }t        t         || ||¬«      |‚|dk(  r8| j                  › d�dz   d| j                  › d�z   }t        t"        || ||¬«      |‚|dk(  r;| j                  › d�dz   d| j                  › d�z   dz   dz   }t        t$        || «      |‚|dk(  r]|�[t&        j)                  |«      �F| j                  › d�dz   d| j                  › d�z   dz   dz   }t        t*        || t-        |«      ¬«      |‚| j                  dk(  rI|�Gt/        |«      x}	�:| j                  › d�dz   d| j                  › d�z   dz   }t        t0        || |	¬«      |‚|dk(  s+| j                  d k(  rZ|d!k7  rU|�St2        j)                  |«      �>| j                  › d�dz   d"| j                  › d�z   d#z   d$z   }t        t4        || ||¬«      |‚| j                  d%k(  r|�d&|› d'�nd(}t        t6        || «      |‚| j                  d)k(  r9d| j                  › d*|› d�d+| j                  › d�z   d,z   }t        t8        || «      |‚| j                  d-k(  r»t;        | j                  «      }
|
�‚d.|
j<                  › d/�}|d0|
j>                  › d1�z  }|
j@                  �:|
jB                  �.|d2|
jD                  › d3|
j@                  › d4|
jB                  › d5�z  }n|dz  }|d6| j                  › d�z  }nd7| j                  › d�}t        t8        || «      |‚| j                  d8k(  r[| j                  j                  j                  d9«      }|› d:|› d;| j                  j                  d<«      › d�}t        t8        || «      |‚t        t8        t        |«      | «      |‚d}~ww xY w)=aÔ  
    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_infoéd   rS   NzX-Error-CodeúX-Error-MessagerR   ÚRevisionNotFoundz Client Error.ú

zRevision Not Found for url: ú.)rY   r\   Ú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Job Not Found for url: zA
Please make sure you specified the correct job ID and namespace.)Újob_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/authenticationrx   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ú (rT   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›   rm   rn   Úraise_for_statusrƒ   ÚHTTPStatusErrorry   r.   rW   re   rP   r(   r]   Ú_formatr   r   r   r   ÚBUCKET_API_REGEXr8   r   ra   rd   r   ÚREPO_API_REGEXr   r   r   r@   r   r!   r"   r#   r    )rv   ræ   rž   Ú
error_codeÚerror_messageÚrequest_urlrY   r\   Úmessageró   r±   Úrange_headers               r-   r°   r°   ó  s  € ðBGÜ  Ô*ð
B?Ø×!Ñ!Õ#øô ò Gä�‰Ð6ÀˆÖFðGûô × Ñ ó @?Ø×Ñ 3Ñ&¨!Ò+Üà×%Ñ%×)Ñ)¨.Ó9ˆ
Ø ×(Ñ(×,Ñ,Ð->Ó?ˆð *2×)9Ñ)9Ð)EÈ(×JZÑJZ×J^ÑJ^ÐJjŒC�× Ñ ×$Ñ$Ô%Ðptð 	ñ HSÔ6°{ÔCÐXdÑˆ	�7àÐ+Ò+Ø!×-Ñ-Ð.¨nÐ=ÀÑFÐKgÐhp×htÑhtÐguÐuvÐIwÑwˆGÜÔ/°¸(ÈiÐahÔiÐopÐpà˜?Ò*Ø!×-Ñ-Ð.¨nÐ=ÀÑFÐKdÐem×eqÑeqÐdrÐrsÐItÑtˆGÜÔ2°G¸XÐQZÐdkÔlÐrsÐsà˜;Ò&à×'Ñ'Ð(¨Ð7¸&Ñ@ÐEfÐgo×gsÑgsÐftÐtuÐCvÑvð ô œ.¨'°8ÀyÐZaÔbÐhiÐiàÐDÒDà×'Ñ'Ð(¨Ð7Øñà5°h·l±l°^À1ÐEñFð ñð 9ñ	9ð ô Ô+¨W°hÓ?ÀQÐFð ˜.Ò(ØÐ'Ü ×'Ñ'¨Ó4Ð@ð ×'Ñ'Ð(¨Ð7Øñà.¨x¯|©|¨n¸AÐ>ñ?ð ]ñ]ð }ñ	}ð ô Ü# W¨hÔB[Ð\gÓBhôàðð
 × Ñ  CÒ'ØÐ'Ü1°+Ó>Ð>�ÐKð ×'Ñ'Ð(¨Ð7Øñà+¨H¯L©L¨>¸Ð;ñ<ð WñWð ô Ô*¨G°XÀfÔMÐSTÐTà˜>Ò)Ø× Ñ  CÒ'ØÐ!NÒNØÐ'Ü×%Ñ% kÓ2Ð>ð ×'Ñ'Ð(¨Ð7Øñà2°8·<±<°.ÀÐBñCð`ñ`ð gñgð ô Ô1°7¸HÐPYÐcjÔkÐqrÐrà×!Ñ! SÒ(àDQÐD]Ð& } o°ZÑ@Ðcuð ô œ/¨7°HÓ=À1ÐDà×!Ñ! SÒ(à�x×+Ñ+Ð,¨L¸¸ÀqÐIØ0°·±°¸aÐ@ñAàGñHð ô
 œ.¨'°8Ó<À!ÐCà×!Ñ! SÒ(Ü4°X×5EÑ5EÓFˆNØÐ)àHÈ×IeÑIeÐHfÐfsÐtð ð ˜^¨N×,KÑ,KÐ+LÈHÐUÑU�Ø!×'Ñ'Ð3¸×8UÑ8UÐ8aØØ˜^×5Ñ5Ð6°a¸×8LÑ8LÐ7Mð N'Ø'5×'DÑ'DÐ&EÀZðQñ‘Gð
 ˜s‘N�GØ˜W X§\¡\ N°!Ð4Ñ4‘à?ÀÇÁ¸~ÈQÐO�Üœ.¨'°8Ó<À!ÐCà×!Ñ! SÒ(Ø#×+Ñ+×3Ñ3×7Ñ7¸Ó@ˆLØ˜Ð.¨|¨nÐ<MÈh×N^ÑN^×NbÑNbÐcrÓNsÐMtÐtuÐvˆGÜœ.¨'°8Ó<À!ÐCô ”n¤c¨!£f¨hÓ7¸QÐ>ûðA@?ús-   ‚ ŽA Ÿ AÁAÁS!ÁSÁ0Q,SÓS!c                 ó.  — | j                   j                  d«      }|D ]u  }d|v r|j                  dd«      nd|f\  }}|j                  «       }|t        vsŒ9|j                  «       }|sŒLt        j                  |«       t        j                  |«       Œw y)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)r.   Úget_listÚsplitrB   Ú_WARNED_TOPICSÚaddrm   rœ   )rv   Úserver_warningsÚserver_warningÚtopicrÿ   s        r-   rö   rö   ¢  sŠ   € ð ×&Ñ&×/Ñ/°Ó?€OØ)ò (ˆØ9<ÀÑ9N˜×-Ñ-¨c°1Ô5ÐUWÐYgÐTh‰ˆˆwØ—‘“ˆØœÒ&Ø—m‘m“oˆGÚÜ×"Ñ" 5Ô)Ü—‘˜wÕ'ñ(r,   Ú_HfHubHTTPErrorT)ÚboundÚ
error_typeÚcustom_messageÚattrsc                 ó�  — g }|j                   j                  d«      }|�|j                  |«       	 	 |j                  «       }|j                  d«      }|j                  d«      }|�Mt        |t        «      r|j                  |«       n>|�|j                  |› d|› �«       n%|j                  |«       n|�|j                  |«       |j                  d«      }	|	� |	D ]  }d|v sŒ|j                  |d   «       Œ |D �cg c]5  }t        |«      j                  «       sŒt        |«      j                  «       ‘Œ7 }}t        t         j#                  |«      «      }d
j%                  |«      }|}|r5|j                  «       |j                  «       vrd|v r	|d
|z   z  }n|d|z   z  }d}d}t&        dft(        dft*        dffD ]8  \  }}|j                   j                  |«      }|sŒ$t        |«      }d|› d|› d�} n |rI|j                  «       |j                  «       vr)d
|v r |j-                  d
«      }|d | |z   ||d  z   }n||z  } | |j                  «       ||xs d ¬«      }|j/                  «       D ]  \  }}t1        |||«       Œ |S # t        j
                  $ r7 	 |j                  «        |j                  «       }n# t        $ r i }Y nw xY wY �Œ�w xY w# t        j                  $ rY |j                   j                  dd«      }
|j                  r-d	|
j                  «       vr|j                  |j                  «       Y �ŒEw xY wc c}w )Nrê   ÚerrorÚerror_descriptionú: Úerrorsrÿ   zContent-TyperÕ   Úhtmlrð   rì   z
Request IDzAmzn Trace IDz	Amz CF IDrô   ú))rv   Úserver_message)r.   rW   ÚappendÚjsonrƒ   ÚResponseNotReadÚreadÚRuntimeErrorr¸   ÚlistÚextendÚJSONDecodeErrorÚtextr6   r(   rB   ÚdictÚfromkeysÚjoinrj   ri   ÚX_AMZ_CF_IDÚindexÚitemsÚsetattr)r  r  rv   r  Úserver_errorsÚfrom_headersr­   r  r  r  Úcontent_typeÚliner  Úfinal_error_messagerr   Úrequest_id_messageÚheaderÚlabelrD   Únewline_indexrÈ   ÚkÚvs                          r-   rù   rù   ½  s|  € ð €Mð ×#Ñ#×'Ñ'Ð(9Ó:€LØÐØ×Ñ˜\Ô*ð+0ð	Ø—=‘=“?ˆDð —‘˜Ó!ˆØ ŸH™HÐ%8Ó9ÐØÐÜ˜%¤Ô&à×$Ñ$ UÕ+Ø"Ð.à×$Ñ$¨ w¨bÐ1BÐ0CÐ%DÕEð ×$Ñ$ UÕ+ØÐ*à× Ñ Ð!2Ô3à—‘˜(Ó#ˆØÐàò ;�Ø Ò%Ø!×(Ñ(¨¨yÑ)9Õ:ð;ð 4AÖV¨4ÄCÈÃIÇOÁOÕDU”S˜“Y—_‘_Õ&ÐV€MÐVô œŸ™ }Ó5Ó6€Mð —Y‘Y˜}Ó-€Nð )ÐÙ˜.×.Ñ.Ó0¸×8LÑ8LÓ8NÑNØ�^Ñ#Ø 4¨.Ñ#8Ñ8Ñà 6¨NÑ#:Ñ:Ðð €JØÐä	�|Ð$Ü	˜/Ð*Ü	�kÐ"ðò 	‰ˆ�ð
 × Ñ ×$Ñ$ VÓ,ˆÚÜ˜U›ˆJØ#% e W¨B¨u¨g°QÐ!7ÐÙð	ñ �j×&Ñ&Ó(Ð0C×0IÑ0IÓ0KÑKØÐ&Ñ&Ø/×5Ñ5°dÓ;ˆMà# N ]Ð3Ð6HÑHÐK^Ð_lÐ_mÐKnÑnñ  ð  Ð#5Ñ5Ðñ Ð(×.Ñ.Ó0¸8ÐTbÒTjÐfjÔ
k€CØ—‘“ò ‰ˆˆ1Ü��Q˜Õðà€Jøôo ×$Ñ$ò 
	ð	Ø—‘”Ø—}‘}“‘øÜò ð ’ðýð	
	ûôF ×Ñò 0à×'Ñ'×+Ñ+¨N¸BÓ?ˆØ�=Š=˜V¨<×+=Ñ+=Ó+?Ñ?Ø× Ñ  §¡Ô/úð	0üò Wsg   ³J ÁB K Ã$K Ã>MÄMÊKÊ J<Ê;KÊ<K
ËKË	K
Ë
KËK ËKËK ËA(M Ì?M )Úsubject_tokenÚaccess_tokenÚrefresh_tokenÚclient_secretÚdevice_codez("z"\s*:\s*")[^"]*(")z\1<REDACTED>\2z(^|&)(z=)[^&]*z\1\2<REDACTED>Úbodyc                 óF   — t         D ]  \  }}|j                  || «      } Œ | S )zRRedact OAuth credential values from a JSON or form-urlencoded request body string.)Ú_SENSITIVE_BODY_PATTERNSÚsub)r7  ÚpatternÚreplacements      r-   Ú_redact_sensitive_bodyr=  2  s+   € ä 8ò .Ñˆ�Ø�{‰{˜;¨Ó-‰ð.à€Kr,   c                 ó´  — dd| j                   fg}t        | j                  j                  «       «      D ]'  \  }}|j	                  «       dk(  rd}|d|› d|› �fgz  }Œ) d}	 | j
                  �>| j
                  j                  dd	¬
«      }t        |«      dkD  r|dd › d�}t        |«      }|�|d|j                  dd«      fgz  }|d| j                  fgz  }g }|D ]P  \  }}|r#|j                  t        t        |«      «      «       |sŒ.|j                  t        t        |«      «      «       ŒR dj!                  |«      S # t        j                  $ r d}Y Œ«w xY w)zÞConvert 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¯   )ro   Úsortedr.   r%  r6   ÚcontentÚdecodeÚlenr=  rƒ   ÚRequestNotReadrä   rP   r  r   r(   r"  )re   Úpartsr0  r1  r7  Ú
flat_partss         r-   rq   rq   9  sz  € ð 	Ø	ˆw�~‰~Ðð$€Eô
 �w—‘×,Ñ,Ó.Ó/ò '‰ˆˆ1Ø�7‰7‹9˜Ò'ØˆAØ�4˜A˜3˜b  ˜Ð%Ð&Ñ&‰ð'ð
 €Dð"Ø�?‰?Ð&Ø—?‘?×)Ñ)¨'¸(Ð)ÓCˆDÜ�4‹y˜4ÒØ˜u ˜+˜Ð&6Ð7�Ü)¨$Ó/ˆDð ÐØ�4˜Ÿ™ d¨BÓ/Ð0Ð1Ñ1ˆà	ˆt�W—[‘[Ð!Ð"Ñ"€Eà€JØò -‰ˆˆ1ÙØ×Ñœe¤C¨£F›mÔ,ÚØ×Ñœe¤C¨£F›mÕ,ð	-ð �8‰8�JÓÐøô ×Ñò "Ø!Šð"ús   Á!A
D? Ä?EÅEz%^\s*bytes\s*=\s*(\d*)\s*-\s*(\d*)\s*$Úoriginal_rangeÚresume_sizec                 ó¤  — | sd|› d�S d| v rt        d| ›d�«      ‚t        j                  | «      }|st        d| ›d�«      ‚|j	                  «       \  }}|s:|st        d| ›d�«      ‚t        |«      |z
  }d|› �}|d	k  rt        d
|›d�«      ‚|S t        |«      }||z   }|r)t        |«      }d|› d|› �}||kD  rt        d
|›d�«      ‚|S d|› d�S )zB
    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 - )rz   ÚRANGE_REGEXr>   r  Úgroupsr*   )rH  rI  r>   ÚstartÚendÚ
new_suffixÚ	new_rangeÚ	new_starts           r-   Ú_adjust_range_headerrT  g  s'  € ñ Ø˜�} AÐ&Ð&à
ˆnÑÜÐ6°~Ð6HÐH\Ð]Ó^Ð^ä×Ñ˜nÓ-€EÙÜÐ4°^Ð4FÀaÐHÓIÐIØ—‘“�J€Eˆ3áÙÜÐ!8¸Ð8JÈ!ÐLÓMÐMä˜“X Ñ+ˆ
Ø˜j˜\Ð*ˆ	Ø˜Š?ÜÐ!3°I°=ÀÐBÓCÐCØÐä�‹J€EØ˜Ñ#€IÙ
Ü�#‹hˆØ˜Y˜K q¨¨Ð.ˆ	Ø�sŠ?ÜÐ!3°I°=ÀÐBÓCÐCØÐà�I�;˜aÐ Ð r,   )r/   N)N)yr'   Úatexitrº   r  ÚosÚreÚ	threadingrÂ   rk   Úcollections.abcr   r   r   Ú
contextlibr   Údataclassesr   Úshlexr   Útypingr	   r
   Úurllib.parser   rƒ   Úhuggingface_hub.errorsr   rÕ   r   r  r   r   r   r   r   r   r   r   r   r   Ú_lfsr   Ú_typingr   Ú
get_loggerr$   rm   r   Úcompiler7   r:   r(   r@   r*   rE   rj   ri   r#  ÚVERBOSErû   rú   rc   rU   r_   rX   Útupler]   ra   rd   ÚRequestrs   ru   r¾   r}   r„   r…   r‡   rˆ   ÚCLIENT_FACTORY_TÚASYNC_CLIENT_FACTORY_TÚLockrŽ   r‰   r)   rŠ   r‹   r�   r”   r–   r˜   r�   ÚregisterÚhasattrrŸ   ÚTimeoutExceptionÚNetworkErrorÚRemoteProtocolErrorr¡   r¹   r›   r£   rÁ   r¿   rÊ   rÏ   rÑ   rÝ   rå   r°   Úsetr  rö   r
  rù   Ú_SENSITIVE_BODY_KEYSr9  r=  rq   Ú
IGNORECASErM  rT  )r<   r;  s   00r-   ú<module>rr     s.  ðò Eã Û 	Û Û 	Û 	Û Û Û ß 8Ñ 8Ý %Ý !Ý ß Ý !ã å 7å ÷
÷ 
õ 
õ Ý Ý "ð 
ˆ×	Ñ	˜HÓ	%€ñ �$Ô÷&ð &ó ð&ð, �2—:‘:ÐmÓnÐ à$˜"Ÿ*™*Ð%OÓPÐ ð8 W¨S°#¨XÑ%6ð 8¸=È4Ñ;Oó 8ðv ¨¨S¨Ñ 1ð °c¸D±jó ð6 €Ø#€Ø€à�—‘ð
ð �*‰*ô€ð �2—:‘:ðð �*‰*ôÐ ð $˜Ÿ™Ð$aÓbÐ ð %˜"Ÿ*™*Ð%iÓjÐ ð '˜BŸJ™JÐ'SÓTÐ ò qÐ ð 3ð ¨5°°t±¸SÀ4¹ZÐ1GÑ+Hó ð2- 3ð -¨3°©:ó -ð- ð -¨¨d©
ó -ð 5§=¡=ð °Tó ðB*¨u¯}©}ð *Àó *ð'°·±ð 'ÀDó 'ð §¡ó ð e×&7Ñ&7ó ð ˜B §¡Ð,Ñ-Ð Ø! " e×&7Ñ&7Ð"7Ñ8Ð àˆy�~‰~Ó€Ø+AÐ Ð(Ó AØ7SÐ Ð4Ó SØ&*€�—‘˜tÑ#Ó *ð0Ð'7ð 0¸Dó 0ð"8Ð3Ið 8Èdó 8ð �U—\‘\ó ð
*˜5×,Ñ,ó 
*ó9ð, €‡��Ô Ù
ˆ2Ð!Ô"Ø€B×Ñ }Õ5ð 
×ÑØ	×ÑØ	×Ñð=Ð ˜e D¨¡O°SÐ$8Ñ9ó ð
 3QÐ   c¨3 h¡Ó Pð ØØØIeØ3QØòa8Øða8à	ða8ð ð	a8ð
 ða8ð ða8ð ˜i™¨5°°i±À#Ð1EÑ+FÑFða8ð   s¨C x¡Ñ0ða8ð ða8ð ˆu�~‰~˜t TÐ)Ñ*óa8ðP ØØØIeØ3QòMØðMà	ðMð ð	Mð
 ðMð ðMð ˜i™¨5°°i±À#Ð1EÑ+FÑFðMð   s¨C x¡Ñ0ðMð ‡^�^óMð` ð
 ØØØIeØ3QòLØðLà	ðLð ð	Lð
 ðLð ðLð ˜i™¨5°°i±À#Ð1EÑ+FÑFðLð   s¨C x¡Ñ0ðLð ˆu�~‰~˜t TÐ)Ñ*òLó ðLð` AFò0Øð0Ø #ð0Ø9=ð0à
‡^�^ó0ðf
 ð 
¨s°T©zð 
¸có 
ñi? %§.¡.ð i?ÀÀtÁð i?ÐW[ó i?ñX “€ð( u§~¡~ð (¸$ó (ñ0 Ð-°^ÔDÐ ðfØÐ%Ñ&ðfØ8;ðfØGLÇ~Á~ðfØ`cðfàófðT jÐ ð $÷àà	ˆ�‰�r˜#˜Ð0Ð1Ó	2Ð4EÐFØ	ˆ�‰�v˜c˜U 'Ð*Ó	+Ð->Ð?ðòð 	ò ðØóÐ ð ð ¨ó ð' �e—m‘mð ' ¨ó ' ðV ˆb�j‰jÐAÀ2Ç=Á=ÓQ€ð"!¨¨t©ð "!À#ð "!È#ÐPTÉ*ô "!ùós   Ð(>R2