
    -:j?                     2   d Z ddlmZ ddlmZ ddlmZmZ  G d de      Z	 G d de      Z
 G d	 d
e      Z G d de      Z G d dee      Z G d de      Z G d de      Z G d dee      Z G d dee      Z G d de      Z G d dee      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z G d' d(e      Z G d) d*e      Z  G d+ d,e!      Z" G d- d.e!      Z# G d/ d0e      Z$ G d1 d2e      Z% G d3 d4e      Z& G d5 d6e      Z' G d7 d8e      Z( G d9 d:e(      Z) G d; d<e      Z* G d= d>e      Z+ G d? d@e      Z, G dA dBee,      Z- G dC dDe.e,      Z/ G dE dFee!      Z0 G dG dHe      Z1 G dI dJe1      Z2 G dK dLe1      Z3 G dM dNe3      Z4 G dO dPe      Z5 G dQ dRe5      Z6 G dS dTe5      Z7 G dU dVe5      Z8 G dW dXe      Z9 G dY dZe      Z: G d[ d\e      Z; G d] d^e;      Z< G d_ d`e;      Z=ya)bzContains all custom errors.    )Enum)Path)	HTTPErrorResponsec                   D     e Zd ZU dZeez  ed<   dedeez  f fdZ xZS )CacheNotFoundz9Exception thrown when the Huggingface cache is not found.	cache_dirmsgc                 :    t        |   |g|i | || _        y N)super__init__r	   )selfr
   r	   argskwargs	__class__s        X/var/www/html/tokenscope/api/venv/lib/python3.12/site-packages/huggingface_hub/errors.pyr   zCacheNotFound.__init__   s!    .t.v."    )	__name__
__module____qualname____doc__strr   __annotations__r   __classcell__r   s   @r   r   r      s,    CTz#C #C$J # #r   r   c                       e Zd ZdZy)CorruptedCacheExceptionzGException for any unexpected structure in the Huggingface cache-system.Nr   r   r   r    r   r   r   r      s    Qr   r   c                       e Zd ZdZy)LocalTokenNotFoundErrorz0Raised if local token is required but not found.Nr   r    r   r   r"   r"          :r   r"   c                       e Zd ZdZy)	OIDCErrora:  Raised when keyless CI/CD auth via OIDC token exchange ("Trusted Publishers") cannot proceed.

    Typically because `HF_OIDC_RESOURCE` is set but no id token is available: not running in a
    supported CI provider and `HF_OIDC_ID_TOKEN` is unset.

    See https://huggingface.co/docs/hub/trusted-publishers.
    Nr   r    r   r   r%   r%   $   s    r   r%   c                   $    e Zd ZdZdZdZdZdZdZy)OAuthErrorCodezUKnown OAuth `error` codes returned by the Hub's token endpoint (RFC 6749 / RFC 8628).authorization_pending	slow_downexpired_tokenaccess_deniedinvalid_grantN)	r   r   r   r   AUTHORIZATION_PENDING	SLOW_DOWNEXPIRED_TOKENACCESS_DENIEDINVALID_GRANTr    r   r   r'   r'   1   s    _3I#M#M#Mr   r'   c                   4     e Zd ZdZddededz  f fdZ xZS )DeviceCodeErrora  Raised when the Device Code OAuth login flow (RFC 8628) or an OAuth token refresh fails.

    Covers failures at any step: requesting the device code, polling for the token,
    authorization denied/expired, or unexpected server responses.

    Attributes:
        error_code (`str`, *optional*):
            The OAuth `error` code returned by the server, if any. Known values are listed in
            [`OAuthErrorCode`] but the server may return other codes.
    Nmessage
error_codec                 2    t         |   |       || _        y r   )r   r   r5   )r   r4   r5   r   s      r   r   zDeviceCodeError.__init__G   s    !$r   r   r   r   r   r   r   r   r   r   s   @r   r3   r3   ;   s$    	% %t % %r   r3   c                       e Zd ZdZy)OfflineModeIsEnabledzTRaised when a request is made but `HF_HUB_OFFLINE=1` is set as environment variable.Nr   r    r   r   r9   r9   O   s    ^r   r9   c            	       z     e Zd ZdZdddedededz  f fdZded	dfd
Zededededz  d	d fd       Z	d Z
 xZS )HfHubHTTPErrora>  
    HTTPError to inherit from for any custom HTTP Error raised in HF Hub.

    Any HTTPError is converted at least into a `HfHubHTTPError`. If some information is
    sent back by the server, it will be added to the error message.

    Added details:
    - Request ID sourced from headers in order of precedence: "X-Request-Id", "X-Amzn-Trace-Id", "X-Amz-Cf-Id".
    - Server error message from the header "X-Error-Message".
    - Server error message if we can found one in the response body.

    Example:
    ```py
        import httpx
        from huggingface_hub.utils import get_session, hf_raise_for_status, HfHubHTTPError

        response = get_session().post(...)
        try:
            hf_raise_for_status(response)
        except HfHubHTTPError as e:
            print(str(e)) # formatted message
            e.request_id, e.server_message # details returned by server

            # Complete the error message with additional information once it's raised
            e.append_to_message("
`create_commit` expects the repository to exist.")
            raise
    ```
    N)server_messager4   responser<   c                   |j                   j                  d      xs8 |j                   j                  d      xs |j                   j                  d      | _        || _        || _        |j
                  | _        t        |   |       y )Nzx-request-idzX-Amzn-Trace-Idzx-amz-cf-id)headersget
request_idr<   r=   requestr   r   )r   r4   r=   r<   r   s       r   r   zHfHubHTTPError.__init__q   s~       0 3##$563##M2 	
 - ''!r   additional_messagereturnc                 T    | j                   d   |z   f| j                   dd z   | _         y)zFAppend additional information to the `HfHubHTTPError` initial message.r      N)r   )r   rC   s     r   append_to_messagez HfHubHTTPError.append_to_message   s)    YYq\$668499QR=H	r   c                      | |||      S )N)r=   r<   r    )clsr4   r=   r<   s       r   _reconstruct_hf_hub_http_errorz-HfHubHTTPError._reconstruct_hf_hub_http_error   s     7XnMMr   c                 r    | j                   j                  t        |       | j                  | j                  ffS )zeFix pickling of Exception subclass with kwargs. We need to override __reduce_ex__ of the parent class)r   rJ   r   r=   r<   )r   protocols     r   __reduce_ex__zHfHubHTTPError.__reduce_ex__   s-    ==D	4==Z^ZmZm?noor   )r   r   r   r   r   r   r   rG   classmethodrJ   rM   r   r   s   @r   r;   r;   S   s    D &*"" 	"
 d
""IC ID I NN%-N?BTzN	N N
pr   r;   c                       e Zd ZdZy)InferenceTimeoutErrorzBError raised when a model is unavailable or the request times out.Nr   r    r   r   rP   rP      s    Lr   rP   c                       e Zd ZdZy)InferenceEndpointErrorz8Generic exception when dealing with Inference Endpoints.Nr   r    r   r   rR   rR      s    Br   rR   c                       e Zd ZdZy)InferenceEndpointTimeoutErrorz<Exception for timeouts while waiting for Inference Endpoint.Nr   r    r   r   rT   rT      s    Fr   rT   c                       e Zd ZdZy)SafetensorsParsingErrorzRaised when failing to parse a safetensors file metadata.

    This can be the case if the file is not a safetensors file or does not respect the specification.
    Nr   r    r   r   rV   rV          r   rV   c                       e Zd ZdZy)NotASafetensorsRepoErrorzRaised when a repo is not a Safetensors repo i.e. doesn't have either a `model.safetensors` or a
    `model.safetensors.index.json` file.
    Nr   r    r   r   rY   rY      s    r   rY   c                       e Zd ZdZy)TextGenerationErrorz3Generic error raised if text-generation went wrong.Nr   r    r   r   r[   r[      s    =r   r[   c                       e Zd ZdZy)ValidationErrorzServer-side validation error.Nr   r    r   r   r]   r]      s    'r   r]   c                       e Zd Zy)GenerationErrorNr   r   r   r    r   r   r_   r_          r   r_   c                       e Zd Zy)OverloadedErrorNr`   r    r   r   rc   rc      ra   r   rc   c                       e Zd Zy)IncompleteGenerationErrorNr`   r    r   r   re   re      ra   r   re   c                       e Zd Zy)UnknownErrorNr`   r    r   r   rg   rg      ra   r   rg   c                       e Zd ZdZy)HFValidationErrorzGeneric exception thrown by `huggingface_hub` validators.

    Inherits from [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError).
    Nr   r    r   r   ri   ri      rW   r   ri   c                   ,     e Zd ZdZdedef fdZ xZS )
