§
    }Štjœ  ã                   ó¼  — 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Zddlm	Z	 ddlm
Z
  ej        d¦  «        Zd	ed
efd„Z G d„ dee¦  «        Z ed¬¦  «         G d„ d¦  «        ¦   «         Zd!dej        dedz  d
edz  fd„Ze
dddœdededededz  dedz  d
efd„¦   «         Z G d„ d¦  «        Z e¦   «         Zd„ Zdeeef         d
eeef         fd„Zd „ ZdS )"é    N)Ú	dataclass)ÚEnumé   )Ú	constantsé   )Úvalidate_hf_hub_argsz^[0-9a-fA-F]{64}$Úxet_hashÚreturnc                 óP   — t          t                               | ¦  «        ¦  «        S )zLReturn whether `xet_hash` looks like a real Xet content hash (64 hex chars).)ÚboolÚ_REGEX_XET_HASHÚ	fullmatch)r	   s    úX/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/huggingface_hub/utils/_xet.pyÚis_valid_xet_hashr      s   € å•×)Ò)¨(Ñ3Ô3Ñ4Ô4Ð4ó    c                   ó   — e Zd ZdZdZdS )ÚXetTokenTypeÚreadÚwriteN)Ú__name__Ú
__module__Ú__qualname__ÚREADÚWRITE© r   r   r   r      s   € € € € € Ø€DØ€E€E€Er   r   T)Úfrozenc                   ó$   — e Zd ZU eed<   eed<   dS )ÚXetFileDataÚ	file_hashÚrefresh_routeN)r   r   r   ÚstrÚ__annotations__r   r   r   r   r      s'   € € € € € € à€N€N�NØÐÐÑÐÐr   r   ÚresponseÚendpointc                 óú  — | €dS 	 | j         t          j                 }t          j        | j        v r| j        t          j                 d         }n| j         t          j                 }n# t          $ r Y dS w xY w|�|nt          j        }|                     t          j	        ¦  «        rF| 
                    t          j	                             d¦  «        |                     d¦  «        ¦  «        }t          ||¬¦  «        S )a^  
    Parse XET file metadata from an HTTP response.

    This function extracts XET file metadata from the HTTP headers or HTTP links
    of a given response object. If the required metadata is not found, it returns `None`.

    Args:
        response (`httpx.Response`):
            The HTTP response object containing headers dict and links dict to extract the XET metadata from.
    Returns:
        `Optional[XetFileData]`:
            An instance of `XetFileData` containing the file hash and refresh route if the metadata
            is found. Returns `None` if the required metadata is missing.
    NÚurlú/)r   r    )Úheadersr   ÚHUGGINGFACE_HEADER_X_XET_HASHÚ$HUGGINGFACE_HEADER_LINK_XET_AUTH_KEYÚlinksÚ&HUGGINGFACE_HEADER_X_XET_REFRESH_ROUTEÚKeyErrorÚENDPOINTÚ
startswithÚHUGGINGFACE_CO_URL_HOMEÚreplaceÚrstripr   )r#   r$   r   r    s       r   Ú!parse_xet_file_data_from_responser3       sý   € ð ÐØˆtðØÔ$¥YÔ%LÔMˆ	åÔ9¸X¼^ÐKÐKØ$œN­9Ô+YÔZÐ[`ÔaˆMˆMà$Ô,­YÔ-]Ô^ˆMøøÝð ð ð Øˆtˆtðøøøà#Ð/ˆxˆxµYÔ5G€HØ×Ò¥	Ô AÑBÔBð sØ%×-Ò-­iÔ.O×.VÒ.VÐWZÑ.[Ô.[Ð]e×]lÒ]lÐmpÑ]qÔ]qÑrÔrˆÝØØ#ðñ ô ð s   †AA& Á&
A4Á3A4)Úrevisionr$   Ú
token_typeÚrepo_idÚ	repo_typer4   c                 ól   — |�|nt           j        }|› d|› d|› d| j        › d�}|dk    s|�|d|› �z  }|S )a×  
    Build the URL used to fetch or refresh a Xet access token for a given repo.
    Args:
        token_type (`XetTokenType`):
            Type of the token to request: `"read"` or `"write"`.
        repo_id (`str`):
            A namespace (user or an organization) and a repo name separated by a `/`.
        repo_type (`str`):
            Type of the repo (e.g. `"model"`, `"dataset"`, `"space"`, `"bucket"`).
        revision (`str`, `optional`):
            The revision of the repo to get the token for.
        endpoint (`str`, `optional`):
            The endpoint to use for the request. Defaults to the Hub endpoint.
    Returns:
        `str`:
            The fully-qualified URL of the token refresh endpoint.
    Nz/api/zs/z/xet-z-tokenÚbucketr'   )r   r.   Úvalue)r5   r6   r7   r4   r$   r&   s         r   Úxet_connection_info_refresh_urlr;   C   se   € ð4 $Ð/ˆxˆxµYÔ5G€HØÐ
OÐ
O˜IÐ
OÐ
O¨Ð
OÐ
O°zÔ7GÐ
OÐ
OÐ
O€CØ�HÒÐ Ð 4ð
 	ˆ~�8ˆ~ˆ~ÑˆØ€Jr   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )ÚXetSessionHoldera7  Holds an optional XetSession; supports safe re-creation after sigint_abort or fork.

    Thread-safe: a ``threading.Lock`` guards all state mutations, which matters
    for free-threaded Python (3.14t) where multiple threads can race on ``get()``
    or ``sigint_abort()`` without the GIL serialising them.
    c                 óR   — t          j        ¦   «         | _        d | _        d | _        d S ©N)Ú	threadingÚLockÚ_lockÚ_sessionÚ_session_pid©Úselfs    r   Ú__init__zXetSessionHolder.__init__p   s&   € Ý”^Ñ%Ô%ˆŒ
