Ë
    /æjoÀ  ã                   ó–
  — 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 ddlmZ dd	lmZmZ dd
lmZ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/m0Z0m1Z1  e,jd                  e3«      Z4 ed¬«       G d„ d«      «       Z5 ejl                  d«      Z7 ejl                  d«      Z8dee9e9f   de5dz  fd„Z:dee9e9f   de;dz  fd„Z<dZ=dZ>dZ? ejl                  d ej€                  ¬!«      ZA ejl                  d"ej€                  ¬!«      ZB ejl                  d#«      ZC ejl                  d$«      ZD ejl                  d%«      ZE ejl                  d&«      ZFh d'£ZGd(e9deHe9dz  e9dz  f   fd)„ZId(e9de9dz  fd*„ZJd(e9de9dz  fd+„ZK ed,d-¬.«      ZLeeM   eNd,<   d/e1de1fd0„ZOd1ej                   de9dz  fd2„ZQd1ej                   de9dz  fd3„ZRd4ej¦                  ddfd5„ZTdejª                  fd6„ZVdej®                  fd7„ZXe
g ejª                  f   ZYe
g ej®                  f   ZZ ej¶                  «       Z\eVa]eYeNd8<   eXa^eZeNd9<   da_ejª                  dz  eNd:<   d;eYddfd<„Z`d=eZddfd>„Zadejª                  fd?„Zbdej®                  fd@„Zcd{dA„Zd ejÊ                  ed«        efedB«      r ejÎ                  ed¬C«       ejÐ                  ejÒ                  ejÔ                  fZkeHelem   dDf   eNdE<   dFZneHe;dDf   eNdG<   dHddIekend-dJœdKe0d(e9dLe;dMeodNeodOelem   eHelem   dDf   z  dPe;eHe;dDf   z  dQeMdeej¦                  ddf   fdR„ZpdHddIekendSœdKe0d(e9dLe;dMeodNeodOelem   eHelem   dDf   z  dPe;eHe;dDf   z  dej¦                  fdT„ZqedHddIekendSœdKe0d(e9dLe;dMeodNeodOelem   eHelem   dDf   z  dPe;eHe;dDf   z  deej¦                  ddf   fdU„«       ZrdVZsd-dWœdKe0d(e9dXeMdej¦                  fdY„ZtdZd[d\œZud(e9deHe9e9e;f   fd]„Zv ewd^„ e!jð                  e!jò                  e!jô                  d_fD «       «      Z{d(e9d`e9deMfda„Z|d(e9dbe9dz  de9fdc„Z}d|d4ej¦                  dde9dz  ddfde„Z~ e«       Z€d4ej¦                  ddfdf„Z� edge'¬h«      Z‚diele‚   dje9d4ej¦                  dkede‚f
dl„ZƒdmZ„e„D � �cg c]9  }  ejl                  dn| › do�«      dpf ejl                  dq| › dr�«      dsffD ]  }|‘Œ Œ; c}} Z…dte9de9fdu„Z†d1ej                   de9fdv„Z‡ ejl                  dwe�j                  «      Z‰dxe9dz  dye;de9dz  fdz„ZŠyc c}} w )}z>Contains utilities to handle HTTP requests in huggingface_hub.é    N)ÚCallableÚ	GeneratorÚMapping)Úcontextmanager)Ú
ContextVar)Ú	dataclass©Úwraps)Úquote)ÚAnyÚTypeVar)ÚurljoinÚurlparse)ÚOfflineModeIsEnabledé   )Ú	constants)	ÚBadRequestErrorÚBucketNotFoundErrorÚDisabledRepoErrorÚGatedRepoErrorÚHfHubHTTPErrorÚJobNotFoundErrorÚRemoteEntryNotFoundErrorÚRepositoryNotFoundErrorÚRevisionNotFoundErroré   )Úlogging)ÚSliceFileObj)ÚHTTP_METHOD_TÚ	CallableTT)Ú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(   © ó    ú^/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/huggingface_hub/utils/_http.pyr#   r#   9   s6   … ñ
ð ÓØƒNØÓØ€Eˆ3�‰:ÓØ!%€N�C˜$‘JÔ%r1   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#   )r3   r6   ÚpolicyÚkeyÚ	lower_keyÚmatchr$   r%   r&   r'   r(   Úpolicy_matchs               r2   Úparse_ratelimit_headersrE   U   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äØ#ØØ)ØØ%ôð r1   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)r;   ÚstripÚisdigitr/   )r3   ÚvaluerA   s      r2   Ú_parse_retry_afterrJ   �   sc   € ð €EØò ˆØ�9‰9‹;˜-Ó'Ø˜C‘LˆEÙðð
 €}ØØ�K‰K‹M€EÙØà‡}�}„Ü�5‹zÐØr1   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)/[^/]+/([^/?]+)zC^https?://[^/]+/api/(models|datasets|spaces)/([^/?]+)(?:/([^/?]+))?zL^https?://[^/]+/(?:(datasets|spaces|kernels)/)?([^/?]+(?:/[^/?]+)?)/resolve/z+^https?://[^/]+/api/buckets/([^/?]+/[^/?]+)>	   ÚrawÚblobÚrefsÚtreeÚcommitÚresolveÚrevisionÚsettingsÚdiscussionsÚurlc                 ó¤  — t         j                  | «      x}r7t        j                  |j	                  d«      xs d   |j	                  d«      fS 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 or a download 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")
        >>> _parse_repo_info_from_url("https://huggingface.co/datasets/user/repo/resolve/main/data.csv")
        ("dataset", "user/repo")
    r   Úmodelsr   ©NNé   ú/)Ú_REPO_ID_FROM_RESOLVE_URL_REGEXr=   r   ÚREPO_TYPES_MAPPINGr>   Ú_REPO_ID_FROM_URL_REGEXÚgetÚ_REPO_URL_SUBPATHS)rU   rC   Ú	repo_typeÚfirstÚsecondÚrepo_ids         r2   Ú_parse_repo_info_from_urlrd   Ý   sÍ   € ô 0×6Ñ6°sÓ;Ð;€uÐ;Ü×+Ñ+¨E¯K©K¸«NÒ,F¸hÑGÈÏÉÐUVËÐWÐWÜ#×*Ñ*¨3Ó/€EÙØÜ×,Ñ,×0Ñ0°·±¸Q³Ó@€IØ—K‘K “N E§K¡K°£Nˆ6€EÙ�&Ô 2Ñ2Ø�G˜1˜V˜HÐ%ˆð �gÐÐð ˆØ�gÐÐr1   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_REGEXr=   r>   ©rU   rC   s     r2   Ú_parse_bucket_id_from_urlrh   ú   s'   € ä%×,Ñ,¨SÓ1€EÙ"ˆ5�;‰;�q‹>Ð,¨Ð,r1   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_REGEXr=   r>   rg   s     r2   Ú_parse_job_id_from_urlrk      s'   € ä"×)Ñ)¨#Ó.€EÙ"ˆ5�;‰;�q‹>Ð,¨Ð,r1   Ú_IS_DOWNLOAD_CALLF)ÚdefaultÚfnc                 ó.   ‡ — t        ‰ «      ˆ fd„«       }|S )a#  Decorator to tag all HTTP calls made by `fn` with the `X-HF-Download-Counter` header.

    Applied on `hf_hub_download`, `snapshot_download`, etc. so that every call they make through [`get_session`]
    is flagged as part of a download, no matter how deep in the call stack it happens.
    c                  óž   •— t         j                  d«      }	  ‰| i |¤Žt         j                  |«       S # t         j                  |«       w xY w)NT)rl   ÚsetÚreset)ÚargsÚkwargsÚtokenrn   s      €r2   Ú_innerz%flag_as_download_call.<locals>._inner  sC   ø€ ä!×%Ñ% dÓ+ˆð	+Ù�tÐ&˜vÑ&ä×#Ñ# EÕ*øÔ×#Ñ# EÕ*ús	   ˜5 µAr	   )rn   rv   s   ` r2   Úflag_as_download_callrw   	  s"   ø€ ô ˆ2ƒYó+ó ð+ð €Mr1   Úrequestc           	      ó°  — t        j                  «       rt        d| j                  › d�«      ‚t        j                  «       rd| j                  t         j                  <   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 )a1  
    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
    - Flag the request as part of a download, if applicable
    - 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.Ú1z%Request %s: %s %s (authenticated: %s)ÚauthorizationNzSend: %s)r   Úis_offline_moder   rU   rl   r^   r3   ÚX_HF_DOWNLOAD_COUNTERÚX_AMZN_TRACE_IDÚX_REQUEST_IDr-   ÚuuidÚuuid4ÚloggerÚdebugÚmethodÚHF_DEBUGÚ_curlify)rx   Ú
