Ë
    Z²j�A  ã            
       óª  — U d Z ddl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mZ ddlmZ e	j                  j!                  «       D � �ci c]  \  } }|| “Œ
 c}} Zeeef   ed	<    ej*                  d
«      Z ee	j                  j1                  «       «      Zee   ed<    ed¬«       G d„ d«      «       Z ed¬«       G d„ d«      «       Zdedefd„Zej<                  dedefd„«       Zdedefd„Z dedede!eedz  edz  f   fd„Z"dedede!e	jF                  ef   fd„Z$dede	jF                  dedefd„Z%dede	jF                  dedefd„Z&yc c}} w ) a|  Centralized parser for Hugging Face Hub URIs ('hf://...') and mount specifications.

A HF URI is a URI-like string that identifies a location on the Hugging Face
Hub: a model/dataset/space/kernel repository, a bucket, optionally a revision,
and optionally a path inside the repo or bucket.

Canonical syntax:

```
hf://[<TYPE>/]<ID>[@<REVISION>][/<PATH>]
```

A HF mount wraps a HF URI with a local mount path and an optional ':ro'/':rw'
flag (used by Spaces and Jobs volumes):

```
hf://[<TYPE>/]<ID>[@<REVISION>][/<PATH>]:<MOUNT_PATH>[:ro|:rw]
```

See 'docs/source/en/package_reference/hf_uris.md' for the full grammar and examples.
é    N)Ú	dataclassÚfield)Úunquote)Ú	constants)Ú
HfUriErrorÚHFValidationErroré   )Úvalidate_repo_idÚ_TYPE_TO_PREFIXz ^refs/(?:convert/[\w.-]+|pr/\d+)Ú_VALID_URI_TYPEST)Úfrozenc                   óÄ   — e Zd ZU dZej
                  ed<   eed<   dZedz  ed<   dZ	eed<    e
dddd¬	«      Zedz  ed
<   dd„Zedefd„«       Zedefd„«       Zdefd„Zy)ÚHfUriaé  Parsed representation of a Hugging Face Hub URI ('hf://...').

    Attributes:
        type (`str`):
            One of 'model', 'dataset', 'space', 'kernel' or 'bucket'.
        id (`str`):
            The repository id ('namespace/name', e.g. 'my-org/my-model') for repo URIs, or the bucket id ('namespace/name') for bucket URIs.
        revision (`str`, *optional*):
            The revision specified after '@' in the URI, URL-decoded. 'None' if no revision was specified, or for bucket URIs (which
            never carry a revision). Special refs like 'refs/pr/10' and 'refs/convert/parquet' are preserved as-is.
        path_in_repo (`str`):
            The path inside the repo or bucket. Empty string if the URI points at the root.
    ÚtypeÚidNÚrevisionÚ Úpath_in_repoF©ÚreprÚhashÚcompareÚdefaultÚ_rawÚreturnc           	      óþ  — | j                   xs d}| j                  t        vr+t        |d| j                  › dt	        t        «      › d�¬«      ‚| j
                  r| j
                  j                  d«      dk7  rt        |d| j
                  › d	�¬«      ‚| j                  d
k7  r	 t        | j
                  «       | j                  �| j                  st        |d¬«      ‚| j                  d
