§
    ¬˜ºh»c  ã                   óØ  — 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m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 ddlZddl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!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, ddl-m.Z.  e(j/        e0¦  «        Z1dZ2dZ3 ej4        dej5        ¬¦  «        Z6 G d„ de¦  «        Z7 G d„ de¦  «        Z8dej9        fd„Z:eg ej9        f         Z;e:a<e;e=d<   e:fde;ddfd„Z>dej9        fd „Z?d?d!„Z@ed"eAd#eAdej9        fd$„¦   «         ZBd%dd&ejC        ejD        fe
jE        d'œd(e.d)eFd*eAd+eGd,eGd-eeeH         eeeH         d.f         f         d/eeAeeAd.f         f         defd0„ZId)eFd1eeF         deFfd2„ZJd@d3ed4eeF         ddfd5„ZKd6ee%         d7eFd3ede%fd8„ZLd9ej        deFfd:„ZM ej4        d;ejN        ¦  «        ZOd<eeF         d=eAdeeF         fd>„ZPdS )Az>Contains utilities to handle HTTP requests in Huggingface Hub.é    N)Ú	lru_cache)Ú
HTTPStatus)Úquote)ÚAnyÚCallableÚListÚOptionalÚTupleÚTypeÚUnion)Ú	HTTPErrorÚResponse)ÚHTTPAdapter)ÚPreparedRequest)ÚOfflineModeIsEnabledé   )Ú	constants)ÚBadRequestErrorÚDisabledRepoErrorÚEntryNotFoundErrorÚGatedRepoErrorÚHfHubHTTPErrorÚRepositoryNotFoundErrorÚRevisionNotFoundErroré   )Úlogging)ÚJSONDecodeError)ÚSliceFileObj)ÚHTTP_METHOD_TúX-Amzn-Trace-Idzx-request-ida  
        # staging or production endpoint
        ^https://[^/]+
        (
            # on /api/repo_type/repo_id
            /api/(models|datasets|spaces)/(.+)
            |
            # or /repo_id/resolve/revision/...
            /(.+)/resolve/(.+)
        )
    )Úflagsc                   ó6   ‡ — e Zd ZdZˆ fd„Zdedefˆ fd„Zˆ xZS )ÚUniqueRequestIdAdapterr    c                 óä  •—  t          ¦   «         j        |fi |¤Ž t          |j        vrL|j                             t
          ¦  «        pt          t          j        ¦   «         ¦  «        |j        t          <   t          t          |j                             dd¦  «        ¦  «        ¦  «        dk    }t                               d|j        t                   › d|j        › d|j        › d|› d�	¦  «         d S )	NÚauthorizationÚ r   zRequest z: ú z (authenticated: ú))ÚsuperÚadd_headersÚX_AMZN_TRACE_IDÚheadersÚgetÚX_REQUEST_IDÚstrÚuuidÚuuid4ÚlenÚloggerÚdebugÚmethodÚurl)ÚselfÚrequestÚkwargsÚ	has_tokenÚ	__class__s       €úc/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/huggingface_hub/utils/_http.pyr*   z"UniqueRequestIdAdapter.add_headersN   så   ø€ Ø�‰ŒÔ˜GÐ.Ð. vÐ.Ð.Ð.õ  '¤/Ð1Ð1Ø/6¬×/BÒ/BÅ<Ñ/PÔ/PÐ/eÕTWÕX\ÔXbÑXdÔXdÑTeÔTeˆGŒO�OÑ,õ �˜GœO×/Ò/°ÀÑDÔDÑEÔEÑFÔFÈÒJˆ	Ý�ŠØv�w”¥Ô7ÐvÐv¸7¼>ÐvÐvÈGÌKÐvÐvÐjsÐvÐvÐvñ	