request_ids     r2   Úhf_request_event_hookrˆ     s  € ô × Ñ Ô"Ü"Ø˜GŸK™K˜=ð  )Jð  Kó
ð 	
ô ×ÑÔØ;>ˆ�‰œ	×7Ñ7Ñ8ô ˜gŸo™oÑ-Ø+2¯?©?×+>Ñ+>¼|Ó+LÒ+aÔPSÔTX×T^ÑT^ÓT`ÓPaˆ�‰œÑ(Ø—‘×$Ñ$¤_Ó5€Jô ‡L�LØ/ØØ�‰Ø�‰Ø�‰×Ñ˜OÓ,°DÐ8ôô ×ÒÜ�‰�Z¤¨'Ó!2Ô3àÐr1   c              ƒ   ó    K  — t        | «      S ­w)z3
    Async version of `hf_request_event_hook`.
    )rˆ   )rx   s    r2   Úasync_hf_request_event_hookrŠ   @  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_coder3   r/   Ú
ValueErrorÚaread)r‹   Úlengths     r2   Úasync_hf_response_event_hookr’   G  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 )zR
    Factory function to create a `httpx2.Client` with the default transport.
    rx   TN©Úevent_hooksÚfollow_redirectsÚtimeout)Úhttpx2ÚClientrˆ   r0   r1   r2   Údefault_client_factoryrš   U  s'   € ô �=‰=ØÔ!6Ð 7Ð8ØØôð r1   c                  óL   — t        j                  t        gt        gdœdd¬«      S )zW
    Factory function to create a `httpx2.AsyncClient` with the default transport.
    )rx   r‹   TNr”   )r˜   ÚAsyncClientrŠ   r’   r0   r1   r2   Údefault_async_client_factoryr�   `  s,   € ô ×ÑÜ!<Ð =ÔLhÐKiÑjØØôð r1   Ú_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 `httpx2.Client` object. On the first call to [`get_session`] the client factory
    will be used to create a new `httpx2.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 `httpx2.Client`.
    N)Ú_CLIENT_LOCKÚclose_sessionrž   )r¡   s    r2   Úset_client_factoryr¥   t  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 `httpx2.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_session`] to get a correctly configured `httpx2.AsyncClient`.

    > [!WARNING]
    > Contrary to the `httpx2.Client` that is shared between all calls made by `huggingface_hub`, the `httpx2.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    r2   Úset_async_client_factoryr©   …  s
   € ð $8Ñ r1   c                  ó†   — t         €%t        5  t         €
