o
    NK&h                     @   s   d 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dS )z"Copyright (C) 2020 Nidhal Baccouric                       s(   e Zd ZdZ fddZdd Z  ZS )	BaseErrorz$
    base error structure class
    c                    s   || _ || _t   dS )z\
        @param val: actual value
        @param message: message shown to the user
        N)valmessagesuper__init__selfr   r   	__class__ M/var/www/html/venv/lib/python3.10/site-packages/deep_translator/exceptions.pyr   	   s   zBaseError.__init__c                 C      d | j| jS )Nz	{} --> {})formatr   r   r   r
   r
   r   __str__      zBaseError.__str__)__name__
__module____qualname____doc__r   r   __classcell__r
   r
   r   r   r      s    	r   c                       $   e Zd ZdZ	d fdd	Z  ZS )LanguageNotSupportedExceptionzg
    exception thrown if the user uses a language
    that is not supported by the deep_translator
    +There is no support for the chosen languagec                    s   t  || d S Nr   r   r   r   r
   r   r      s   z&LanguageNotSupportedException.__init__)r   r   r   r   r   r   r   r
   r
   r   r   r      s    r   c                       r   )NotValidPayload@
    exception thrown if the user enters an invalid payload
    Wtext must be a valid text with maximum 5000 character,otherwise it cannot be translatedc                       t t| || d S r   )r   r   r   r   r   r
   r   r   '   s   zNotValidPayload.__init__)r   r   r
   r
   r   r   r   "       r   c                       s"   e Zd ZdZd fdd	Z  ZS )InvalidSourceOrTargetLanguager   "Invalid source or target language!c                    r   r   )r   r!   r   r   r   r
   r   r   5   s   z&InvalidSourceOrTargetLanguage.__init__)r"   r   r
   r
   r   r   r!   0   s    r!   c                       r   )TranslationNotFoundzX
    exception thrown if no translation was found for the text provided by the user
    NNo translation was found using the current translator. Try another translator?c                    r   r   )r   r#   r   r   r   r
   r   r   >   s   zTranslationNotFound.__init__)r$   r   r
   r
   r   r   r#   9   r    r#   c                       r   )ElementNotFoundInGetRequestz`
    exception thrown if the html element was not found in the body parsed by beautifulsoup
    2Required element was not found in the API responsec                    r   r   )r   r%   r   r   r   r
   r   r   K   s   z$ElementNotFoundInGetRequest.__init__)r&   r   r
   r
   r   r   r%   F   s    r%   c                           e Zd ZdZ fddZ  ZS )NotValidLengthzY
    exception thrown if the provided text exceed the length limit of the translator
    c                    s(   d| d| d}t t| || d S )NzText length need to be between z and z characters)r   r(   r   )r   r   	min_chars	max_charsr   r   r
   r   r   V   s   zNotValidLength.__init__r   r
   r
   r   r   r(   Q       r(   c                   @   $   e Zd ZdZ	dddZdd ZdS )	RequestErrorb
    exception thrown if an error occurred during the request call, e.g a connection problem.
    gRequest exception can happen due to an api connection error. Please check your connection and try againc                 C   
   || _ d S r   r   r   r   r
   r
   r   r   `   s   
zRequestError.__init__c                 C      | j S r   r1   r   r
   r
   r   r   g      zRequestError.__str__N)r/   r   r   r   r   r   r   r
   r
   r
   r   r-   [   s
    
r-   c                   @       e Zd ZdZdd Zdd ZdS )MicrosoftAPIerrorzE
    exception thrown if Microsoft API returns one of its errors
    c                 C      t || _d| _d S )Nz*Microsoft API returned the following errorstrapi_messager   r   r;   r
   r
   r   r   p      

zMicrosoftAPIerror.__init__c                 C   r   Nz{}: {}r   r   r;   r   r
   r
   r   r   t   r   zMicrosoftAPIerror.__str__Nr5   r
   r
   r
   r   r7   k       r7   c                   @   r,   )	TooManyRequestsr.   Server Error: You made too many requests to the server.According to google, you are allowed to make 5 requests per secondand up to 200k requests per day. You can wait and try again later oryou can try the translate_batch functionc                 C   r0   r   r1   r2   r
   r
   r   r   }   s   
zTooManyRequests.__init__c                 C   r3   r   r1   r   r
   r
   r   r      r4   zTooManyRequests.__str__N)rB   r5   r
   r
   r
   r   rA   x   s
    
	rA   c                       s<   e Zd ZdZdddddddd	d
dddZ fddZ  ZS )ServerExceptionzE
    Default YandexTranslate exception from the official website
    ERR_BAD_REQUESTERR_KEY_INVALIDERR_KEY_BLOCKEDERR_DAILY_REQ_LIMIT_EXCEEDEDERR_DAILY_CHAR_LIMIT_EXCEEDEDERR_TEXT_TOO_LONGERR_TOO_MANY_REQUESTSERR_UNPROCESSABLE_TEXTERR_INTERNAL_SERVER_ERRORERR_LANG_NOT_SUPPORTEDERR_SERVICE_NOT_AVAIBLE)i  i  i  i  i  i  i  i  i  i  i  c                    s*   | j |d}tt| j|g|R   d S )NzAPI server error)errorsgetr   rC   r   )r   status_codeargsr   r   r
   r   r      s   zServerException.__init__)r   r   r   r   rO   r   r   r
   r
   r   r   rC      s    rC   c                       r'   )ApiKeyExceptionz4
    exception thrown if no ApiKey was provided
    c                    s$   d| d| d}t  d | d S )Nz
You have to pass your api_key!
You can do this by passing the key as a parameter/argument to the translator class
or by setting the environment variable z

Example: export z="your_api_key"
r   )r   env_varmsgr   r
   r   r      s   zApiKeyException.__init__r   r
   r
   r   r   rS      r+   rS   c                       s   e Zd Z fddZ  ZS )AuthorizationExceptionc                    s    d| }t  j|g|R   d S )Nz%Unauthorized access with the api key r   )r   api_keyrR   rU   r   r
   r   r      s   zAuthorizationException.__init__)r   r   r   r   r   r
   r
   r   r   rV      s    rV   c                   @   r6   )BaiduAPIerrorzA
    exception thrown if Baidu API returns one of its errors
    c                 C   r8   )Nz&Baidu API returned the following errorr9   r<   r
   r
   r   r      r=   zBaiduAPIerror.__init__c                 C   r   r>   r?   r   r
   r
   r   r      r   zBaiduAPIerror.__str__Nr5   r
   r
   r
   r   rX      r@   rX   N)__copyright__	Exceptionr   r   r   r!   r#   r%   r(   r-   r7   rA   rC   rS   rV   rX   r
   r
   r
   r   <module>   s    	