HfUriErrora8  Raised when an `hf://...` URI is malformed.

    See [`parse_hf_uri`] and the
    [HF URIs reference](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/hf_uris)
    for the canonical syntax.

    Inherits from [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError).
    urir
   c                 ^    || _         || _        |rd| d| nd| }t        |   |       y )NzInvalid HF URI 'z'. zInvalid HF URI. )rl   r
   r   r   )r   rl   r
   full_msgr   s       r   r   zHfUriError.__init__   s?    7:%cU#cU3BRSVRW@X"r   r7   r   s   @r   rk   rk      s     #C #c # #r   rk   c                       e Zd ZdZy)DryRunErrorzXError triggered when a dry run is requested but cannot be performed (e.g. invalid repo).Nr   r    r   r   rp   rp      s    br   rp   c                       e Zd ZdZy)FileMetadataErrorzError triggered when the metadata of a file on the Hub cannot be retrieved (missing ETag or commit_hash).

    Inherits from `OSError` for backward compatibility.
    Nr   r    r   r   rr   rr      rW   r   rr   c                   &    e Zd ZU dZdZedz  ed<   y)BucketNotFoundErrora  
    Raised when trying to access a bucket that does not exist.

    Attributes:
        bucket_id (`str` or `None`):
            The bucket id (namespace/name) that was not found, if it could be determined from the request URL.

    Example:

    ```py
    >>> from huggingface_hub import bucket_info
    >>> bucket_info("<non_existent_bucket>")
    (...)
    huggingface_hub.errors.BucketNotFoundError: 404 Client Error. (Request ID: XXX)

    Bucket Not Found for url: https://huggingface.co/api/buckets/namespace/name.
    Please make sure you specified the correct bucket id (namespace/name).
    If the bucket is private, make sure you are authenticated and your token has the required permissions.
    ```
    N	bucket_id)r   r   r   r   ru   r   r   r    r   r   rt   rt      s    * !IsTz r   rt   c                       e Zd ZU dZeed<   y)JobNotFoundErrorz
    Raised when trying to access a Job that does not exist.

    Attributes:
        job_id (`str`):
            The job id that was not found.
    job_idN)r   r   r   r   r   r   r    r   r   rw   rw     s     Kr   rw   c                   :    e Zd ZU dZdZedz  ed<   dZedz  ed<   y)RepositoryNotFoundErrora  
    Raised when trying to access a hf.co URL with an invalid repository name, or
    with a private repo name the user does not have access to.

    Attributes:
        repo_id (`str` or `None`):
            The repo id that was not found, if it could be determined from the request URL.
        repo_type (`str` or `None`):
            The repo type ("model", "dataset", or "space"), if it could be determined from the request URL.

    Example:

    ```py
    >>> from huggingface_hub import model_info
    >>> model_info("<non_existent_repository>")
    (...)
    huggingface_hub.errors.RepositoryNotFoundError: 401 Client Error. (Request ID: PvMw_VjBMjVdMz53WKIzP)

    Repository Not Found for url: https://huggingface.co/api/models/%3Cnon_existent_repository%3E.
    Please make sure you specified the correct `repo_id` and `repo_type`.
    If the repo is private, make sure you are authenticated and your token has the required permissions.
    Invalid username or password.
    ```
    Nrepo_id	repo_typer   r   r   r   r{   r   r   r|   r    r   r   rz   rz   &  s%    2 GS4Z IsTz r   rz   c                       e Zd ZdZy)GatedRepoErrora  
    Raised when trying to access a gated repository for which the user is not on the
    authorized list.

    Note: derives from `RepositoryNotFoundError` to ensure backward compatibility.

    Example:

    ```py
    >>> from huggingface_hub import model_info
    >>> model_info("<gated_repository>")
    (...)
    huggingface_hub.errors.GatedRepoError: 403 Client Error. (Request ID: ViT1Bf7O_026LGSQuVqfa)

    Cannot access gated repo for url https://huggingface.co/api/models/ardent-figment/gated-model.
    Access to model ardent-figment/gated-model is restricted and you are not in the authorized list.
    Visit https://huggingface.co/ardent-figment/gated-model to ask for access.
    ```
    Nr   r    r   r   r   r   D  s    r   r   c                       e Zd ZdZy)DisabledRepoErrora  
    Raised when trying to access a repository that has been disabled by its author.

    Example:

    ```py
    >>> from huggingface_hub import dataset_info
    >>> dataset_info("laion/laion-art")
    (...)
    huggingface_hub.errors.DisabledRepoError: 403 Client Error. (Request ID: Root=1-659fc3fa-3031673e0f92c71a2260dbe2;bc6f4dfb-b30a-4862-af0a-5cfe827610d8)

    Cannot access repository for url https://huggingface.co/api/datasets/laion/laion-art.
    Access to this resource is disabled.
    ```
    Nr   r    r   r   r   r   Z      r   r   c                   :    e Zd ZU dZdZedz  ed<   dZedz  ed<   y)RevisionNotFoundErrora  
    Raised when trying to access a hf.co URL with a valid repository but an invalid
    revision.

    Attributes:
        repo_id (`str` or `None`):
            The repo id, if it could be determined from the request URL.
        repo_type (`str` or `None`):
            The repo type ("model", "dataset", or "space"), if it could be determined from the request URL.

    Example:

    ```py
    >>> from huggingface_hub import hf_hub_download
    >>> hf_hub_download('bert-base-cased', 'config.json', revision='<non-existent-revision>')
    (...)
    huggingface_hub.errors.RevisionNotFoundError: 404 Client Error. (Request ID: Mwhe_c3Kt650GcdKEFomX)

    Revision Not Found for url: https://huggingface.co/bert-base-cased/resolve/%3Cnon-existent-revision%3E/config.json.
    ```
    Nr{   r|   r}   r    r   r   r   r   o  %    , GS4Z IsTz r   r   c                       e Zd ZdZy)EntryNotFoundErrora  
    Raised when entry not found, either locally or remotely.

    Example:

    ```py
    >>> from huggingface_hub import hf_hub_download
    >>> hf_hub_download('bert-base-cased', '<non-existent-file>')
    (...)
    huggingface_hub.errors.RemoteEntryNotFoundError (...)
    >>> hf_hub_download('bert-base-cased', '<non-existent-file>', local_files_only=True)
    (...)
    huggingface_hub.utils.errors.LocalEntryNotFoundError (...)
    ```
    Nr   r    r   r   r   r     r   r   r   c                   :    e Zd ZU dZdZedz  ed<   dZedz  ed<   y)RemoteEntryNotFoundErrora  
    Raised when trying to access a hf.co URL with a valid repository and revision
    but an invalid filename.

    Attributes:
        repo_id (`str` or `None`):
            The repo id, if it could be determined from the request URL.
        repo_type (`str` or `None`):
            The repo type ("model", "dataset", or "space"), if it could be determined from the request URL.

    Example:

    ```py
    >>> from huggingface_hub import hf_hub_download
    >>> hf_hub_download('bert-base-cased', '<non-existent-file>')
    (...)
    huggingface_hub.errors.EntryNotFoundError: 404 Client Error. (Request ID: 53pNl6M0MxsnG5Sw8JA6x)

    Entry Not Found for url: https://huggingface.co/bert-base-cased/resolve/main/%3Cnon-existent-file%3E.
    ```
    Nr{   r|   r}   r    r   r   r   r     r   r   r   c                   (     e Zd ZdZdef fdZ xZS )LocalEntryNotFoundErroraF  
    Raised when trying to access a file or snapshot that is not on the disk when network is
    disabled or unavailable (connection issue). The entry may exist on the Hub.

    Example:

    ```py
    >>> from huggingface_hub import hf_hub_download
    >>> hf_hub_download('bert-base-cased', '<non-cached-file>',  local_files_only=True)
    (...)
    huggingface_hub.errors.LocalEntryNotFoundError: Cannot find the requested files in the disk cache and outgoing traffic has been disabled. To enable hf.co look-ups and downloads online, set 'local_files_only' to False.
    ```
    r4   c                 $    t         |   |       y r   )r   r   )r   r4   r   s     r   r   z LocalEntryNotFoundError.__init__  s    !r   r7   r   s   @r   r   r     s    " " "r   r   c                       e Zd ZdZy)BadRequestErroraG  
    Raised by `hf_raise_for_status` when the server returns a HTTP 400 error.

    Example:

    ```py
    >>> resp = httpx.post("hf.co/api/check", ...)
    >>> hf_raise_for_status(resp, endpoint_name="check")
    huggingface_hub.errors.BadRequestError: Bad request for check endpoint: {details} (Request ID: XXX)
    ```
    Nr   r    r   r   r   r     s    