t        «       a ddd«       t         S t         S # 1 sw Y   t         S xY w)a  
    Get a `httpx2.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 `httpx2.Client`.
    N)r    r£   rž   r0   r1   r2   Úget_sessionr«   •  s@   € ô ÐÜñ 	:ÜÐ%Ü!7Ó!9�÷	:ô ÐŒ>Ð÷	:ô Ðús	   �2²A c                  ó   — t        «       S )a¿  
    Return a `httpx2.AsyncClient` object, using the transport factory from the user.

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

    > [!WARNING]
    > Contrary to the `httpx2.Client` that is shared between all calls made by `huggingface_hub`, the `httpx2.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¨   r0   r1   r2   Úget_async_sessionr­   ¥  s   € ô (Ó)Ð)r1   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 `httpx2.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Ú	Exceptionr‚   Úwarning)ÚclientÚes     r2   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é   é   )Úmax_retriesÚbase_wait_timeÚmax_wait_timeÚretry_on_exceptionsÚretry_on_status_codesÚstreamr„   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                  «       }
	 ‰dz  ŠdŠt        «       }	 |
�|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   r‹   r4   c                 óL  •— | j                   ‰vryt        j                  d| j                   › d‰› d‰› �«       ‰‰kD  rt        | «       y| j                   dk(  r3t	        | j
                  «      x}�|j                  dk(  r|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·   r   T)	rŽ   r‚   r±   Úhf_raise_for_statusrE   r3   r%   r&   rJ   )	r‹   Úratelimit_infoÚretry_afterr»   r„   Únb_triesÚratelimit_resetr¿   rU   s	      €€€€€€r2   Ú_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Ø&×0Ñ0°AÒ5à&4×&EÑ&E�Oð ô &8¸×8HÑ8HÓ%IÐI�kÐVØ&1�Oàr1   ©r„   rU   ú'z' thrown while requesting rÄ   zRate limited. Waiting zs before retry [Retry rZ   z].zRetrying in z	s [Retry r   r0   )Ú
isinstanceÚtyper/   ÚioÚIOBaser   Útellr«   Úseekr˜   ÚResponseÚboolrÀ   rx   r‚   r±   ÚConnectErrorr¤   ÚfloatÚtimeÚsleepÚmin)r„   rU   r»   r¼   r½   r¾   r¿   rÀ   rt   Ú
sleep_timeÚio_obj_initial_posr²   rÊ   r‹   ÚerrÚactual_sleeprÈ   rÉ   s   ```   `         @@r2   Ú_http_backoff_baserÞ   Õ  s4  ýè ø€ ô Ð%¤tÔ,Ø2Ð4ÐäÐ'¬Ô-Ø!6Ð 8Ðà€HØ€JØ"&€Oð
 ÐØ�ÑœJ v¨f¡~¼¿	¹	Ä<Ð7PÔQØ# F™^×0Ñ0Ó2Ðà
Ø�A‰ˆØˆô “ˆð4	ð "Ð-Ø�v‘×#Ñ#Ð$6Ô7ð¬¯©ð ¼D÷ ò ñ6 Ø"�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ˆ
ñM ÷Rð ûð #ò 	Ü�N‰N˜Q˜s˜eÐ#=¸f¸XÀQÀsÀeÐLÔMä˜#œv×2Ñ2Ô3Ü”à˜+Ò%Ø�	ô &ûð	ü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 )ae  Wrapper around httpx2 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 `httpx2.TimeoutException`, `httpx2.NetworkError` and `httpx2.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 `httpx2.request`.

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

    # Same usage as "httpx2.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©r„   rU   r»   r¼   r½   r¾   r¿   rÀ   r0   )ÚnextrÞ   ©r„   rU   r»   r¼   r½   r¾   r¿   rt   s           r2   Úhttp_backoffrã   <  sA   € ôB Üð 
	
