
    i                         d Z ddlZddlmZmZmZ ddlmZ ej                  rddl
mZ ddZddZddZdd	Zdd
ZddZy)z1Raise exception for an HTTP response is an error.    N)SearxEngineCaptchaException#SearxEngineTooManyRequestsException SearxEngineAccessDeniedException)get_setting)SXNG_Responsec                     | j                   dv r9d| j                  v s*d| j                  v rd| j                  v rd| j                  v ry| j                   dk(  rd| j                  v ryy	)
N)    z__cf_chl_jschl_tk__=z/cdn-cgi/challenge-platform/zorchestrate/jsch/v1zwindow._cf_chl_enter(T  z__cf_chl_captcha_tk__=Fstatus_codetextresps    2/root/searxng/searx/network/raise_for_httperror.pyis_cloudflare_challenger      sc    :%"dii/*dii7%2'49943#;tyy#H    c                 @    | j                   dk(  xr d| j                  v S )Nr   z'<span class="cf-error-code">1020</span>r   r   s    r   is_cloudflare_firewallr      s%    s"]'PTXT]T]']]r   c                     | j                   j                  dd      j                  d      rCt        |       rt	        dt        d            t        |       rt        dt        d            y y )	NServer 
cloudflarezCloudflare CAPTCHAz,search.suspended_times.cf_SearxEngineCaptchamessagesuspended_timezCloudflare Firewallz1search.suspended_times.cf_SearxEngineAccessDenied)headersget
startswithr   r   r   r   r   r   s    r   raise_for_cloudflare_captchar    !   sp    ||"%00>"4( .,[Iw=x  "$'2-*+^_  ( ?r   c                 l    | j                   dk(  r%d| j                  v rt        dt        d            y y )Nr
   z""https://www.google.com/recaptcha/	ReCAPTCHAz3search.suspended_times.recaptcha_SearxEngineCaptchar   )r   r   r   r   r   s    r   raise_for_recaptchar#   1   s=    3#G499#T)<q0r
 	
 $Ur   c                 0    t        |        t        |        y )N)r    r#   r   s    r   raise_for_captchar%   8   s     &r   c                    | j                   ru| j                   dk\  ret        |        | j                   dv r"t        dt        | j                         z         | j                   dk(  r
t	               | j                          yyy)a  Raise exception for an HTTP response is an error.

    Args:
        resp (requests.Response): Response to check

    Raises:
        requests.HTTPError: raise by resp.raise_for_status()
        searx.exceptions.SearxEngineAccessDeniedException: raise when the HTTP status code is 402 or 403.
        searx.exceptions.SearxEngineTooManyRequestsException: raise when the HTTP status code is 429.
        searx.exceptions.SearxEngineCaptchaException: raise when if CATPCHA challenge is detected.
    i  )i  r   zHTTP error )r   r	   N)r   r%   r   strr   raise_for_statusr   s    r   raise_for_httperrorr)   =   sv     D,,3$z)2=3tO_O_K`;`aas"577 4r   )r   r   )r   r   returnN)__doc__typingtsearx.exceptionsr   r   r   searxr   TYPE_CHECKINGsearx.extended_typesr   r   r   r    r#   r%   r)    r   r   <module>r3      sC    7  
 ??2
^ 

 r   