k(  r| j                  �t        |d¬«      ‚| j                  rE| j                  j                  d«      sd| j                  v rt        |d| j                  › d�¬«      ‚y y # t        $ r}t        |t        |«      ¬«      |‚d }~ww xY w)Nr   zInvalid type 'z'. Must be one of ú.©ÚuriÚmsgú/r	   z"Id must be 'namespace/name', got 'ú'.Úbucketz%Revision must not be an empty string.z&Bucket URIs do not support a revision.z//z+Path must not contain empty segments (got 'z').)r   r   r   r   Úsortedr   Úcountr
   r   Ústrr   r   Ú
startswith)Úselfr   Úes      ú]/var/www/html/ia-enhanced/venv/lib/python3.12/site-packages/huggingface_hub/utils/_hf_uris.pyÚ__post_init__zHfUri.__post_init__T   s]  € Ø�i‰iŠo˜2ˆð �9‰9Ô,Ñ,Ü ¨N¸4¿9¹9¸+ÐEWÔX^Ô_oÓXpÐWqÐqrÐ*sÔtÐtð �wŠw˜$Ÿ'™'Ÿ-™-¨Ó,°Ò1Ü Ð,NÈtÏwÉwÈiÐWYÐ*ZÔ[Ð[Ø�9‰9˜Ò ð=Ü  §¡Ô)ð
 �=‰=Ð$¨T¯]ª]Ü Ð*QÔRÐRØ�9‰9˜Ò  T§]¡]Ð%>Ü Ð*RÔSÐSð ×ÒØ× Ñ ×+Ñ+¨CÔ0°D¸D×<MÑ<MÑ4MÜ  SÐ0[Ð\`×\mÑ\mÐ[nÐnqÐ.rÔsÐsð 5Nð øô %ò =Ü  S¬c°!«fÔ5¸1Ð<ûð=ús   Â#E Å	E<Å E7Å7E<c                 ó    — | j                   dk(  S )z$True if this URI points at a bucket.r#   ©r   ©r(   s    r*   Ú	is_bucketzHfUri.is_bucketo   ó   € ð �y‰y˜HÑ$Ð$ó    c                 ó    — | j                   dk7  S )zJTrue if this URI points at a repository (model, dataset, space or kernel).r#   r-   r.   s    r*   Úis_repozHfUri.is_repot   r0   r1   c                 ó„  — t         j                  t        | j                     d| j                  g}| j
                  �K| j
                  }d|v r't        j                  |«      €|j                  dd«      }|j                  d|› �«       | j                  r|j                  d| j                  › �«       dj                  |«      S )z’Render the URI as a canonical 'hf://' string.

        The type prefix is always written explicitly (e.g. 'hf://models/my-org/my-model').
        r!   z%2Fú@r   )r   ÚHF_PROTOCOLr   r   r   r   Ú_SPECIAL_REFS_REVISION_REGEXÚ	fullmatchÚreplaceÚappendr   Újoin)r(   Úpartsr   s      r*   Úto_urizHfUri.to_uriy   sª   € ô
 &×1Ñ1´?À4Ç9Á9Ñ3MÈsÐTX×T[ÑT[Ð\ˆØ�=‰=Ð$ð —}‘}ˆHØ�h‰Ô#?×#IÑ#IÈ(Ó#SÐ#[Ø#×+Ñ+¨C°Ó7�Ø�L‰L˜1˜X˜J˜Ô(Ø×ÒØ�L‰L˜1˜T×.Ñ.Ð/Ð0Ô1Ø�w‰w�u‹~Ðr1   ©r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú	HfUriTypeÚ__annotations__r&   r   r   r   r   r+   ÚpropertyÚboolr/   r3   r=   © r1   r*   r   r   >   s“   … ñð ×
Ñ
ÓØƒGØ€Hˆc�D‰jÓØ€L�#ÓÙ %¨e¸UÈDÔQ€Dˆ#�‰*ÓQótð6 ð%˜4ò %ó ð%ð ð%˜ò %ó ð%ð˜ô r1   r   c                   óv   — e Zd ZU dZeed<   eed<   dZedz  ed<    e	dddd¬«      Z
edz  ed<   dd
„Zd	efd„Zy)ÚHfMountaF  A HF URI paired with a local mount path and optional read-only flag.

    Used by Spaces and Jobs to describe volume mounts. The full syntax is:

    ```
    hf://[<TYPE>/]<ID>[@<REVISION>][/<PATH>]:<MOUNT_PATH>[:ro|:rw]
    ```

    Attributes:
        source ([`HfUri`]):
            The parsed HF URI identifying the Hub resource to mount.
        mount_path (`str`):
            The local mount path (always starts with '/').
        read_only (`bool`, *optional*):
            True if the mount ends with ':ro', False if it ends with ':rw', 'None' if no flag was provided.
    ÚsourceÚ
mount_pathNÚ	read_onlyFr   r   r   c                 ó®   — | j                   xs d}| j                  j                  d«      r| j                  dk(  rt        |d| j                  › d�¬«      ‚y )Nr   r!   zEMount path must be a non-empty absolute path starting with '/', got 'r"   r   )r   rK   r'   r   )r(   Úraws     r*   r+   zHfMount.__post_init__¤   sW   € Ø�i‰iŠo˜2ˆØ�‰×)Ñ)¨#Ô.°$·/±/ÀSÒ2HÜØØ[Ð\`×\kÑ\kÐ[lÐlnÐoôð ð 3Ir1   c                 óÈ   — | j                   j                  «       d| j                  g}| j                  �|j	                  | j                  rdnd«       dj                  |«      S )zqRender the mount as a canonical 'hf://' string.

        Example: 'hf://models/my-org/my-model:/data:ro'
        ú:ú:roú:rwr   )rJ   r=   rK   rL   r:   r;   )r(   r<   s     r*   r=   zHfMount.to_uri¬   sM   € ð
 —‘×#Ñ#Ó% s¨D¯O©OÐ<ˆØ�>‰>Ð%Ø�L‰L $§.¢.™°eÔ<Ø�w‰w�u‹~Ðr1   r>   )r?   r@   rA   rB   r   rD   r&   rL   rF   r   r   r+   r=   rG   r1   r*   rI   rI   Œ   sK   … ñð" ƒMØƒOØ!€Iˆt�d‰{Ó!Ù %¨e¸UÈDÔQ€Dˆ#�‰*ÓQóð˜ô r1   rI   r   r   c                 ó:   — 	 t        | «       y# t        $ r Y yw xY w)z'Check if a string is a valid hf:// URI.TF)Úparse_hf_urir   )r   s    r*   Ú	is_hf_urirU   ·   s$   € ðÜ�SÔØøÜò Ùðús   ‚ Ž	™c                 ó|  — | j                  t        j                  «      s/t        | dt        j                  › dt        j                  › d�«      ‚| }| t	        t        j                  «      d }|st        | dt        j                  › d�«      ‚t        ||¬«      \  }}|dk(  rt        |||¬«      S t        |||¬«      S )	aÊ  Parse a Hugging Face Hub URI ('hf://...').

    A HF URI is a URI-like string identifying a location on the Hugging Face Hub. The full grammar is:

    ```
    hf://[<TYPE>/]<ID>[@<REVISION>][/<PATH>]
    ```

    See 'docs/source/en/package_reference/hf_uris.md' for the full specification.

    Args:
        uri (`str`):
            The URI to parse. Must start with 'hf://'.

    Returns:
        [`HfUri`]: the parsed URI.

    Raises:
        [`HfUriError`]:
            If the URI is malformed (missing prefix, invalid type, missing id, etc.).

    Examples:
        ```py
        >>> from huggingface_hub.utils import parse_hf_uri
        >>> parse_hf_uri("hf://my-org/my-model")
        HfUri(type='model', id='my-org/my-model', revision=None, path_in_repo='')
        >>> parse_hf_uri("hf://datasets/my-org/my-dataset@refs/pr/3/train.json")
        HfUri(type='dataset', id='my-org/my-dataset', revision='refs/pr/3', path_in_repo='train.json')
        ```
    úMust start with 'z'. Expected format: z#[<TYPE>/]<ID>[@<REVISION>][/<PATH>]NúEmpty body after 'r"   ©rN   r#   )r'   r   r6   r   ÚlenÚ_split_typeÚ_parse_bucket_bodyÚ_parse_repo_body)r   rN   ÚbodyÚtype_Úlocations        r*   rT   rT   À   sÅ   € ð@ �>‰>œ)×/Ñ/Ô0ÜØØ¤	× 5Ñ 5Ð6ð 7 Ü )× 5Ñ 5Ð6Ð6Yð[ó
ð 	
ð €CØŒs”9×(Ñ(Ó)Ð+Ð,€DÙÜ˜Ð 2´9×3HÑ3HÐ2IÈÐLÓMÐMä! $¨CÔ0�O€Eˆ8à�ÒÜ! (¨E°sÔ;Ð;Ü˜H e°Ô5Ð5r1   Ú	mount_strc                 óê  — | j                  t        j                  «      st        | dt        j                  › d�¬«      ‚| }| t	        t        j                  «      d }|st        |dt        j                  › d�¬«      ‚t        ||¬«      \  }}}|€t        |d¬«      ‚t        j                  |z   }	 t        |«      }t        ||||¬«      S # t        $ r}t        ||j                  ¬«      |‚d}~ww xY w)	a·  Parse a HF mount specification ('hf://...:<MOUNT_PATH>[:ro|:rw]').

    A mount specification is a HF URI followed by a local mount path and an optional read-only/read-write flag.
    The full grammar is:

    ```
    hf://[<TYPE>/]<ID>[@<REVISION>][/<PATH>]:<MOUNT_PATH>[:ro|:rw]
    ```

    See 'docs/source/en/package_reference/hf_uris.md' for the full specification.

    Args:
        mount_str (`str`):
            The mount string to parse. Must start with 'hf://' and contain a ':<MOUNT_PATH>' segment.

    Returns:
        [`HfMount`]: the parsed mount.

    Raises:
        [`HfUriError`]:
            If the mount string is malformed (missing mount path, invalid URI, etc.).

    Examples:
        ```py
        >>> from huggingface_hub.utils import parse_hf_mount
        >>> parse_hf_mount("hf://my-org/my-model:/data:ro")
        HfMount(source=HfUri(type='model', id='my-org/my-model', revision=None, path_in_repo=''), mount_path='/data', read_only=True)
        >>> parse_hf_mount("hf://buckets/my-org/my-bucket/sub/dir:/mnt:rw")
        HfMount(source=HfUri(type='bucket', id='my-org/my-bucket', revision=None, path_in_repo='sub/dir'), mount_path='/mnt', read_only=False)
        ```
    rW   r"   r   NrX   rY   zKMissing mount path. Expected ':<MOUNT_PATH>' (e.g. 'hf://org/model:/data').)rJ   rK   rL   r   )	r'   r   r6   r   rZ   Ú_split_mountrT   r    rI   )	ra   rN   r^   r`   rK   rL   Úuri_strrJ   r)   s	            r*   Úparse_hf_mountre   ó   sþ   € ð@ ×Ñ¤	× 5Ñ 5Ô6ÜØØ#¤I×$9Ñ$9Ð#:¸"Ð=ô
