o
    0j9                     @   s  d Z ddlmZ ddlmZmZ G dd deZG dd deZG dd	 d	e	Z
G d
d deZG dd deeZG dd deeZG dd deZG dd deeZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZG d(d) d)eZG d*d+ d+eZG d,d- d-eZ G d.d/ d/eZ!G d0d1 d1e!Z"G d2d3 d3eZ#G d4d5 d5eZ$G d6d7 d7eZ%G d8d9 d9ee%Z&G d:d; d;e'e%Z(G d<d= d=eeZ)G d>d? d?eZ*G d@dA dAe*Z+G dBdC dCe*Z,G dDdE dEe,Z-G dFdG dGeZ.G dHdI dIe.Z/G dJdK dKe.Z0G dLdM dMe.Z1G dNdO dOeZ2G dPdQ dQe2Z3G dRdS dSe2Z4G dTdU dUeZ5G dVdW dWeZ6G dXdY dYe6Z7G dZd[ d[e6Z8d\S )]zContains all custom errors.    )Path)	HTTPErrorResponsec                       s<   e Zd ZU dZeeB ed< dedeeB f fddZ  ZS )CacheNotFoundz9Exception thrown when the Huggingface cache is not found.	cache_dirmsgc                    s$   t  j|g|R i | || _d S N)super__init__r   )selfr   r   argskwargs	__class__ W/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/huggingface_hub/errors.pyr
      s   
zCacheNotFound.__init__)	__name__
__module____qualname____doc__strr   __annotations__r
   __classcell__r   r   r   r   r      s   
 "r   c                   @      e Zd ZdZdS )CorruptedCacheExceptionzGException for any unexpected structure in the Huggingface cache-system.Nr   r   r   r   r   r   r   r   r          r   c                   @   r   )LocalTokenNotFoundErrorz0Raised if local token is required but not found.Nr   r   r   r   r   r      r   r   c                   @   r   )OfflineModeIsEnabledzTRaised when a request is made but `HF_HUB_OFFLINE=1` is set as environment variable.Nr   r   r   r   r   r   #   r   r   c                	       st   e Zd ZdZdddedededB f fddZd	ed
dfddZededededB d
d fddZ	dd Z
  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_messagemessageresponser    c                   sJ   |j dp|j dp|j d| _|| _|| _|j| _t | d S )Nzx-request-idzX-Amzn-Trace-Idzx-amz-cf-id)headersgetZ
request_idr    r"   requestr	   r
   )r   r!   r"   r    r   r   r   r
   E   s   

