Ë
    Q^(hô#  ã            
       óè   — d 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	m
Z
 ddlmZ ddlmZ  ej                  d	ej                   ¬
«      Zdedefd„Zdeddfd„Zdedede
ee	f   de
ee	f   fd„Zy)zDContains utilities to validate argument values in `huggingface_hub`.é    N)Úwraps)Úchain)ÚAnyÚDict)ÚHFValidationErroré   )Ú	CallableTzñ
    ^
    (\b[\w\-.]+\b/)? # optional namespace (username or organization)
    \b               # starts with a word boundary
    [\w\-.]{1,96}    # repo_name: alphanumeric + . _ -
    \b               # ends with a word boundary
    $
    )ÚflagsÚfnÚreturnc                 óœ   ‡ ‡‡— t        j                  ‰ «      Šd‰j                  vxr d‰j                  v Št        ‰ «      ˆˆ ˆfd„«       }|S )a­  Validate values received as argument for any public method of `huggingface_hub`.

    The goal of this decorator is to harmonize validation of arguments reused
    everywhere. By default, all defined validators are tested.

    Validators:
        - [`~utils.validate_repo_id`]: `repo_id` must be `"repo_name"`
          or `"namespace/repo_name"`. Namespace is a username or an organization.
        - [`~utils.smoothly_deprecate_use_auth_token`]: Use `token` instead of
          `use_auth_token` (only if `use_auth_token` is not expected by the decorated
          function - in practice, always the case in `huggingface_hub`).

    Example:
    ```py
    >>> from huggingface_hub.utils import validate_hf_hub_args

    >>> @validate_hf_hub_args
    ... def my_cool_method(repo_id: str):
    ...     print(repo_id)

    >>> my_cool_method(repo_id="valid_repo_id")
    valid_repo_id

    >>> my_cool_method("other..repo..id")
    huggingface_hub.utils._validators.HFValidationError: Cannot have -- or .. in repo_id: 'other..repo..id'.

    >>> my_cool_method(repo_id="other..repo..id")
    huggingface_hub.utils._validators.HFValidationError: Cannot have -- or .. in repo_id: 'other..repo..id'.

    >>> @validate_hf_hub_args
    ... def my_cool_auth_method(token: str):
    ...     print(token)

    >>> my_cool_auth_method(token="a token")
    "a token"

    >>> my_cool_auth_method(use_auth_token="a use_auth_token")
    "a use_auth_token"

    >>> my_cool_auth_method(token="a token", use_auth_token="a use_auth_token")
    UserWarning: Both `token` and `use_auth_token` are passed (...)
    "a token"
    ```

    Raises:
        [`~utils.HFValidationError`]:
            If an input is not valid.
    Úuse_auth_tokenÚtokenc                  óî   •— d}t        t        ‰j                  | «      |j                  «       «      D ]   \  }}|dv rt	        |«       Œ|dk(  sŒ|€Œd}Œ" ‰rt        ‰j                  ||¬«      } ‰| i |¤ŽS )NF)Úrepo_idÚfrom_idÚto_idr   T)Úfn_nameÚ	has_tokenÚkwargs)r   ÚzipÚ
parametersÚitemsÚvalidate_repo_idÚ!smoothly_deprecate_use_auth_tokenÚ__name__)Úargsr   r   Úarg_nameÚ	arg_valueÚcheck_use_auth_tokenr   Ú	signatures        €€€ú_/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/huggingface_hub/utils/_validators.pyÚ	_inner_fnz'validate_hf_hub_args.<locals>._inner_fnb   sˆ   ø€ àˆ	Ü#(Ü�	×$Ñ$ dÓ+Ø�L‰L‹Nó$
ò 	!ÑˆH�ið Ð:Ñ:Ü  Õ+à˜WÓ$¨Ñ)>Ø ‘	ð	!ñ  Ü6¸r¿{¹{ÐV_ÐhnÔoˆFá�4Ð"˜6Ñ"Ð"ó    )Úinspectr!   r   r   )r   r#   r    r!   s   ` @@r"   Úvalidate_hf_hub_argsr&   *   sX   ú€ ôd ×!Ñ! "Ó%€Ið ,°9×3GÑ3GÐGÒkÈGÐW`×WkÑWkÐLkÐä
ˆ2ƒYõ#ó ð#ð" Ðr$   r   c                 óV  — t        | t        «      st        dt        | «      › d| › d�«      ‚| j	                  d«      dkD  rt        d| › d�«      ‚t
        j                  | «      st        d| › d�«      ‚d	| v sd
| v rt        d| › d�«      ‚| j                  d«      rt        d| › d�«      ‚y)a”  Validate `repo_id` is valid.

    This is not meant to replace the proper validation made on the Hub but rather to
    avoid local inconsistencies whenever possible (example: passing `repo_type` in the
    `repo_id` is forbidden).

    Rules:
    - Between 1 and 96 characters.
    - Either "repo_name" or "namespace/repo_name"
    - [a-zA-Z0-9] or "-", "_", "."
    - "--" and ".." are forbidden

    Valid: `"foo"`, `"foo/bar"`, `"123"`, `"Foo-BAR_foo.bar123"`

    Not valid: `"datasets/foo/bar"`, `".repo_id"`, `"foo--bar"`, `"foo.git"`

    Example:
    ```py
    >>> from huggingface_hub.utils import validate_repo_id
    >>> validate_repo_id(repo_id="valid_repo_id")
    >>> validate_repo_id(repo_id="other..repo..id")
    huggingface_hub.utils._validators.HFValidationError: Cannot have -- or .. in repo_id: 'other..repo..id'.
    ```

    Discussed in https://github.com/huggingface/huggingface_hub/issues/1008.
    In moon-landing (internal repository):
    - https://github.com/huggingface/moon-landing/blob/main/server/lib/Names.ts#L27
    - https://github.com/huggingface/moon-landing/blob/main/server/views/components/NewRepoForm/NewRepoForm.svelte#L138
    zRepo id must be a string, not z: 'z'.ú/r   zCRepo id must be in the form 'repo_name' or 'namespace/repo_name': 'z&'. Use `repo_type` argument if needed.z�Repo id must use alphanumeric chars or '-', '_', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96: 'z--z..z"Cannot have -- or .. in repo_id: 'z.gitzRepo_id cannot end by '.git': 'N)Ú
isinstanceÚstrr   ÚtypeÚcountÚREPO_ID_REGEXÚmatchÚendswith)r   s    r"   r   r   w   sÛ   € ô< �gœsÔ#äÐ"@ÄÀgÃÀÈsÐSZÐR[Ð[]Ð ^Ó_Ð_à‡}�}�SÓ˜AÒÜðØ�	Ð?ðAó
ð 	
ô
 ×Ñ˜wÔ'Üðà�	˜ðó