r   r   c                       e Zd ZdZy)	DDUFErrorz5Base exception for errors related to the DDUF format.Nr   r    r   r   r   r     s    ?r   r   c                       e Zd ZdZy)DDUFCorruptedFileErrorz1Exception thrown when the DDUF file is corrupted.Nr   r    r   r   r   r         ;r   r   c                       e Zd ZdZy)DDUFExportErrorz-Base exception for errors during DDUF export.Nr   r    r   r   r   r     s    7r   r   c                       e Zd ZdZy)DDUFInvalidEntryNameErrorz0Exception thrown when the entry name is invalid.Nr   r    r   r   r   r     r#   r   r   c                       e Zd ZdZy)StrictDataclassErrorz&Base exception for strict dataclasses.Nr   r    r   r   r   r     s    0r   r   c                       e Zd ZdZy)StrictDataclassDefinitionErrorz@Exception thrown when a strict dataclass is defined incorrectly.Nr   r    r   r   r   r     s    Jr   r   c                   ,     e Zd ZdZdedef fdZ xZS )#StrictDataclassFieldValidationErrorzLException thrown when a strict dataclass fails validation for a given field.fieldcausec                 n    d| d}|d|j                   j                   d| z  }t        |   |       y )NzValidation error for field '':
    : r   r   r   r   )r   r   r   error_messager   s       r   r   z,StrictDataclassFieldValidationError.__init__  s@    6ugR@6%//":":!;2eWEE'r   r   r   r   r   r   	Exceptionr   r   r   s   @r   r   r     s    V(c () ( (r   r   c                   ,     e Zd ZdZdedef fdZ xZS )#StrictDataclassClassValidationErrorzOException thrown when a strict dataclass fails validation on a class validator.	validatorr   c                 n    d| d}|d|j                   j                   d| z  }t        |   |       y )Nz&Class validation error for validator 'r   r   r   r   )r   r   r   r   r   s       r   r   z,StrictDataclassClassValidationError.__init__  s@    @2N6%//":":!;2eWEE'r   r   r   s   @r   r   r     s    Y(# (i ( (r   r   c                       e Zd ZdZy)XetDownloadErrorz:Exception thrown when the download from Xet Storage fails.Nr   r    r   r   r   r     s    Dr   r   c                       e Zd ZdZy)FileDuplicationErrorz1Raised when duplicating files across repos fails.Nr   r    r   r   r   r     r   r   r   c                       e Zd ZdZy)CLIErrorz7CLI error with clean message (no traceback by default).Nr   r    r   r   r   r     s    Ar   r   c                       e Zd ZdZy)ConfirmationErrorzERaised when a confirmation prompt is declined (non-interactive mode).Nr   r    r   r   r   r     s    Or   r   c                       e Zd ZdZy)CLIExtensionInstallErrorz(Error during CLI extension installation.Nr   r    r   r   r   r   #  s    2r   r   N)>r   enumr   pathlibr   httpxr   r   r   r   r   EnvironmentErrorr"   r%   r   r'   r3   ConnectionErrorr9   OSErrorr;   TimeoutErrorrP   rR   rT   rV   rY   r[   r]   r_   rc   re   rg   
ValueErrorri   rk   rp   rr   rt   rw   rz   r   r   r   r   r   FileNotFoundErrorr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   <module>r      sn   !   %#I #Ri R;. ;	 $S$ $%i %(_? _;pY ;pBMI| MCY CG$:L Gi y >) >
() (	) 		) 		 3 		& 	
 # #(c' c !. !8	~ 	!n !<, , *!N !8 $!~/A !6"/1C "(nj "@	 @<Y <8i 8; ;19 1K%9 K(*> ((*> (Ey E<9 <By BP P3x 3r   