ô 	
ð 	
ð 	
ð 	
ó    r8   Úreturnc                 óH  •— t           j        r*t                               dt	          |¦  «        › �¦  «         	  t          ¦   «         j        |g|¢R i |¤ŽS # t          j        $ r<}|j	         
                    t          ¦  «        }|�g |j        ¢d|› d�‘R |_        ‚ d}~ww xY w)zSCatch any RequestException to append request id to the error message for debugging.zSend: Nz(Request ID: r(   )r   ÚHF_DEBUGr3   r4   Ú_curlifyr)   ÚsendÚrequestsÚRequestExceptionr,   r-   r+   Úargs)r7   r8   rE   r9   ÚeÚ
request_idr;   s         €r<   rB   zUniqueRequestIdAdapter.send[   s¾   ø€ åÔð 	7Ý�LŠLÐ5¥(¨7Ñ"3Ô"3Ð5Ð5Ñ6Ô6Ð6ð	Ø•5‘7”7”< Ð9¨$Ð9Ð9Ð9°&Ð9Ð9Ð9øÝÔ(ð 	ð 	ð 	Ø œ×,Ò,­_Ñ=Ô=ˆJØÐ%àA˜1œ6ÐAÐ#@°:Ð#@Ð#@Ð#@ÐAÐA�”Øøøøøð	øøøs   ¹A ÁB!Á%7BÂB!)	Ú__name__Ú
__module__Ú__qualname__r+   r*   r   r   rB   Ú__classcell__)r;   s   @r<   r#   r#   K   si   ø€ € € € € Ø'€Oð
ð 
ð 
ð 
ð 
ð˜Oð Àð ð ð ð ð ð ð ð ð ð r=   r#   c                   ó   — e Zd Zdedefd„ZdS )ÚOfflineAdapterr8   r>   c                 ó2   — t          d|j        › d�¦  «        ‚)NzCannot reach za: offline mode is enabled. To disable it, please unset the `HF_HUB_OFFLINE` environment variable.)r   r6   )r7   r8   rE   r9   s       r<   rB   zOfflineAdapter.sendj   s0   € Ý"ð K˜GœKð  Kð  Kð  Kñ
ô 
ð 	
r=   N)rH   rI   rJ   r   r   rB   © r=   r<   rM   rM   i   s6   € € € € € ð
˜Oð 
Àð 
ð 
ð 
ð 
ð 
ð 
r=   rM   r>   c                  óV  — t          j        ¦   «         } t          j        rE|                      dt          ¦   «         ¦  «         |                      dt          ¦   «         ¦  «         nD|                      dt          ¦   «         ¦  «         |                      dt          ¦   «         ¦  «         | S )Nzhttp://zhttps://)rC   ÚSessionr   ÚHF_HUB_OFFLINEÚmountrM   r#   )Úsessions    r<   Ú_default_backend_factoryrU   p   s�   € ÝÔÑ Ô €GÝÔð <Ø�Š�i¥Ñ!1Ô!1Ñ2Ô2Ð2Ø�Š�j¥.Ñ"2Ô"2Ñ3Ô3Ð3Ð3à�Š�iÕ!7Ñ!9Ô!9Ñ:Ô:Ð:Ø�Š�jÕ"8Ñ":Ô":Ñ;Ô;Ð;Ø€Nr=   Ú_GLOBAL_BACKEND_FACTORYÚbackend_factoryc                 ó&   — | a t          ¦   «          dS )aË  
    Configure the HTTP backend by providing a `backend_factory`. Any HTTP calls made by `huggingface_hub` will use a
    Session object instantiated by this factory. 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 configured Session. Since `requests.Session` is not guaranteed to be thread-safe,
    `huggingface_hub` creates 1 Session instance per thread. They are all instantiated using the same `backend_factory`
    set in [`configure_http_backend`]. A LRU cache is used to cache the created sessions (and connections) between
    calls. Max size is 128 to avoid memory leaks if thousands of threads are spawned.

    See [this issue](https://github.com/psf/requests/issues/2766) to know more about thread-safety in `requests`.

    Example:
    ```py
    import requests
    from huggingface_hub import configure_http_backend, get_session

    # Create a factory function that returns a Session with configured proxies
    def backend_factory() -> requests.Session:
        session = requests.Session()
        session.proxies = {"http": "http://10.10.1.10:3128", "https": "https://10.10.1.11:1080"}
        return session

    # Set it as the default session factory
    configure_http_backend(backend_factory=backend_factory)

    # In practice, this is mostly done internally in `huggingface_hub`
    session = get_session()
    ```
    N)rV   Úreset_sessions)rW   s    r<   Úconfigure_http_backendrZ      s   € ð@ .ÐÝÑÔÐÐÐr=   c                  óh   — t          t          j        ¦   «         t          j        ¦   «         ¬¦  «        S )aÜ  
    Get a `requests.Session` object, using the session factory from the user.

    Use [`get_session`] to get a configured Session. Since `requests.Session` is not guaranteed to be thread-safe,
    `huggingface_hub` creates 1 Session instance per thread. They are all instantiated using the same `backend_factory`
    set in [`configure_http_backend`]. A LRU cache is used to cache the created sessions (and connections) between
    calls. Max size is 128 to avoid memory leaks if thousands of threads are spawned.

    See [this issue](https://github.com/psf/requests/issues/2766) to know more about thread-safety in `requests`.

    Example:
    ```py
    import requests
    from huggingface_hub import configure_http_backend, get_session

    # Create a factory function that returns a Session with configured proxies
    def backend_factory() -> requests.Session:
        session = requests.Session()
        session.proxies = {"http": "http://10.10.1.10:3128", "https": "https://10.10.1.11:1080"}
        return session

    # Set it as the default session factory
    configure_http_backend(backend_factory=backend_factory)

    # In practice, this is mostly done internally in `huggingface_hub`
    session = get_session()
    ```
    ©Ú
process_idÚ	thread_id)Ú_get_session_from_cacheÚosÚgetpidÚ	threadingÚ	get_identrO   r=   r<   Úget_sessionrd   £   s&   € õ: #­b¬i©k¬kÅYÔEXÑEZÔEZÐ[Ñ[Ô[Ð[r=   c                  ó8   — t                                ¦   «          dS )z«Reset the cache of sessions.

    Mostly used internally when sessions are reconfigured or an SSLError is raised.
    See [`configure_http_backend`] for more details.
    N)r_   Úcache_clearrO   r=   r<   rY   rY   Ã   s   € õ ×'Ò'Ñ)Ô)Ð)Ð)Ð)r=   r]   r^   c                 ó   — t          ¦   «         S )zÒ
    Create a new session per thread using global factory. Using LRU cache (maxsize 128) to avoid memory leaks when
    using thousands of threads. Cache is cleared when `configure_http_backend` is called.
    )rV   r\   s     r<   r_   r_   Ì   s   € õ #Ñ$Ô$Ð$r=   é   é   )Úmax_retriesÚbase_wait_timeÚmax_wait_timeÚretry_on_exceptionsÚretry_on_status_codesr5   r6   rj   rk   rl   rm   .rn   c          	      ó€  — t          |t          ¦  «        r|f}t          |t          ¦  «        r|f}d}|}	d}