ð 	
ð ˆw�˜$ '™/ÜÐ"DÀWÀIÈRÐ PÓQÐQà×Ñ˜ÔÜÐ"AÀ'ÀÈ"Ð MÓNÐNð  r$   r   r   r   c                 ó’   — |j                  «       }|j                  dd«      }|�"|rt        j                  d| › d�«       |S ||d<   |S )ac  Smoothly deprecate `use_auth_token` in the `huggingface_hub` codebase.

    The long-term goal is to remove any mention of `use_auth_token` in the codebase in
    favor of a unique and less verbose `token` argument. This will be done a few steps:

    0. Step 0: methods that require a read-access to the Hub use the `use_auth_token`
       argument (`str`, `bool` or `None`). Methods requiring write-access have a `token`
       argument (`str`, `None`). This implicit rule exists to be able to not send the
       token when not necessary (`use_auth_token=False`) even if logged in.

    1. Step 1: we want to harmonize everything and use `token` everywhere (supporting
       `token=False` for read-only methods). In order not to break existing code, if
       `use_auth_token` is passed to a function, the `use_auth_token` value is passed
       as `token` instead, without any warning.
       a. Corner case: if both `use_auth_token` and `token` values are passed, a warning
          is thrown and the `use_auth_token` value is ignored.

    2. Step 2: Once it is release, we should push downstream libraries to switch from
       `use_auth_token` to `token` as much as possible, but without throwing a warning
       (e.g. manually create issues on the corresponding repos).

    3. Step 3: After a transitional period (6 months e.g. until April 2023?), we update
       `huggingface_hub` to throw a warning on `use_auth_token`. Hopefully, very few
       users will be impacted as it would have already been fixed.
       In addition, unit tests in `huggingface_hub` must be adapted to expect warnings
       to be thrown (but still use `use_auth_token` as before).

    4. Step 4: After a normal deprecation cycle (3 releases ?), remove this validator.
       `use_auth_token` will definitely not be supported.
       In addition, we update unit tests in `huggingface_hub` to use `token` everywhere.

    This has been discussed in:
    - https://github.com/huggingface/huggingface_hub/issues/1094.
    - https://github.com/huggingface/huggingface_hub/pull/928
    - (related) https://github.com/huggingface/huggingface_hub/pull/1064
    r   Nz1Both `token` and `use_auth_token` are passed to `z‚` with non-None values. `token` is now the preferred argument to pass a User Access Token. `use_auth_token` value will be ignored.r   )ÚcopyÚpopÚwarningsÚwarn)r   r   r   Ú
new_kwargsr   s        r"   r   r   ­   sd   € ðJ —‘“€Jà—^‘^Ð$4°dÓ;€NØÐ!ÙÜ�M‰MðØ�Ið ;ð;ôð Ðð #1ˆJ�wÑàÐr$   )Ú__doc__r%   Úrer3   Ú	functoolsr   Ú	itertoolsr   Útypingr   r   Úhuggingface_hub.errorsr   Ú_typingr	   ÚcompileÚVERBOSEr-   r&   r*   r   Úboolr   © r$   r"   ú<module>rA      sª   ðñ Kã Û 	Û Ý Ý ß å 4å ð �—
‘
ðð �*‰*ô
€ðJ˜Yð J¨9ó JðZ3O˜cð 3O dó 3Oðl5¨sð 5¸tð 5ÈTÐRUÐWZÐRZÉ^ð 5Ð`dÐehÐjmÐemÑ`nô 5r$   