ØØØ#Ø)Ø'Ø 3Ø"7Øñ
	
ð ñ
	
óð r1   c             +   óH   K  — t        d| ||||||ddœ|¤ŽE d{  –—†  y7 Œ­w)a½  Wrapper around httpx2 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 `httpx2.TimeoutException`, `httpx2.NetworkError` and `httpx2.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 `httpx2.request`.

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

    # Same usage as "httpx2.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 `httpx2` 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à   Nr0   )rÞ   râ   s           r2   Úhttp_stream_backoffrå   Œ  sB   è ø€ ôF "ð 
ØØØØ%Ø#Ø/Ø3Øñ
ð ñ
÷ 
ò 
ús   ‚"š ›"é   )Úretry_on_errorsrç   c                ó0  — |ri ndddœ}t        t        «      D ]\  }t        d| |dœ|¤ddi¤|¤Ž}t        |«       |j                  s|c S t        ||j                  d   «      }t        ||«      s|c S |}Œ^ t        j                  dt        › d|› d	�«      ‚)
aÅ  Perform an HTTP request with backoff, following redirects that stay on the Hub.

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

    Redirects to the same host or another Hub host are followed. Redirects to any other host (CDN, storage
    bucket) are not: the file metadata is on the redirect response itself and the auth header must not leave the Hub.

    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).
        **httpx2_kwargs (`dict`, *optional*):
            Params to pass to `httpx2.request`.
    r0   )r¾   r¿   rË   r–   FÚLocationz	Exceeded z redirects while resolving 'z'.)
ÚrangeÚ_MAX_REDIRECTSrã   rÅ   Úhas_redirect_locationr   r3   Ú_is_same_or_hub_hostr˜   ÚTooManyRedirects)r„   rU   rç   Úhttpx2_kwargsÚno_retry_kwargsÚ_r‹   Útargets           r2   Ú)_httpx2_follow_hub_redirects_with_backoffró   ß  sË   € ñ2 ‰¸2ÐXZÑ#[ð ô ”>Ó"ò ˆÜð 
ØØñ
ð ñ
ð #ñ	
ð
 ñ
ˆô 	˜HÔ%à×-Ò-ØŠOä˜˜h×.Ñ.¨zÑ:Ó;ˆÜ# C¨Ô0ð ŠOà‰ð'ô* ×
!Ñ
! I¬nÐ-=Ð=YÐZ]ÐY^Ð^`Ð"aÓ
bÐbr1   éP   i»  )ÚhttpÚhttpsc                 óÆ   — t        | «      }|j                  |j                  xs dj                  «       |j                  xs  t
        j                  |j                  d«      fS )zZOrigin of a url: (scheme, hostname, port), with the scheme's default port if not explicit.Ú r   )r   ÚschemeÚhostnamer;   ÚportÚ_DEFAULT_PORTSr^   )rU   Úparseds     r2   Ú_url_originrþ     sL   € ä�c‹]€FØ�M‰M˜FŸO™OÒ1¨r×8Ñ8Ó:¸F¿K¹KÒ<oÌ>×K]ÑK]Ð^d×^kÑ^kÐmnÓKoÐpÐpr1   c              #   ó2   K  — | ]  }t        |«      –— Œ y ­w©N)rþ   )Ú.0Úendpoints     r2   ú	<genexpr>r    s   è ø€ ò àô �×ñùs   ‚zhttps://hf.corò   c                 ó<   — t        |«      t        | «      ht        £v S )zQWhether `target` is served by the same origin as `url`, or by a known Hub origin.)rþ   Ú_HUB_ORIGINS)rU   rò   s     r2   rí   rí   (  s   € ä�vÓ¤;¨sÓ#3Ð"C´lÐ"CÐCÐCr1   r  c                 ó  — |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.
    rZ   )Úrstripr   ÚENDPOINTÚ_HF_DEFAULT_ENDPOINTÚ_HF_DEFAULT_STAGING_ENDPOINTÚreplace)rU   r  s     r2   Ú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ˆØ€Jr1   Ú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                  «      }