d|v rAt          |d         t          j        t
          f¦  «        r|d                              ¦   «         }
t          ¦   «         }	 |dz  }	 |
�|d                              |
¦  «          |j	        d| |dœ|¤Ž}|j
        |vr|S t                               d|j
        › d| › d	|› �¦  «         ||k    r|                     ¦   «          |S ne# |$ r]}t                               d
|› d| › d	|› �¦  «         t          |t          j        ¦  «        rt!          ¦   «          ||k    r|‚Y d}~nd}~ww xY wt                               d|	› d|› d|› d�¦  «         t#          j        |	¦  «         t'          ||	dz  ¦  «        }	�Œ5)a#  Wrapper around requests to retry calls on an endpoint, with exponential backoff.

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

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

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

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

    # Same usage as "requests.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()
    ```

    <Tip warning={true}>

    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).

    </Tip>
    r   NÚdataTr   )r5   r6   zHTTP Error z thrown while requesting r'   ú'z' thrown while requesting zRetrying in z	s [Retry ú/z].r   rO   )Ú
isinstanceÚtypeÚintÚioÚIOBaser   Útellrd   Úseekr8   Ústatus_coder3   ÚwarningÚraise_for_statusrC   ÚConnectionErrorrY   ÚtimeÚsleepÚmin)r5   r6   rj   rk   rl   rm   rn   r9   Únb_triesÚ
sleep_timeÚio_obj_initial_posrT   ÚresponseÚerrs                 r<   Úhttp_backoffr†   Õ   s?  € õN Ð%¥tÑ,Ô,ð 5Ø2Ð4ÐåÐ'­Ñ-Ô-ð 9Ø!6Ð 8Ðà€HØ€Jð
 ÐØ�ÐÐ�J v¨f¤~½¼	Å<Ð7PÑQÔQÐØ# Fœ^×0Ò0Ñ2Ô2Ðå‰mŒm€Gð#8Ø�A‰ˆð	ð "Ð-Ø�v”×#Ò#Ð$6Ñ7Ô7Ð7ð '�w”ÐH¨f¸#ÐHÐHÀÐHÐHˆHØÔ#Ð+@Ð@Ð@Ø�õ �NŠNÐf¨Ô)=ÐfÐfÐX^ÐfÐfÐadÐfÐfÑgÔgÐgØ˜+Ò%Ð%Ø×)Ò)Ñ+Ô+Ð+ð  �ð	 &øð #ð 	ð 	ð 	Ý�NŠNÐL˜sÐLÐL¸fÐLÐLÀsÐLÐLÑMÔMÐMå˜#�xÔ7Ñ8Ô8ð !ÝÑ Ô Ð à˜+Ò%Ð%Ø�	ð &Ð%Ð%Ð%Ð%øøøøð	øøøõ 	�ŠÐU jÐUÐU¸8ÐUÐUÀkÐUÐUÐUÑVÔVÐVÝŒ
�:ÑÔÐõ ˜¨
°Q©Ñ7Ô7ˆ
ñG#8s    Â7D Ã	AD ÄE0ÄAE+Å+E0Úendpointc                 ó   — |r|                      d¦  «        nt          j        }|t          j        t          j        fvr@|                      t          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.
    rr   )Úrstripr   ÚENDPOINTÚ_HF_DEFAULT_ENDPOINTÚ_HF_DEFAULT_STAGING_ENDPOINTÚreplace)r6   r‡   s     r<   Úfix_hf_endpoint_in_urlrŽ   S  si   € ð
 (0ÐGˆx�Š˜sÑ#Ô#Ð#µYÔ5G€Hà�	Ô6½	Ô8^Ð_Ð_Ð_Ø�kŠk�)Ô8¸(ÑCÔCˆØ�kŠk�)Ô@À(ÑKÔKˆØ€Jr=   r„   Úendpoint_namec                 ób  — 	 |                       ¦   «          dS # t          $ �r‹}| j                             d¦  «        }| j                             d¦  «        }|dk    r0| j        › d�dz   d| j        › d�z   }t          t          || ¦  «        |‚|dk    r0| j        › d�dz   d	| j        › d�z   }t          t          || ¦  «        |‚|d
k    r0| j        › d�dz   d| j        › d�z   }t          t          || ¦  «        |‚|dk    r6| j        › d�dz   d| j        › d�z   dz   dz   }t          t          || ¦  «        |‚|dk    sH| j        dk    rp|dk    rj| j        �c| j        j        �Wt                               | j        j        ¦  «        �3| j        › d�dz   d| j        › d�z   dz   }t          t          || ¦  «        |‚| j        dk    r!|�d|› d�nd}t          t          || ¦  «        |‚| j        dk    r4d| j        › d|› d�d| j        › d�z   dz   }t          t           || ¦  «        |‚| j        dk    rY| j        j                             d¦  «        }|› d|› d | j                             d!¦  «        › d�}t          t           || ¦  «        |‚t          t           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 `HfHubHTTPError`.

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


    Example:
    ```py
        import requests
        from huggingface_hub.utils import get_session, hf_raise_for_status, HfHubHTTPError

        response = get_session().post(...)
        try:
            hf_raise_for_status(response)
        except HfHubHTTPError as e:
            print(str(e)) # formatted message
            e.request_id, e.server_message # details returned by server

            # Complete the error message with additional information once it's raised
            e.append_to_message("
`create_commit` expects the repository to exist.")
            raise
    ```

    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.

    <Tip warning={true}>

    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 find.
        - [`~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.

    </Tip>
    zX-Error-CodeúX-Error-MessageÚRevisionNotFoundz Client Error.ú

zRevision Not Found for url: ú.ÚEntryNotFoundzEntry Not Found for url: Ú	GatedRepoz!Cannot access gated repo for url z$Access to this resource is disabled.z!Cannot access repository for url ú
ÚRepoNotFoundi‘  z+Invalid credentials in Authorization headerNzRepository Not Found for url: zí
Please make sure you specified the correct `repo_id` and `repo_type`.
If you are trying to access a private or gated repo, make sure you are authenticated. For more details, see https://huggingface.co/docs/huggingface_hub/authenticationi�  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.i   ÚRangez. Requested range: z. Content-Range: zContent-Range)r|   r   r,   r-   rz   r6   Ú_formatr   r   r   r   r8   ÚREPO_API_REGEXÚsearchr   r   r   r/   )r„   r�   rF   Ú
error_codeÚerror_messageÚmessageÚrange_headers          r<   Úhf_raise_for_statusr¡   `  s—  € ðpJ?Ø×!Ò!Ñ#Ô#Ð#Ð#Ð#øÝð H?ñ H?ð H?ØÔ%×)Ò)¨.Ñ9Ô9ˆ
Ø Ô(×,Ò,Ð->Ñ?Ô?ˆàÐ+Ò+Ð+Ø!Ô-Ð=Ð=Ð=ÀÑFÐIwÐhpÔhtÐIwÐIwÐIwÑwˆGÝÕ/°¸(ÑCÔCÈÐJà˜?Ò*Ð*Ø!Ô-Ð=Ð=Ð=ÀÑFÐItÐemÔeqÐItÐItÐItÑtˆGÝÕ,¨g°xÑ@Ô@ÀaÐGà˜;Ò&Ð&àÔ'Ð7Ð7Ð7¸&Ñ@ÐCvÐgoÔgsÐCvÐCvÐCvÑvð õ �.¨'°8Ñ<Ô<À!ÐCàÐDÒDÐDàÔ'Ð7Ð7Ð7ØñàE°h´lÐEÐEÐEñFð ñð 9ñ	9ð õ Õ+¨W°hÑ?Ô?ÀQÐFà˜>Ò)Ð)ØÔ  CÒ'Ð'ØÐ!NÒNÐNØÔ Ð,ØÔ Ô$Ð0Ý×%Ò% hÔ&6Ô&:Ñ;Ô;ÐGð Ô'Ð7Ð7Ð7ØñàB°8´<ÐBÐBÐBñCðNñNð õ Õ1°7¸HÑEÔEÈ1ÐLàÔ! SÒ(Ð(àDQÐD]Ð@ }Ð@Ð@Ð@Ð@Ðcuð õ �/¨7°HÑ=Ô=À1ÐDàÔ! SÒ(Ð(àI�xÔ+ÐIÐI¸ÐIÐIÐIØ@°´Ð@Ð@Ð@ñAàGñHð õ
 �.¨'°8Ñ<Ô<À!ÐCàÔ! SÒ(Ð(Ø#Ô+Ô3×7Ò7¸Ñ@Ô@ˆLØÐvÐv¨|ÐvÐvÈhÔN^×NbÒNbÐcrÑNsÔNsÐvÐvÐvˆGÝ�.¨'°8Ñ<Ô<À!ÐCõ •n¥c¨!¡f¤f¨hÑ7Ô7¸QÐ>øøøøðQH?øøøs   ‚ ˜J.£JJ)Ê)J.Ú
error_typeÚcustom_messagec                 ój  — g }|j                              d¦  «        }|�|                     |¦  «         	 |                     ¦   «         }|                     d¦  «        }|�@t	          |t
          ¦  «        r|                     |¦  «         n|                     |¦  «         |                     d¦  «        }|�$|D ]!}d|v r|                     |d         ¦  «         Œ"nb# t          $ rU |j                              dd¦  «        }|j        r0d| 	                    ¦   «         vr|                     |j        ¦  «         Y nw xY wd„ |D ¦   «         }t          t                               |¦  «        ¦  «        }d	                     |¦  «        }	|}
|	r=|	 	                    ¦   «         | 	                    ¦   «         vrd
|v r	|
d	|	z   z  }
n|
d
|	z   z  }
t          |j                              t          d¦  «        ¦  «        }|rd|› d�}n5t          |j                              t          d¦  «        ¦  «        }|rd|› d�}|r_| 	                    ¦   «         |
 	                    ¦   «         vr7d	|
v r.|
                     d	¦  «        }|
d |…         |z   |
|d …         z   }
n|
|z  }
 | |
                     ¦   «         ||	pd ¬¦  «        S )Nr‘   ÚerrorÚerrorsrŸ   zContent-Typer&   Úhtmlc                 ó’   — g | ]D}t          |¦  «                             ¦   «         ¯#t          |¦  «                             ¦   «         ‘ŒES rO   )r/   Ústrip)Ú.0Úlines     r<   ú
<listcomp>z_format.<locals>.<listcomp>	  s=   € ÐVÐVÐV¨4ÅCÈÁIÄIÇOÂOÑDUÔDUÐV•S˜‘Y”Y—_’_Ñ&Ô&ÐVÐVÐVr=   r—   r“   z (Request ID: r(   z (Amzn Trace ID: )r„   Úserver_message)r,   r-   ÚappendÚjsonrs   ÚlistÚextendr   ÚtextÚlowerÚdictÚfromkeysÚjoinr/   r.   r+   Úindexr©   )r¢   r£   r„   Úserver_errorsÚfrom_headersrp   r¥   r¦   Úcontent_typer­   Úfinal_error_messagerG   Úrequest_id_messageÚnewline_indexs                 r<   rš   rš   å  s'  € Ø€Mð Ô#×'Ò'Ð(9Ñ:Ô:€LØÐØ×Ò˜\Ñ*Ô*Ð*ð0à�}Š}‰Œˆà—’˜Ñ!Ô!ˆØÐÝ˜%¥Ñ&Ô&ð ,à×$Ò$ UÑ+Ô+Ð+Ð+ð ×$Ò$ UÑ+Ô+Ð+à—’˜(Ñ#Ô#ˆØÐàð ;ð ;�Ø Ð%Ð%Ø!×(Ò(¨¨yÔ)9Ñ:Ô:Ð:øøøåð 0ð 0ð 0àÔ'×+Ò+¨N¸BÑ?Ô?ˆØŒ=ð 	0˜V¨<×+=Ò+=Ñ+?Ô+?Ð?Ð?Ø× Ò  ¤Ñ/Ô/Ð/øøð	0øøøð WÐV°=ÐVÑVÔV€Mõ �Ÿš }Ñ5Ô5Ñ6Ô6€Mð —Y’Y˜}Ñ-Ô-€Nð )ÐØð ;˜.×.Ò.Ñ0Ô0¸×8LÒ8LÑ8NÔ8NÐNÐNØ�^Ð#Ð#Ø 4¨.Ñ#8Ñ8ÐÐà 6¨NÑ#:Ñ:Ðå�XÔ%×)Ò)­,¸Ñ;Ô;Ñ<Ô<€JØð CØ;¨jÐ;Ð;Ð;ÐÐõ ˜Ô)×-Ò-­o¸rÑBÔBÑCÔCˆ
Øð 	CØ!B°ZÐ!BÐ!BÐ!BÐØð 6�j×&Ò&Ñ(Ô(Ð0C×0IÒ0IÑ0KÔ0KÐKÐKØÐ&Ð&Ð&Ø/×5Ò5°dÑ;Ô;ˆMà# N ] NÔ3Ð6HÑHÐK^Ð_lÐ_mÐ_mÔKnÑnð  Ðð  Ð#5Ñ5Ðð ˆ:Ð)×/Ò/Ñ1Ô1¸HÐUcÐUkÐgkÐlÑlÔlÐls   µB&C ÃAD;Ä:D;r8   c                 óÖ  — dd| j         fg}t          | j                             ¦   «         ¦  «        D ];\  }}|                     ¦   «         dk    rd}|dd                     ||¦  «        fgz  }Œ<| j        r‚| j        }t          |t          ¦  «        r| 	                    dd¬	¦  «        }nt          |d
¦  «        rd}t          |¦  «        dk    r|dd…         dz   }|d|                     dd¦  «        fgz  }|d| j        fgz  }g }|D ]M\  }}|r"|                     t          |¦  «        ¦  «         |r"|                     t          |¦  «        ¦  «         ŒNd                     |¦  «        S )zéConvert a `requests.PreparedRequest` 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-Hz{0}: {1}zutf-8Úignore)r¦   Úreadz<file-like object>iè  Nz ... [truncated]z-dr—   r&   r'   )r5   Úsortedr,   Úitemsr³   ÚformatÚbodyrs   ÚbytesÚdecodeÚhasattrr2   r�   r6   r®   r   r¶   )r8   ÚpartsÚkÚvrÅ   Ú
flat_partss         r<   rA   rA   /  s—  € ð 	Ø	ˆwŒ~Ðð$€Eõ
 �w”×,Ò,Ñ.Ô.Ñ/Ô/ð 3ð 3‰ˆˆ1Ø�7Š7‰9Œ9˜Ò'Ð'ØˆAØ�4˜×*Ò*¨1¨aÑ0Ô0Ð1Ð2Ñ2ˆˆà„|ð 2ØŒ|ˆÝ�d�EÑ"Ô"ð 	(Ø—;’;˜w¨x�;Ñ8Ô8ˆDˆDÝ�T˜6Ñ"Ô"ð 	(Ø'ˆDÝˆt‰9Œ9�tÒÐØ˜˜˜”;Ð!3Ñ3ˆDØ�4˜Ÿš d¨BÑ/Ô/Ð0Ð1Ñ1ˆà	ˆt�W”[Ð!Ð"Ñ"€Eà€JØð (ð (‰ˆˆ1Øð 	(Ø×Ò�e A™hœhÑ'Ô'Ð'Øð 	(Ø×Ò�e A™hœhÑ'Ô'Ð'øà�8Š8�JÑÔÐr=   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                               | ¦  «        }|st          d| ›d�¦  «        ‚|                     ¦   «         \  }}|sG|st          d| ›d�¦  «        ‚t          |¦  «        |z
  }d|› �}|d	k    rt          d
|›d�¦  «        ‚|S t          |¦  «        }||z   }|r2t          |¦  «        }d|› d|› �}||k    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 - )Ú
ValueErrorÚRANGE_REGEXÚmatchÚRuntimeErrorÚgroupsru   )rÍ   rÎ   rÔ   ÚstartÚendÚ
new_suffixÚ	new_rangeÚ	new_starts           r<   Ú_adjust_range_headerrÜ   [  sq  € ð ð 'Ø&˜Ð&Ð&Ð&Ð&à
ˆnÐÐÝÐ]°~Ð]Ð]Ð]Ñ^Ô^Ð^å×Ò˜nÑ-Ô-€EØð JÝÐH°^ÐHÐHÐHÑIÔIÐIØ—’‘”�J€Eˆ3àð Øð 	NÝÐL¸ÐLÐLÐLÑMÔMÐMå˜‘X”X Ñ+ˆ
Ø*˜jÐ*Ð*ˆ	Ø˜Š?ˆ?ÝÐB°IÐBÐBÐBÑCÔCÐCØÐå�‰JŒJ€EØ˜Ñ#€IØ
ð Ý�#‰hŒhˆØ.˜YÐ.Ð.¨Ð.Ð.ˆ	Ø�sŠ?ˆ?ÝÐB°IÐBÐBÐBÑCÔCÐCØÐà �IÐ Ð Ð Ð r=   )r>   N)N)QÚ__doc__rv   r`   Úrerb   r~   r0   Ú	functoolsr   Úhttpr   Úshlexr   Útypingr   r   r   r	   r
   r   r   rC   r   r   Úrequests.adaptersr   Úrequests.modelsr   Úhuggingface_hub.errorsr   r&   r   r¦   r   r   r   r   r   r   r   r   Ú_fixesr   Ú_lfsr   Ú_typingr   Ú
get_loggerrH   r3   r+   r.   ÚcompileÚVERBOSEr›   r#   rM   rQ   rU   ÚBACKEND_FACTORY_TrV   Ú__annotations__rZ   rd   rY   ru   r_   ÚTimeoutr}   ÚSERVICE_UNAVAILABLEr/   ÚfloatÚ	Exceptionr†   rŽ   r¡   rš   rA   Ú
IGNORECASErÓ   rÜ   rO   r=   r<   ú<module>ró      s8  ðð EÐ DÐ Dà 	€	€	€	Ø 	€	€	€	Ø 	€	€	€	Ø Ð Ð Ð Ø €€€Ø €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ Dà €€€Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø )Ð )Ð )Ð )Ð )Ð )Ø +Ð +Ð +Ð +Ð +Ð +à 7Ð 7Ð 7Ð 7Ð 7Ð 7à Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð Ð Ð Ð Ð Ð Ø #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "ð 
ˆÔ	˜HÑ	%Ô	%€ð
 $€Ø€à�”ð
