Ë
    ÂÓ^j¡  ã                   óV  — 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	  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y)é    N)Ú	dataclass)ÚEnumé   )Ú	constantsé   )Úvalidate_hf_hub_argsc                   ó   — e Zd ZdZdZy)ÚXetTokenTypeÚreadÚwriteN)Ú__name__Ú
__module__Ú__qualname__ÚREADÚWRITE© ó    úe/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/huggingface_hub/utils/_xet.pyr
   r
      s   „ Ø€DØ�Er   r
   T)Úfrozenc                   ó"   — e Zd ZU eed<   eed<   y)ÚXetFileDataÚ	file_hashÚrefresh_routeN)r   r   r   ÚstrÚ__annotations__r   r   r   r   r      s   … àƒNØÔr   r   ÚresponseÚendpointÚreturnc                 ó  — | €y	 | j                   t        j                     }t        j                  | j                  v r!| j                  t        j                     d   }n| j                   t        j
                     }|�|nt        j                  }|j                  t        j                  «      r>|j                  t        j                  j                  d«      |j                  d«      «      }t        ||¬«      S # t        $ r Y yw xY w)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_responser-      sê   € ð ÐØðØ×$Ñ$¤Y×%LÑ%LÑMˆ	ä×9Ñ9¸X¿^¹^ÑKØ$ŸN™N¬9×+YÑ+YÑZÐ[`Ña‰Mà$×,Ñ,¬Y×-]Ñ-]Ñ^ˆMð $Ð/‰x´Y×5GÑ5G€HØ×Ñ¤	× AÑ AÔBØ%×-Ñ-¬i×.OÑ.O×.VÑ.VÐWZÓ.[Ð]e×]lÑ]lÐmpÓ]qÓrˆÜØØ#ôð øô ò Ùðús   …A7C: Ã:	DÄD)Úrevisionr   Ú
token_typeÚrepo_idÚ	repo_typer.   c                 ó|   — |�|nt         j                  }|› d|› d|› d| j                  › d�}|dk7  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.
    z/api/zs/z/xet-z-tokenÚbucketr!   )r   r(   Úvalue)r/   r0   r1   r.   r   r    s         r   Úxet_connection_info_refresh_urlr5   :   s_   € ð4 $Ð/‰x´Y×5GÑ5G€HØˆJ�e˜I˜; b¨¨	°°z×7GÑ7GÐ6HÈÐ
O€CØ�HÒ Ð 4ð
 	��8�*ˆ~ÑˆØ€Jr   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)Ú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 | _        y ©N)Ú	threadingÚLockÚ_lockÚ_sessionÚ_session_pid©Úselfs    r   Ú__init__zXetSessionHolder.__init__g   s   € Ü—^‘^Ó%ˆŒ
ØˆŒØ(,ˆÕr   c                 ó  — | j                   5  t        j                  «       }| j                  �| j                  |k7  rd| _        | j                  €ddlm}  |«       | _        || _        | j                  cddd«       S # 1 sw Y   yxY w)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)r<   ÚosÚgetpidr=   r>   Úhf_xetrC   )r@   Úcurrent_pidrC   s      r   ÚgetzXetSessionHolder.getl   sp   € ð �Z‰Zñ 	!ÜŸ)™)›+ˆKà�}‰}Ð(¨T×->Ñ->À+Ò-Mð !%�”à�}‰}Ð$Ý-á *£�”Ø$/�Ô!à—=‘=÷	!÷ 	!ò 	!ús   �A'A>Á>Bc                 óÎ   — | j                   5  | j                  �)	 | j                  j                  «        d| _        d| _        ddd«       y# t        $ r Y Œ"w xY w# 1 sw Y   yxY w)zMAbort the current session and clear it so the next get() creates a fresh one.N)r<   r=   Úsigint_abortÚ	Exceptionr>   r?   s    r   rJ   zXetSessionHolder.sigint_abort„   sg   € à�Z‰Zñ 	)Ø�}‰}Ð(ðØ—M‘M×.Ñ.Ô0ð !%�”Ø$(�Ô!÷	)ð 	)øô !ò Ùðú÷		)ð 	)ús-   �A›AµAÁ	AÁAÁAÁAÁA$N)r   r   r   Ú__doc__rA   rH   rJ   r   r   r   r7   r7   _   s   „ ñò-ò
!ó0	)r   r7   c                  ó*   — t         j                  «       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_HOLDERrH   r   r   r   Úget_xet_sessionrO   “   s   € ô ×!Ñ!Ó#Ð#r   r"   c                 ó~   — | j                  «       D ��ci c]  \  }}|j                  «       dk7  sŒ||“Œ c}}S c c}}w )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.
    Úauthorization)ÚitemsÚlower)r"   Úkeyr4   s      r   Úxet_headers_without_authrU   �   s3   € ð *1¯©«×[™:˜3 ¸C¿I¹I»KÈ?Ó<ZˆC�‰JÓ[Ð[ùÓ[s   ”9°9c                  ó,   — t         j                  «        y)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)rN   rJ   r   r   r   Úabort_xet_sessionrW   ¦   s   € ô ×#Ñ#Õ%r   r9   )rD   r:   Údataclassesr   Úenumr   ÚhttpxÚ r   r   r   r
   r   ÚResponser-   r5   r7   rN   rO   ÚdictrU   rW   r   r   r   ú<module>r^      s  ðÛ 	Û Ý !Ý ã å Ý "ô�3˜ô ñ
 �$Ô÷ð ó ðñ
 °·±ð  È#ÐPTÉ*ð  Ð`kÐnrÑ`ró  ðF ð  Øò!àð!ð ð!ð ð	!ð
 �D‰jð!ð �D‰jð!ð 	ò!ó ð!÷H.)ñ .)ñb &Ó'Ð ò$ð\ d¨3°¨8¡nð \¸¸cÀ3¸h¹ó \ó&r   