|
�‘|
j<                  d.k(  r‚d/|
j>                  › d0�}|d1|
j@                  › d2�z  }|
jB                  �:|
jD                  �.|d3|
j<                  › d4|
jB                  › d5|
jD                  › d6�z  }n|dz  }|d7| j                  › d�z  }nd8| j                  › d�}t        t8        || «      |‚| j                  d9k(  r[| j                  j                  j                  d:«      }|› 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   rY   NzX-Error-CodeúX-Error-MessagerX   ÚRevisionNotFoundz Client Error.ú

zRevision Not Found for url: ú.)r`   rc   Ú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/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·   r   z0

429 Too Many Requests: you have reached your 'z' rate limit.z
Retry after z secondsú (rZ   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°   r‚   rƒ   Úraise_for_statusr˜   ÚHTTPStatusErrorrŽ   r3   r^   rx   rU   r-   rd   Ú_formatr   r   r   r   ÚBUCKET_API_REGEXr=   r   rh   rk   r   ÚREPO_API_REGEXr   r   r   rE   r%   r$   r&   r'   r(   )r‹   r  r³   Ú
error_codeÚerror_messageÚrequest_urlr`   rc   Úmessager  rÆ   Úrange_headers               r2   rÅ   rÅ   :  s  € ðBGÜ  Ô*ð
C?Ø×!Ñ!Õ#øô ò Gä�‰Ð6ÀˆÖFðGûô ×!Ñ!ó A?Ø×Ñ 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àÐ)¨n×.FÑ.FÈ!Ò.Kà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Ð>ûðCA?ús-   ‚ ŽA Ÿ AÁAÁS0ÁS+Á0Q;S+Ó+S0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 (`httpx2.Response`):
            The HTTP response to check for warning headers.
    zX-HF-Warningú;r   rø   N)r3   Úget_listÚsplitrG   Ú_WARNED_TOPICSÚaddr‚   r±   )r‹   Úserver_warningsÚserver_warningÚtopicr&  s        r2   r  r  ê  sŠ   € ð ×&Ñ&×/Ñ/°Ó?€OØ)ò (ˆØ9<ÀÑ9N˜×-Ñ-¨c°1Ô5ÐUWÐYgÐTh‰ˆˆwØ—‘“ˆØœÒ&Ø—m‘m“oˆGÚÜ×"Ñ" 5Ô)Ü—‘˜wÕ'ñ(r1   Ú_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  ú))r‹   Úserver_message)r3   r^   ÚappendÚjsonr˜   ÚResponseNotReadÚreadÚRuntimeErrorrÍ   ÚlistÚextendÚJSONDecodeErrorÚtextr;   r-   rG   ÚdictÚfromkeysÚjoinr   r~   ÚX_AMZ_CF_IDÚindexÚitemsÚsetattr)r3  r4  r‹   r5  Úserver_errorsÚfrom_headersrÂ   r7  r8  r:  Úcontent_typeÚliner=  Úfinal_error_messager‡   Úrequest_id_messageÚheaderÚlabelrI   Únewline_indexrÜ   ÚkÚvs                          r2   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)r^  ÚpatternÚreplacements      r2   Ú_redact_sensitive_bodyrd  z  s+   € ä 8ò .Ñˆ�Ø�{‰{˜;¨Ó-‰ð.à€Kr1   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 `httpx2.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-Xr{   z<TOKEN>z-Hr9  Nzutf-8Úignore)r:  iè  z ... [truncated]z<streaming body>z-dr  rø   rÄ   )r„   Úsortedr3   rL  r;   ÚcontentÚdecodeÚlenrd  r˜   ÚRequestNotReadr  rU   r>  r   r-   rI  )rx   ÚpartsrW  rX  r^  Ú
