o
    i                      @   s   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	 ddl
mZ ddlmZ ejd	ejd
ZdedefddZdeddfddZdedeee	f deee	f fddZdS )zDContains utilities to validate argument values in `huggingface_hub`.    N)wraps)chain)Any)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                    s$   t  t  fd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_legacy_arguments`]: Ignore `proxies` when downloading files (should be set globally).

    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'.
    ```

    Raises:
        [`~utils.HFValidationError`]:
            If an input is not valid.
    c                     sL   t tj| | D ]\}}|dv rt| qt j|d} | i |S )N)repo_idfrom_idto_id)fn_namekwargs)r   zip
parametersitemsvalidate_repo_id#smoothly_deprecate_legacy_arguments__name__)argsr   arg_name	arg_valuer	   	signature g/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py	_inner_fnN   s   
z'validate_hf_hub_args.<locals>._inner_fn)inspectr   r   )r	   r   r   r   r   validate_hf_hub_args*   s   
"r   r   c                 C   s   t | tstdt|  d|  d| ddkr!td|  dt| s.td|  dd	| v s6d
| v r>td|  d| drKtd|  ddS )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.zRepo id must use alphanumeric chars, '-', '_' or '.'. The name cannot start or end with '-' or '.' and the maximum 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   r   r   r   r   ^   s&   


r   r   r   c                 C   s   |  }|dd}|durtd|  d |dd}|dur*td|  d |dd}|dur=td	|  d
 |dd}|durPtd|  d |S )a  Smoothly deprecate legacy arguments in the `huggingface_hub` codebase.

    This function ignores some deprecated arguments from the kwargs and warns the user they are ignored.
    The goal is to avoid breaking existing code while guiding the user to the new way of doing things.

    List of deprecated arguments:
        - `proxies`:
            To set up proxies, user must either use the HTTP_PROXY environment variable or configure the `httpx.Client`
            manually using the [`set_client_factory`] function.

            In huggingface_hub 0.x, `proxies` was a dictionary directly passed to `requests.request`.
            In huggingface_hub 1.x, we migrated to `httpx` which does not support `proxies` the same way.
            In particular, it is not possible to configure proxies on a per-request basis. The solution is to configure
            it globally using the [`set_client_factory`] function or using the HTTP_PROXY environment variable.

            For more details, see:
            - https://www.python-httpx.org/advanced/proxies/
            - https://www.python-httpx.org/compatibility/#proxy-keys.

        - `resume_download`: deprecated without replacement. `huggingface_hub` always resumes downloads whenever possible.
        - `force_filename`: deprecated without replacement. Filename is always the same as on the Hub.
        - `local_dir_use_symlinks`: deprecated without replacement. Downloading to a local directory does not use symlinks anymore.
    proxiesNz&The `proxies` argument is ignored in `z`. To set up proxies, use the HTTP_PROXY / HTTPS_PROXY environment variables or configure the `httpx.Client` manually using `huggingface_hub.set_client_factory`. See https://www.python-httpx.org/advanced/proxies/ for more details.resume_downloadz=The `resume_download` argument is deprecated and ignored in `z-`. Downloads always resume whenever possible.force_filenamez<The `force_filename` argument is deprecated and ignored in `z-`. Filename is always the same as on the Hub.local_dir_use_symlinkszDThe `local_dir_use_symlinks` argument is deprecated and ignored in `zB`. Downloading to a local directory does not use symlinks anymore.)copypopwarningswarn)r   r   
new_kwargsr(   r)   r*   r+   r   r   r   r      s,   



r   )__doc__r   rer.   	functoolsr   	itertoolsr   typingr   huggingface_hub.errorsr   _typingr   compileVERBOSEr%   r   r"   r   dictr   r   r   r   r   <module>   s    4*6