
    3jc              
       4   % S r SSKrSSKrSSKJrJr  SSKJrJrJ	r	  SSK
Jr  SSKJrJr  SSKJr  \R"                  R%                  5        V Vs0 s H  u  pX_M	     snn r\\\4   \S	'   \R.                  " S
5      r\" \R"                  R5                  5       5      r\\   \S'   \" 1 Sk5      r\\   \S'   \" SS15      r\\   \S'   \" SS9 " S S5      5       r\" SS9 " S S5      5       rS\S\ 4S jr!\RD                  S\S\4S j5       r#S\S\ 4S jr$S\S\4S jr%S\S\4S jr&S \S\4S! jr'S"\S#\S\(\\S-  \ S-  4   4S$ jr)S%\S#\S\(\RT                  \4   4S& jr+S%\S'\RT                  S#\S\4S( jr,S%\S'\RT                  S#\S\4S) jr-gs  snn f )*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>]
```

For convenience, [`parse_hf_uri`] also accepts Hugging Face **web URLs** (the
ones you copy-paste from your browser), e.g.
'https://huggingface.co/datasets/my-org/my-dataset/blob/main/train.csv'. They are
normalized to the canonical 'hf://' form before parsing. Only unambiguous URLs
(repository / bucket pages and file/folder viewer routes) are accepted; any other
route is rejected rather than guessed.

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)quoteunquoteurlsplit)	constants)
HfUriErrorHFValidationError   )validate_repo_id_TYPE_TO_PREFIXz ^refs/(?:convert/[\w.-]+|pr/\d+)_VALID_URI_TYPES>   rawblobtreeblameresolve_URL_REPO_LOCATION_ACTIONSr   r   _URL_BUCKET_LOCATION_ACTIONST)frozenc                       \ rS rSr% Sr\R                  \S'   \\S'   Sr	\S-  \S'   Sr
\\S'   \" S	S	S	SS
9r\S-  \S'   SS jr\S\4S j5       r\S\4S j5       rS\4S jrSS\S-  S\4S jjrSrg)HfUriN   a  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           	          U R                   =(       d    SnU R                  [        ;  a(  [        USU R                   S[	        [        5       S3S9eU R
                  (       a  U R
                  R                  S5      S:w  a  [        USU R
                   S	3S9eU R                  S
:w  a   [        U R
                  5        U R                  b  U R                  (       d
  [        USS9eU R                  S
:X  a  U R                  b
  [        USS9eU R                  (       aI  U R                  R                  S5      (       d  SU R                  ;   a  [        USU R                   S3S9eg g ! [         a  n[        U[        U5      S9UeS nAff = f)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+Path must not contain empty segments (got 'z').)r$   r   r   r	   sortedr   countr   r
   strr   r   
startswith)selfr)   es      X/home/wildlama/miniconda3/lib/python3.13/site-packages/huggingface_hub/utils/_hf_uris.py__post_init__HfUri.__post_init__d   s`   iio2 99,,N499+EWX^_oXpWqqr*stt ww$''--,1,NtwwiWY*Z[[99 = )
 ==$T]]*QRR99 T]]%>*RSS   ++C00DD<M<M4M S0[\`\m\m[nnq.rss 5N  % = Sc!f51<=s   +E* *
F4FFc                      U R                   S:H  $ )z$True if this URI points at a bucket.r-   r   r3   s    r5   	is_bucketHfUri.is_bucket        yyH$$    c                      U R                   S:g  $ )zJTrue if this URI points at a repository (model, dataset, space or kernel).r-   r9   r:   s    r5   is_repoHfUri.is_repo   r=   r>   c                    [         R                  [        U R                     SU R                  /nU R
                  bN  U R
                  nSU;   a(  [        R                  U5      c  UR                  SS5      nUR                  SU 35        U R                  (       a  UR                  SU R                   35        SR                  U5      $ )zRender the URI as a canonical 'hf://' string.

The type prefix is always written explicitly (e.g. 'hf://models/my-org/my-model').
r+   %2F@r   )r   HF_PROTOCOLr   r   r   r   _SPECIAL_REFS_REVISION_REGEX	fullmatchreplaceappendr   join)r3   partsr   s      r5   to_uriHfUri.to_uri   s    
 &11?4993MsTXT[T[\==$ }}Hh#?#I#I(#S#[#++C7LL1XJ(LL1T../01wwu~r>   endpointc                 T   U=(       d    [         R                  R                  S5      n[        U R                  SS9nU R
                  S:X  a"  U SU R                   3nU(       a  USU 3-  nU$ U R
                  S:X  a  U SU R                   3O$U S[        U R
                      SU R                   3nU R                  nUb.  SU;   a(  [        R                  U5      c  UR                  SS5      nU(       a$  USU=(       d    [         R                   SU 3-  nU$ Ub  USU 3-  nU$ )	ay  Render the URI as a Hugging Face **web URL** (the kind you open in a browser).

This is the inverse of parsing a URL with [`parse_hf_uri`]. The returned URL points at:

- the repository / bucket landing page when no path or revision is set;
- the folder viewer ('/tree/<revision>') when only a revision is set;
- the file viewer ('/blob/<revision>/<path>') for repository files (revision defaults to 'main');
- the tree route ('/tree/<path>') for bucket files (buckets are not versioned).

Args:
    endpoint (`str`, *optional*):
        Base endpoint to use. Defaults to 'constants.ENDPOINT' (i.e. 'https://huggingface.co').

Returns:
    `str`: the web URL.

Example:
    ```py
    >>> from huggingface_hub import parse_hf_uri
    >>> parse_hf_uri("hf://datasets/my-org/my-dataset@v1/train.csv").to_url()
    'https://huggingface.co/datasets/my-org/my-dataset/blob/v1/train.csv'
    ```
r+   )safer-   z	/buckets/z/tree/modelrC   z/blob/)r   ENDPOINTrstripr   r   r   r   r   r   rF   rG   rH   DEFAULT_REVISION)r3   rN   basepathurlr   s         r5   to_urlHfUri.to_url   s;   0 .I..66s; T&&S199 F)DGG9-Cv&J &*YY'%9ay!$qY]YbYbIcHddefjfmfmen?o== C8O8T8^8^_g8h8p''U3HVHB	(B(BC1TFKKC 
 !VH:&&C
r>    r%   NN)__name__
__module____qualname____firstlineno____doc__r   	HfUriType__annotations__r1   r   r   r   r$   r6   propertyboolr;   r@   rL   rX   __static_attributes__rZ   r>   r5   r   r   N   s     

GHcDjL#%eUDQD#*Qt6 %4 % % % % % $.sTz .S . .r>   r   c                   |    \ rS rSr% Sr\\S'   \\S'   Sr\	S-  \S'   \
" SSSSS9r\S-  \S	'   SS jrS
\4S jrSrg)HfMount   a  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                     U R                   =(       d    SnU R                  R                  S5      (       a  U R                  S:X  a  [        USU R                   S3S9eg )Nr   r+   zEMount path must be a non-empty absolute path starting with '/', got 'r,   r(   )r$   rk   r2   r	   )r3   r   s     r5   r6   HfMount.__post_init__   sZ    iio2))#..$//S2H[\`\k\k[llno  3Ir>   c                     U R                   R                  5       SU R                  /nU R                  b$  UR	                  U R                  (       a  SOS5        SR                  U5      $ )zaRender the mount as a canonical 'hf://' string.

Example: 'hf://models/my-org/my-model:/data:ro'
::ro:rwr   )rj   rL   rk   rl   rI   rJ   )r3   rK   s     r5   rL   HfMount.to_uri   sM    
 ##%sDOO<>>%LL$..e<wwu~r>   rZ   r[   )r]   r^   r_   r`   ra   r   rc   r1   rl   re   r   r$   r6   rL   rf   rZ   r>   r5   rh   rh      sK    " MO!Itd{!%eUDQD#*Q r>   rh   r)   r%   c                 <     [        U 5        g! [         a     gf = f)zVCheck if a string is a valid HF URI ('hf://...') or a recognized Hugging Face web URL.TF)parse_hf_urir	   )r)   s    r5   	is_hf_urirv      s$    S s    
c                    U nU R                  [        R                  5      (       aB  U [        [        R                  5      S nU(       d  [	        U S[        R                   S35      eOK[        U 5      (       a  [        U 5      nO/[	        U S[        R                   S[        R                   S35      e[        X!S9u  p4US:X  a
  [        XCUS9$ [        XCUS9$ )	a  Parse a Hugging Face Hub URI ('hf://...') or a Hugging Face web URL.

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>]
```

For convenience, Hugging Face **web URLs** (the ones you copy-paste from the website) are also
accepted and normalized to the canonical 'hf://' form, e.g.
'https://huggingface.co/datasets/my-org/my-dataset/blob/main/train.csv'. Only unambiguous URLs
(repository / bucket pages and file/folder viewer routes) are accepted; any other route is rejected.

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

Args:
    uri (`str`):
        The URI to parse. Must start with 'hf://', or be a Hugging Face URL (e.g. 'https://huggingface.co/...').

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

Raises:
    [`HfUriError`]:
        If the URI is malformed (missing prefix, invalid type, missing id, unsupported URL route, 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')
    >>> parse_hf_uri("https://huggingface.co/datasets/my-org/my-dataset/blob/main/train.csv")
    HfUri(type='dataset', id='my-org/my-dataset', revision='main', path_in_repo='train.csv')
    ```
NEmpty body after 'r,   Must start with 'zQ' or be a Hugging Face URL (e.g. 'https://huggingface.co/...'). Expected format: z#[<TYPE>/]<ID>[@<REVISION>][/<PATH>]r   r-   )
r2   r   rE   lenr	   _looks_like_hf_url_url_to_uri_body_split_type_parse_bucket_body_parse_repo_body)r)   r   bodytype_locations        r5   ru   ru      s    N C
~~i++,,3y,,-/0S$6y7L7L6MR"PQQ 	C	 	 $	 5 56 7  ) 5 566Y[
 	
 "$0OE!(s;;H55r>   c                    ^ U R                  5       mTR                  S5      (       a  g[        U4S j[        R                   5       5      $ )zNReturn True if 'uri' looks like a (possibly scheme-less) Hugging Face web URL.)zhttp://zhttps://Tc              3   d   >#    U  H%  nTU:H  =(       d    TR                  US -   5      v   M'     g7f)r+   N)r2   ).0hostlowereds     r5   	<genexpr>%_looks_like_hf_url.<locals>.<genexpr>B  s.     dMcTw$@'"4"4TCZ"@@Mcs   -0)lowerr2   anyr   HF_URL_HOSTS)r)   r   s    @r5   r|   r|   <  s:    iikG122dYMcMcdddr>   segmentc                 8    [        U 5      R                  SS5      $ )ag  Percent-decode a single URL path segment (e.g. 'file%20name.txt' -> 'file name.txt').

A decoded '/' is re-encoded as '%2F' so the segment stays atomic when the normalized body is
re-split by the shared parser. This decodes ordinary path characters (spaces, '#', ...) that
browsers encode, while keeping '%2F'-encoded revisions (e.g. 'feature%2Ffoo') intact.
r+   rC   )r   rH   )r   s    r5   _decode_url_path_segmentr   E  s     7##C//r>   rW   c                    U n[        SU ;   a  U OSU -   5      nUR                  =(       d    SR                  5       nU[        R                  ;  a  [        USU=(       d    U  S3S9eUR                  R                  S5       Vs/ s H  oD(       d  M  UPM     nnU(       d  [        USU  S	3S9eS
nUS   [        R                  ;   a
  US   nUSS
 n[        U5      S:  a  [        USU  S3S9eUS    SUS    3nUSS
 nUS:X  aV  U(       d  SU 3$ UtpU	[        ;  a  [        USU  SU	 S3S9eSR                  S U
 5       5      nU(       a  SU SU 3$ SU 3$ U(       a  U S3OSnU(       d  U U 3$ UtpU	[        ;  a  [        USU  SU	 S3S9eU
(       d  U U 3$ SR                  S U
 5       5      nU U SU 3$ s  snf )a^  Normalize a Hugging Face web URL into the body of a 'hf://' URI (everything after 'hf://').

The returned string is fed back into the regular URI parsing logic, so all validation
(repo id, revision, empty path segments, ...) is shared with the canonical 'hf://' path.
Only unambiguous URLs are accepted: any unrecognized route raises [`HfUriError`].
z://r.   r   zUnrecognized host 'zC'. Expected a Hugging Face URL (e.g. 'https://huggingface.co/...').r(   r+   z0Missing repository or bucket identifier in URL 'r,   Nr   r      zCannot parse URL 'z{': expected a '<namespace>/<name>' repository or bucket. User/organization pages and single-segment URLs are not supported.bucketszbuckets/zCannot parse bucket URL 'z': unsupported '/z	/' route.c              3   8   #    U  H  n[        U5      v   M     g 7fr\   r   r   r   s     r5   r   #_url_to_uri_body.<locals>.<genexpr>~  s     Ng099   zl/' route. Only repository pages and file/folder viewer routes (blob, resolve, raw, tree, ...) can be parsed.c              3   8   #    U  H  n[        U5      v   M     g 7fr\   r   r   s     r5   r   r     s     MW/88r   rD   )r   hostnamer   r   r   r	   rV   splitHF_URI_TYPE_PREFIXESr{   r   rJ   r   )rW   r   parsedr   r   segmentstype_prefixrepo_idrestactiontailrV   prefixdecodeds                 r5   r}   r}   O  sO    CUc\ctcz:FOO!r((*D9)))%dkc]2uv
 	
 (.{{'8'8'=I'=G'=HIS(XY\X]]_&`aa #K{i444qkAB< 8}q$SE *U U
 	
 !Qx{m,GAB<DigY''55,EcUJ[\b[ccl*mnnxxNNN.2'!D6*L(7)8LL"-}A2F'##MF//$SE):6( Cu u
 	
 '##
 hhMMMGXgYay))i Js   
GG	mount_strc                    U R                  [        R                  5      (       d  [        U S[        R                   S3S9eU nU [	        [        R                  5      S nU(       d  [        US[        R                   S3S9e[        X!S9u  p4nUc
  [        USS9e[        R                  U-   n [        U5      n[        XtXQS9$ ! [         a  n[        XR                  S9UeSnAff = f)	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)
    ```
ry   r,   r(   Nrx   rz   zKMissing mount path. Expected ':<MOUNT_PATH>' (e.g. 'hf://org/model:/data').)rj   rk   rl   r$   )	r2   r   rE   r	   r{   _split_mountru   r*   rh   )	r   r   r   r   rk   rl   uri_strrj   r4   s	            r5   parse_hf_mountr     s    @ 	 5 566#I$9$9#:"=
 	

 CS../12DS(:9;P;P:QQS&TUU&24&A#H)S&stt ##h.G4g& &9WW  4See,!34s   /C 
C'C""C'r   r   c                >   U R                  S5      (       a  SU R                  S5      pO+U R                  S5      (       a  SU R                  S5      pOSnU R                  S5      nUS:X  a  Ub
  [        USS	9eU SS4$ U SU nXS
-   S nU(       d
  [        USS	9eXEU4$ )zSplit 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   r   rl   idxr   rk   s         r5   r   r     s    
 }}U 1 1% 84	u		!2!25!94	 **T
C
by x  T4DSzHAgiJS&KLL**r>   r   c          	         U R                  S5      nUS:X  ao  U [        R                  ;   a!  [        USU  S[        R                   U  S3S9e[
        R                  U 5      =nb  [        US[        R                   U S	3S9eS
U 4$ U SU nXS-   S nU[        R                  ;   a  [        R                  U   U4$ [
        R                  U5      =nb  [        USU SU S3S9eS
U 4$ )zDetect 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+   r   zMissing identifier after 'z'. Expected 'z/<ID>'.r(   Nz*Type prefix must be plural. Did you mean 'z/...'?rQ   r   z!Type prefix must be plural, got 'z/'. Did you mean 'z/'?)findr   r   r	   rE   r   get)r   r   	slash_idxsingular_pluralfirstr   s         r5   r~   r~     s-   
 c"IBy5550
-	H]H]G^_g^hhop   /228<<OI@AVAV@WXgWhhno    Zi EMO$D	...--e4d::*..u55B<UGCUVeUffij
 	
 Hr>   r   c                *   U R                  S5      n U R                  SS5      n[        U5      S:  d  US   (       a
  US   (       d  [        USU  S3S9eUS    SUS    3nSU;   a
  [        US	S9e[        U5      S
:  a  US   OSn[	        UUSUUS9$ )z8Parse the body of a bucket URI: 'namespace/name[/path]'.r+   r   r   r   z)Bucket id must be 'namespace/name', got 'r,   r(   rD   z3Bucket URIs do not support a revision marker ('@').   r   Nr   r   r   r   r$   )stripr   r{   r	   r   )r   r   r   rK   	bucket_idpath_in_buckets         r5   r   r     s     ~~c"HNN3"E
5zA~U1XU1XS(QRZQ[[]&^__8*AeAhZ(I
iS&[\\!$UqU1XbN# r>   c                   U R                  S5      n U (       d
  [        USS9eU R                  S5      nUS:X  d  U SU R                  S5      S:  aU  SnU R	                  SS5      n[        U5      S:  a  [        US	U  S
3S9eUS    SUS    3n[        U5      S:  a  US   OSnOU SU nXS-   S nU(       d
  [        USS9eUR                  S5      S:w  a  [        US	U S3S9e[        R                  U5      n	U	b.  U	R                  5       nU[        U5      S R                  S5      nO(UR                  S5      n
U
S:X  a  UnSnOUSU
 nXS-   S n[        U5      nU(       d
  [        USS9e[        UUUUUS9$ )z@Parse the body of a repo URI: '<repo_id>[@<revision>][/<path>]'.r+   zMissing repository id.r(   rD   r   Nr   r   z-Repository id must be 'namespace/name', got 'z'. r   r   z!Missing repository id before '@'.r,   zEmpty revision after '@'.r   )r   r	   r   r0   r   r{   rF   matchgroupremoveprefixr   r   )r   r   r   at_idxr   rK   r   r   rev_and_pathr   r   s              r5   r   r   '  s    ~~c"HS&>??
 ]]3F |x(..s3a7sA&u:>,YZbYccf*ghh1XJaaz*#&u:>uQxr7F#
-*MNN==",YZaYbbd*eff -22<@{{}H'H8EEcJL$))#.IB'!'
3+MO<8$*EFF! r>   ).ra   	functoolsredataclassesr   r   urllib.parser   r   r   huggingface_hubr   huggingface_hub.errorsr	   r
   _validatorsr   r   itemsr   dictr1   rc   compilerF   	frozensetvaluesr   r   r   r   rh   re   rv   	lru_cacheru   r|   r   r}   r   tupler   rb   r~   r   r   )kvs   00r5   <module>r      sV  :  	 ( 1 1 % @ )
 5>4R4R4X4X4Z"[4ZDA144Z"[c3h [  "zz*MN  $-Y-K-K-R-R-T#U )C. U .77b-c IcN c 09)V9L/M in M $z z zz $' ' 'T3 4  86c 86e 86 86veC eD e0c 0c 0F*# F*# F*R7Xc 7Xg 7Xt+s +C +E#sTz4$;2N,O +<# s uY5H5H#5M/N > 
	
 0888 
	8
 8_ #\s   F