flat_partss         r2   r†   r†   �  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 - )r�   ÚRANGE_REGEXÚ	fullmatchrB  Úgroupsr/   )ro  rp  rC   ÚstartÚendÚ
new_suffixÚ	new_rangeÚ	new_starts           r2   Ú_adjust_range_headerr|  ¯  s'  € ñ Ø˜�} AÐ&Ð&à
ˆnÑÜÐ6°~Ð6HÐH\Ð]Ó^Ð^ä×!Ñ! .Ó1€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Ð Ð r1   )r4   Nr   )‹r,   ÚatexitrÏ   r?  ÚosÚreÚ	threadingr×   r€   Úcollections.abcr   r   r   Ú
contextlibr   Úcontextvarsr   Údataclassesr   Ú	functoolsr
   Úshlexr   Útypingr   r   Úurllib.parser   r   r˜   Úhuggingface_hub.errorsr   rø   r   r:  r   r   r   r   r   r   r   r   r   r   Ú_lfsr   Ú_typingr   r    Ú
get_loggerr)   r‚   r#   Úcompiler<   r?   r-   rE   r/   rJ   r   r~   rJ  ÚVERBOSEr"  r!  rj   r]   r[   rf   r_   Útuplerd   rh   rk   rl   rÔ   r.   rw   ÚRequestrˆ   rŠ   rÓ   r’   r™   rš   rœ   r�   ÚCLIENT_FACTORY_TÚASYNC_CLIENT_FACTORY_TÚLockr£   rž   rŸ   r    r¥   r©   r«   r­   r¤   ÚregisterÚhasattrr´   ÚTimeoutExceptionÚNetworkErrorÚRemoteProtocolErrorr¶   rÎ   r°   r¸   rÖ   rÞ   rã   rå   rë   ró   rü   rþ   Ú	frozensetr	  r
  r  r  rí   r  rÅ   rq   r,  r  r1  r   Ú_SENSITIVE_BODY_KEYSr`  rd  r†   Ú
IGNORECASErt  r|  )rA   rb  s   00r2   ú<module>rœ     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Ð ð %˜"Ÿ*™*Ð%kÓlÐ ð #- "§*¡*ØSó#Ð ð
 '˜BŸJ™JÐ'UÓVÐ ò qÐ ð 3ð ¨5°°t±¸SÀ4¹ZÐ1GÑ+Hó ð:- 3ð -¨3°©:ó -ð- ð -¨¨d©
ó -ñ '1Ð1DÈeÔ&TÐ �:˜dÑ#Ó Tð˜ið ¨Ió ð$" 6§>¡>ð "°c¸D±jó "ðJ*¨v¯~©~ð *À#ÈÁ*ó *ð'°·±ð 'ÀTó 'ð §¡ó ð f×&8Ñ&8ó ð ˜B §¡Ð-Ñ.Ð Ø! " f×&8Ñ&8Ð"8Ñ9Ð àˆy�~‰~Ó€Ø+AÐ Ð(Ó AØ7SÐ Ð4Ó SØ'+€�—‘ Ñ$Ó +ð0Ð'7ð 0¸Dó 0ð"8Ð3Ið 8Èdó 8ð �V—]‘]ó ð 
*˜6×-Ñ-ó 
*ó9ð, €‡��Ô Ù
ˆ2Ð!Ô"Ø€B×Ñ }Õ5ð ×ÑØ
×ÑØ
×Ñð=Ð ˜e D¨¡O°SÐ$8Ñ9ó ð
 3QÐ   c¨3 h¡Ó Pð ØØØIeØ3QØòd8Øðd8à	ðd8ð ð	d8ð
 ðd8ð ðd8ð ˜i™¨5°°i±À#Ð1EÑ+FÑFðd8ð   s¨C x¡Ñ0ðd8ð ðd8ð ˆv�‰  dÐ*Ñ+ód8ðV ØØØ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ð ˆv�‰  dÐ*Ñ+òLó ðLð^ €ð AFò1cØð1cØ #ð1cØ9=ð1cà‡_�_ó1cðh  sÑ+€ðq�Sð q˜U 3¨¨S =Ñ1ó qñ ñ ð 	×&Ñ&Ø×.Ñ.Ø×ÑØð	ôó €ðD˜cð D¨3ð D°4ó Dð

 ð 
¨s°T©zð 
¸có 
ñj? &§/¡/ð j?À#ÈÁ*ð j?ÐX\ó j?ñZ “€ð( v§¡ð (¸4ó (ñ0 Ð-°^ÔDÐ ðfØÐ%Ñ&ðfØ8;ðfØGMÇÁðfØadðfàófðT jÐ ð $÷àà	ˆ�‰�r˜#˜Ð0Ð1Ó	2Ð4EÐFØ	ˆ�‰�v˜c˜U 'Ð*Ó	+Ð->Ð?ðòð 	ò ðØóÐ ð ð ¨ó ð' �f—n‘nð ' ¨ó ' ðV ˆb�j‰jÐ?ÀÇÂÓO€ð"!¨¨t©ð "!À#ð "!È#ÐPTÉ*ô "!ùós   Ò:>U