ØˆŒØ(,ˆÔÐÐr   c                 óð   — | j         5  t          j        ¦   «         }| j        �| j        |k    rd| _        | j        €ddlm}  |¦   «         | _        || _        | j        cddd¦  «         S # 1 swxY w Y   dS )a  Return the current session, creating one if needed.

        Fork-safe: if the current process PID differs from the PID that created
        the session (i.e. we are in a forked child), the old session is discarded
        and a fresh session is created for this process.
        Nr   )Ú
XetSession)rB   ÚosÚgetpidrC   rD   Úhf_xetrI   )rF   Úcurrent_pidrI   s      r   ÚgetzXetSessionHolder.getu   sÍ   € ð ŒZð 	!ð 	!Ýœ)™+œ+ˆKàŒ}Ð(¨TÔ->À+Ò-MÐ-Mð !%�”àŒ}Ð$Ø-Ð-Ð-Ð-Ð-Ð-à * 
¡¤�”Ø$/�Ô!à”=ð	!ð 	!ð 	!ð 	!ñ 	!ô 	!ð 	!ð 	!ð 	!ð 	!ð 	!ð 	!øøøð 	!ð 	!ð 	!ð 	!ð 	!ð 	!s   ˆAA+Á+A/Á2A/c                 óÆ   — | j         5  | j        �9	 | j                             ¦   «          n# t          $ r Y nw xY wd| _        d| _        ddd¦  «         dS # 1 swxY w Y   dS )zMAbort the current session and clear it so the next get() creates a fresh one.N)rB   rC   Úsigint_abortÚ	ExceptionrD   rE   s    r   rP   zXetSessionHolder.sigint_abort�   sÁ   € àŒZð 	)ð 	)ØŒ}Ð(ðØ”M×.Ò.Ñ0Ô0Ð0Ð0øÝ ð ð ð Ø�Dðøøøà $�”Ø$(�Ô!ð	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)øøøð 	)ð 	)ð 	)ð 	)ð 	)ð 	)s,   ˆA‘+ªA«
8µA·8¸AÁAÁAN)r   r   r   Ú__doc__rG   rN   rP   r   r   r   r=   r=   h   sK   € € € € € ðð ð-ð -ð -ð
!ð !ð !ð0	)ð 	)ð 	)ð 	)ð 	)r   r=   c                  ó4   — t                                ¦   «         S )a*  Return the global :class:`hf_xet.XetSession`, creating it on first call.

    The session is shared across all calls within a process, just as the HTTP
    client returned by :func:`~huggingface_hub.utils._http.get_session` is shared.
    It is created lazily and is fork-safe and thread-safe.
    )Ú_GLOBAL_XET_HOLDERrN   r   r   r   Úget_xet_sessionrU   œ   s   € õ ×!Ò!Ñ#Ô#Ð#r   r(   c                 ó>   — d„ |                       ¦   «         D ¦   «         S )zßReturn a copy of headers with the authorization header removed.

    Xet storage requests use a short-lived xet access token for auth, so the
    Hub authorization header must not be forwarded to xet storage endpoints.
    c                 óJ   — i | ] \  }}|                      ¦   «         d k    ¯||“Œ!S )Úauthorization)Úlower)Ú.0Úkeyr:   s      r   ú
<dictcomp>z,xet_headers_without_auth.<locals>.<dictcomp>¬   s0   € Ð[Ð[Ð[™:˜3 ¸C¿IºI¹K¼KÈ?Ò<ZÐ<ZˆC�Ð<ZÐ<ZÐ<Zr   )Úitems)r(   s    r   Úxet_headers_without_authr^   ¦   s!   € ð \Ð[¨¯ª©¬Ð[Ñ[Ô[Ð[r   c                  ó8   — t                                ¦   «          dS )zÏAbort the global xet session after a KeyboardInterrupt.

    Cancels any in-flight Rust operation and clears the session so the next
    call to :func:`get_xet_session` starts fresh (notebook-friendly).
    N)rT   rP   r   r   r   Úabort_xet_sessionr`   ¯   s   € õ ×#Ò#Ñ%Ô%Ð%Ð%Ð%r   r?   )rJ   Úrer@   Údataclassesr   Úenumr   ÚhttpxÚ r   r   Úcompiler   r!   r   r   r   r   ÚResponser3   r;   r=   rT   rU   Údictr^   r`   r   r   r   ú<module>ri      se  ðØ 	€	€	€	Ø 	€	€	€	Ø Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð à €€€à Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "ð �"”*Ð1Ñ2Ô2€ð5 ð 5¨ð 5ð 5ð 5ð 5ð
ð ð ð ð �3˜ñ ô ð ð
 €�$ÐÑÔðð ð ð ð ñ ô ñ Ôðð
 ð  °´ð  È#ÐPTÉ*ð  Ð`kÐnrÑ`rð  ð  ð  ð  ðF ð  Øð!ð !ð !àð!ð ð!ð ð	!ð
 �D‰jð!ð �D‰jð!ð 	ð!ð !ð !ñ Ôð!ðH.)ð .)ð .)ð .)ð .)ñ .)ô .)ð .)ðb &Ð%Ñ'Ô'Ð ð$ð $ð $ð\ d¨3°¨8¤nð \¸¸cÀ3¸h¼ð \ð \ð \ð \ð&ð &ð &ð &ð &r   