ð Œ*ðñ ô €ð ð ð ð ð ˜[ñ ô ð ð<
ð 
ð 
ð 
ð 
�[ñ 
ô 
ð 
ð (Ô"2ð ð ð ð ð ˜R Ô!1Ð1Ô2Ð Ø-EÐ Ð*Ð EÐ EÑ Eð AYð !ð !Ð,=ð !Ð]að !ð !ð !ð !ðH\�XÔ%ð \ð \ð \ð \ð@*ð *ð *ð *ð ð%¨ð %¸ð %ÀÔ@Pð %ð %ð %ñ „ð%ð ØØàÔØÔ ðPð :DÔ9Wð{8ð {8ð {8Øð{8à	ð{8ð ð	{8ð
 ð{8ð ð{8ð ˜t Iœ°°d¸9´oÀsÐ6JÔ0KÐKÔLð{8ð !  e¨C°¨H¤oÐ!5Ô6ð{8ð ð{8ð {8ð {8ð {8ð|
 ð 
¨x¸¬}ð 
Àð 
ð 
ð 
ð 
ðB?ð B? (ð B?¸8ÀC¼=ð B?ÐTXð B?ð B?ð B?ð B?ðJGm˜˜^Ô,ð Gm¸cð GmÈXð GmÐZhð Gmð Gmð Gmð GmðT% �hÔ.ð % °3ð % ð % ð % ð % ðR ˆbŒjÐAÀ2Ä=ÑQÔQ€ð"!¨°#¬ð "!ÀSð "!ÈXÐVYÌ]ð "!ð "!ð "!ð "!ð "!ð "!r=   