
    h                    B    d Z ddlmZ ddlmZ dZdZd
dZddZddd	Z	y)u  
error_guard.py
===================

Lekki strażnik HTML-a: wykrywa stronki-błędy (np. CloudFront 403, WAF/CAPTCHA),
i normalizuje wynik tak, aby NIE zapisywać do bazy pełnego HTML-a błędu,
tylko kontrolną wartość "error" + meta z powodem.

API:
    is_error, reason, normalized_html = check_and_normalize_html(html, http_status=None)

- is_error: bool – czy to znany „error HTML”
- reason:   str  – krótki powód (np. "cloudfront_403")
- normalized_html: str – "error" jeśli wykryto błąd, inaczej oryginalny html
    )annotations)Tuple)z"the request could not be satisfiedzgenerated by cloudfrontz	403 errorzrequest blocked.)zjust a moment...zenable javascriptzaccess deniedzattention requiredzbot verificationc                *    | xs dj                         S )N )lower)xs    6/var/www/extractly/html_agregator/utils/error_guard.py_lcr
   '   s    G??    c                ,     t         fd|D              S )Nc              3  &   K   | ]  }|v  
 y wN ).0nhaystacks     r	   	<genexpr>z _contains_any.<locals>.<genexpr>,   s     .gqH}gs   )any)r   needless   ` r	   _contains_anyr   +   s    .g...r   Nc                    t        |       }|dv rdd| dfS t        |t              ryt        |t              rydd| xs dfS )	u   
    Zwraca: (is_error, reason, normalized_html)

    Zasada:
      - jeśli status w [403, 401, 429, 503] → "status_<code>"
      - jeśli treść HTML ma sygnatury CloudFront/WAF → "cloudfront_403" / "waf_or_captcha"
      - w przypadku błędu zwraca normalized_html = "error"
    >           Tstatus_error)Tcloudfront_403r   )Twaf_or_captchar   Fr   )r
   r   CLOUD_ERROR_SIGNSWAF_CAPTCHA_SIGNS)htmlhttp_statushs      r	   check_and_normalize_htmlr%   /   s]     	D	A **w{m,g55 Q)*.Q)*. "djb  r   )r   
str | Nonereturnstr)r   r(   r   ztuple[str, ...]r'   boolr   )r"   r&   r#   z
int | Noner'   zTuple[bool, str, str])
__doc__
__future__r   typingr   r    r!   r
   r   r%   r   r   r	   <module>r-      s1     #   /!r   