ð 	
ð
 €CØ”Sœ×.Ñ.Ó/Ð1Ð2€DÙÜ˜SÐ(:¼9×;PÑ;PÐ:QÐQSÐ&TÔUÐUä&2°4¸SÔ&AÑ#€Hˆj˜)àÐÜ˜SÐ&sÔtÐtô ×#Ñ# hÑ.€Gð4Ü˜gÓ&ˆô ˜&¨ZÀ9ÐSVÔWÐWøô ò 4Ü˜S a§e¡eÔ,°!Ð3ûð4ús   Â2C Ã	C2ÃC-Ã-C2r^   rN   c                ó0  — | j                  d«      rd| j                  d«      } }n'| j                  d«      rd| j                  d«      } }nd}| j                  d«      }|dk(  r|�t        |d¬	«      ‚| ddfS | d| }| |d
z   d }|st        |d¬	«      ‚|||fS )z©Split the ':<MOUNT_PATH>[:ro|:rw]' suffix from 'body'.

    Returns '(location, mount_path, read_only)' where 'mount_path' is 'None' if no mount segment is present.
    rQ   TrR   FNz:/éÿÿÿÿzb':ro'/':rw' suffix is only valid when a mount path is provided (e.g. 'hf://...:/<MOUNT_PATH>:ro').r   r	   z#Missing location before mount path.)ÚendswithÚremovesuffixÚrfindr   )r^   rN   rL   Úidxr`   rK   s         r*   rc   rc   -  sÀ   € ð
 ‡}�}�UÔØ × 1Ñ 1°%Ó 8�4‰	Ø	�‰�uÔ	Ø ×!2Ñ!2°5Ó!9�4‰	àˆ	ð �*‰*�TÓ