zHfHubHTTPError.__init__additional_messagereturnc                 C   s$   | j d | f| j dd  | _ dS )zFAppend additional information to the `HfHubHTTPError` initial message.r      N)r   )r   r&   r   r   r   append_to_messageV   s   $z HfHubHTTPError.append_to_messagec                 C   s   | |||dS )N)r"   r    r   )clsr!   r"   r    r   r   r   _reconstruct_hf_hub_http_errorZ   s   z-HfHubHTTPError._reconstruct_hf_hub_http_errorc                 C   s   | 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   r+   r   r"   r    )r   protocolr   r   r   __reduce_ex__`   s   zHfHubHTTPError.__reduce_ex__)r   r   r   r   r   r   r
   r)   classmethodr+   r-   r   r   r   r   r   r   '   s,    "r   c                   @   r   )InferenceTimeoutErrorzBError raised when a model is unavailable or the request times out.Nr   r   r   r   r   r/   h   r   r/   c                   @   r   )InferenceEndpointErrorz8Generic exception when dealing with Inference Endpoints.Nr   r   r   r   r   r0   o   r   r0   c                   @   r   )InferenceEndpointTimeoutErrorz<Exception for timeouts while waiting for Inference Endpoint.Nr   r   r   r   r   r1   s   r   r1   c                   @   r   )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   r   r2   z   r   r2   c                   @   r   )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   r   r3      r   r3   c                   @   r   )TextGenerationErrorz3Generic error raised if text-generation went wrong.Nr   r   r   r   r   r4      r   r4   c                   @   r   )ValidationErrorzServer-side validation error.Nr   r   r   r   r   r5      r   r5   c                   @      e Zd ZdS )GenerationErrorNr   r   r   r   r   r   r   r7          r7   c                   @   r6   )OverloadedErrorNr8   r   r   r   r   r:      r9   r:   c                   @   r6   )IncompleteGenerationErrorNr8   r   r   r   r   r;      r9   r;   c                   @   r6   )UnknownErrorNr8   r   r   r   r   r<      r9   r<   c                   @   r   )HFValidationErrorzGeneric exception thrown by `huggingface_hub` validators.

    Inherits from [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError).
    Nr   r   r   r   r   r=      r   r=   c                       s*   e Zd ZdZdedef fddZ  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                    s:   || _ || _|rd| d| nd| }t | d S )NzInvalid HF URI 'z'. zInvalid HF URI. )r?   r   r	   r
   )r   r?   r   Zfull_msgr   r   r   r
      s   zHfUriError.__init__r   r   r   r   r   r
   r   r   r   r   r   r>      s    	r>   c                   @   r   )DryRunErrorzXError triggered when a dry run is requested but cannot be performed (e.g. invalid repo).Nr   r   r   r   r   rA      r   rA   c                   @   r   )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   r   rB      r   rB   c                   @   s"   e Zd ZU dZdZedB ed< dS )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   rD   r   r   r   r   r   r   rC      s   
 rC   c                   @   2   e Zd ZU dZdZedB ed< dZedB ed< dS )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   rG   r   r   rH   r   r   r   r   rF      s   
 rF   c                   @   r   )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   rJ   	  r   rJ   c                   @   r   )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   rK     r   rK   c                   @   rE   )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.
    ```
    NrG   rH   rI   r   r   r   r   rL   4     
 rL   c                   @   r   )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   rN   P  r   rN   c                   @   rE   )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.
    ```
    NrG   rH   rI   r   r   r   r   rO   b  rM   rO   c                       s&   e Zd ZdZdef fddZ  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.
    ```
    r!   c                    s   t  | d S r   )r	   r
   )r   r!   r   r   r   r
     s   z LocalEntryNotFoundError.__init__r@   r   r   r   r   rP   }  s    rP   c                   @   r   )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   rQ     r   rQ   c                   @   r   )	DDUFErrorz5Base exception for errors related to the DDUF format.Nr   r   r   r   r   rR     r   rR   c                   @   r   )DDUFCorruptedFileErrorz1Exception thrown when the DDUF file is corrupted.Nr   r   r   r   r   rS     r   rS   c                   @   r   )DDUFExportErrorz-Base exception for errors during DDUF export.Nr   r   r   r   r   rT     r   rT   c                   @   r   )DDUFInvalidEntryNameErrorz0Exception thrown when the entry name is invalid.Nr   r   r   r   r   rU     r   rU   c                   @   r   )StrictDataclassErrorz&Base exception for strict dataclasses.Nr   r   r   r   r   rV     r   rV   c                   @   r   )StrictDataclassDefinitionErrorz@Exception thrown when a strict dataclass is defined incorrectly.Nr   r   r   r   r   rW     r   rW   c                       *   e Zd ZdZdedef fddZ  ZS )#StrictDataclassFieldValidationErrorzLException thrown when a strict dataclass fails validation for a given field.fieldcausec                    4   d| d}|d|j j d| 7 }t | d S )NzValidation error for field '':
    : r   r   r	   r
   )r   rZ   r[   error_messager   r   r   r
        z,StrictDataclassFieldValidationError.__init__r   r   r   r   r   	Exceptionr
   r   r   r   r   r   rY         rY   c                       rX   )#StrictDataclassClassValidationErrorzOException thrown when a strict dataclass fails validation on a class validator.	validatorr[   c                    r\   )Nz&Class validation error for validator 'r]   r^   r_   r`   )r   rg   r[   ra   r   r   r   r
     rb   z,StrictDataclassClassValidationError.__init__rc   r   r   r   r   rf     re   rf   c                   @   r   )XetErrorz1Base exception for errors related to Xet Storage.Nr   r   r   r   r   rh     r   rh   c                   @   r   )XetAuthorizationErrorzXException thrown when the user does not have the right authorization to use Xet Storage.Nr   r   r   r   r   ri     r   ri   c                   @   r   )XetRefreshTokenErrorz3Exception thrown when the refresh token is invalid.Nr   r   r   r   r   rj     r   rj   c                   @   r   )XetDownloadErrorz:Exception thrown when the download from Xet Storage fails.Nr   r   r   r   r   rk     r   rk   c                   @   r   )CLIErrorz7CLI error with clean message (no traceback by default).Nr   r   r   r   r   rl     r   rl   c                   @   r   )ConfirmationErrorzERaised when a confirmation prompt is declined (non-interactive mode).Nr   r   r   r   r   rm     r   rm   c                   @   r   )CLIExtensionInstallErrorz(Error during CLI extension installation.Nr   r   r   r   r   rn     r   rn   N)9r   pathlibr   Zhttpxr   r   rd   r   r   EnvironmentErrorr   ConnectionErrorr   OSErrorr   TimeoutErrorr/   r0   r1   r2   r3   r4   r5   r7   r:   r;   r<   
ValueErrorr=   r>   rA   rB   rC   rF   rJ   rK   rL   rN   rO   FileNotFoundErrorrP   rQ   rR   rS   rT   rU   rV   rW   rY   rf   rh   ri   rj   rk   rl   rm   rn   r   r   r   r   <module>   s^    
A	
	