€CØ
ˆb‚yØÐ ÜØØxôð ð �T˜4ÐÐà�D�Sˆz€HØ�c˜A‘g�i�€JÙÜ˜SÐ&KÔLÐLØ�Z Ð*Ð*r1   r`   c          	      óØ  — | j                  d«      }|dk(  rr| t        j                  v r$t        |d| › dt        j                  › | › d�¬«      ‚t
        j                  | «      x}�!t        |dt        j                  › |› d	�¬«      ‚d
| fS | d| }| |dz   d }|t        j                  v rt        j                  |   |fS t
        j                  |«      x}�t        |d|› d|› d�¬«      ‚d
| fS )zÙDetect the (optional) type prefix and return '(type, remaining_location)'.

    A missing type prefix defaults to 'model'. Singular forms ('model/', 'dataset/', etc.) are explicitly rejected with a helpful error.
    r!   rg   zMissing identifier after 'z'. Expected 'z/<ID>'.r   Nz*Type prefix must be plural. Did you mean 'z/...'?Úmodelr	   z!Type prefix must be plural, got 'z/'. Did you mean 'z/'?)Úfindr   ÚHF_URI_TYPE_PREFIXESr   r6   r   Úget)r`   rN   Ú	slash_idxÚsingular_pluralÚfirstÚrests         r*   r[   r[   K  s/  € ð
 —‘˜cÓ"€IØ�B‚à”y×5Ñ5Ñ5ÜØØ0°°
¸-Ì	×H]ÑH]ÐG^Ð_gÐ^hÐhoÐpôð ô  /×2Ñ2°8Ó<Ð<ˆOÐIÜØØ@Ä×AVÑAVÐ@WÐXgÐWhÐhnÐoôð ð ˜Ð Ð à�Z�iÐ €EØ�I ‘M�OÐ$€DØ”	×.Ñ.Ñ.Ü×-Ñ-¨eÑ4°dÐ:Ð:Ü*×.Ñ.¨uÓ5Ð5ˆÐBÜØÐ<¸U¸GÐCUÐVeÐUfÐfiÐjô
ð 	
ð �HÐÐr1   r_   c                ó   — | j                  d«      } | j                  dd«      }t        |«      dk  s
|d   r|d   st        |d| › d�¬«      ‚|d   › d|d   › �}d|v rt        |d	¬«      ‚t        |«      d
k\  r|d   nd}t	        ||d||¬«      S )z8Parse the body of a bucket URI: 'namespace/name[/path]'.r!   é   r   r	   z)Bucket id must be 'namespace/name', got 'r"   r   r5   z3Bucket URIs do not support a revision marker ('@').é   r   N©r   r   r   r   r   )ÚstripÚsplitrZ   r   r   )r`   r_   rN   r<   Ú	bucket_idÚpath_in_buckets         r*   r\   r\   j  s²   € ð �~‰~˜cÓ"€HØ�N‰N˜3 Ó"€EÜ
ˆ5ƒz�A‚~˜U 1šX¨U°1ªXÜ˜SÐ(QÐRZÐQ[Ð[]Ð&^Ô_Ð_Ø˜‘8�*˜A˜e A™h˜ZÐ(€IØ
ˆiÑÜ˜SÐ&[Ô\Ð\Ü!$ U£¨q¢�U˜1’X°b€NÜØØØØ#Øôð r1   c                óø  — | j                  d«      } | st        |d¬«      ‚| j                  d«      }|dk(  s| d| j                  d«      dkD  rVd}| j	                  dd«      }t        |«      dk  rt        |d	| › d
�¬«      ‚|d   › d|d   › �}t        |«      dkD  r|d   nd}nÈ| d| }| |dz   d }|st        |d¬«      ‚|j                  d«      dk7  rt        |d	|› d�¬«      ‚t        j                  |«      }	|	�.|	j                  «       }|t        |«      d j                  d«      }n(|j                  d«      }
|
dk(  r|}d}n|d|
 }||
dz   d }t        |«      }|st        |d¬«      ‚t        |||||¬«      S )z@Parse the body of a repo URI: '<repo_id>[@<revision>][/<path>]'.r!   zMissing repository id.r   r5   rg   Nr	   rv   z-Repository id must be 'namespace/name', got 'z'. r   r   z!Missing repository id before '@'.r"   zEmpty revision after '@'.rx   )ry   r   rn   r%   rz   rZ   r7   ÚmatchÚgroupÚremoveprefixr   r   )r`   r_   rN   Úat_idxr   r<   Úrepo_idr   Úrev_and_pathr~   rq   s              r*   r]   r]   ‚  sÆ  € ð �~‰~˜cÓ"€HÙÜ˜SÐ&>Ô?Ð?ð
 �]‰]˜3Ó€Fð �‚|�x  Ð(×.Ñ.¨sÓ3°aÒ7àˆØ—‘˜s AÓ&ˆÜˆu‹:˜Š>Ü Ð,YÐZbÐYcÐcfÐ*gÔhÐhØ˜1‘X�J˜a  a¡˜zÐ*ˆÜ#& u£:°¢>�u˜Q’x°r‰à˜7˜FÐ#ˆØ ¨¡
 Ð-ˆÙÜ Ð*MÔNÐNØ�=‰=˜Ó Ò"Ü Ð,YÐZaÐYbÐbdÐ*eÔfÐfô -×2Ñ2°<Ó@ˆØÐØ—{‘{“}ˆHØ'¬¨H«¨Ð8×EÑEÀcÓJ‰Là$×)Ñ)¨#Ó.ˆIØ˜BŠØ'�Ø!‘à'¨
¨Ð3�Ø+¨I¸©M¨OÐ<�Ü˜8Ó$ˆÙÜ Ð*EÔFÐFäØØØØ!Øôð r1   )'rB   Ú	functoolsÚreÚdataclassesr   r   Úurllib.parser   Úhuggingface_hubr   Úhuggingface_hub.errorsr   r   Ú_validatorsr
   ro   Úitemsr   Údictr&   rD   Úcompiler7   Ú	frozensetÚvaluesr   r   rI   rF   rU   Ú	lru_cacherT   re   Útuplerc   rC   r[   r\   r]   )ÚkÚvs   00r*   ú<module>r”      sá  ðòó, Û 	ß (Ý  å %ß @å )ð
 5>×4RÑ4R×4XÑ4XÓ4Z×"[©D¨A¨q 1 a¡4Ó"[€��c˜3�h‘Ó [ð  *˜rŸz™zÐ*MÓNÐ ñ $-¨Y×-KÑ-K×-RÑ-RÓ-TÓ#UÐ �)˜C‘.Ó Uñ �$Ô÷Jð Jó ðJñZ �$Ô÷'ð 'ó ð'ðT�3ð ˜4ó ð ×Ñð/6�cð /6˜eò /6ó ð/6ðd7X˜cð 7X gó 7Xðt+�sð + Cð +¨E°#°s¸T±zÀ4È$Á;Ð2NÑ,Oó +ð<˜#ð  sð ¨u°Y×5HÑ5HÈ#Ð5MÑ/Nó ð>Øðà×Ñðð 
ð	ð
 óð08Øð8à×Ñð8ð 
ð	8ð
 ô8ùóc
 #\s   ÁE