
    Mim                    B   S r SSKJr  SSKrSSKJrJr  SSKJr  Sr	\R                  " S\R                  5      r\R                  " S\R                  5      r\R                  " S	\R                  5      r\R                  " S
\R                  5      rSS jrSS jrSS jrg)z<Stage 1b: charset declaration extraction (HTML/XML/PEP 263).    )annotationsN)DETERMINISTIC_CONFIDENCEDetectionResult)lookup_encodingi   s*   <\?xml[^>]+encoding\s*=\s*['"]([^'"]+)['"]s,   <meta[^>]+charset\s*=\s*['"]?\s*([^\s'">;]+)s6   <meta[^>]+content\s*=\s*['"][^'"]*charset=([^\s'">;]+)s&   ^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)c                ~   SU SS ;  a  gSR                  U R                  SS5      SS 5      n[        R                  U5      nU(       a]   UR	                  S5      R                  S5      R                  5       n[        U5      nUb   [        X5      (       a  [        U[        SSS	9$ g! [        [        4 a     gf = f)
a.  Check the first two lines of *data* for a PEP 263 encoding declaration.

PEP 263 declarations (e.g. ``# -*- coding: utf-8 -*-``) are only valid
on line 1 or line 2 of a Python source file.

:param data: The raw byte data to scan.
:returns: A :class:`DetectionResult` with confidence 0.95, or ``None``.
   #N      
      asciiztext/x-pythonencoding
confidencelanguage	mime_type)joinsplit
_PEP263_REsearchgroupdecodestripUnicodeDecodeError
ValueErrorr   _validate_bytesr   r   )datafirst_two_linesmatchraw_namer   s        q/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/chardet/pipeline/markup.py_detect_pep263r"      s     4:jjE1!5bq!9:Oo.E	{{1~,,W5;;=H #8,OD$C$C"!3)	   #J/ 		s   .B) )B<;B<c                   U (       d  gU S[          n[        [        [        4 H  nUR	                  U5      nU(       d  M   UR                  S5      R                  S5      R                  5       n[        U5      nUc  M\  [        X5      (       d  Mn  U[        L a  SOSn[        U[        SUS9s  $    [        U 5      $ ! [        [        4 a     M  f = f)av  Scan the first bytes of *data* for a charset declaration.

Checks for:

1. ``<?xml ... encoding="..."?>``
2. ``<meta charset="...">``
3. ``<meta http-equiv="Content-Type" content="...; charset=...">``
4. PEP 263 ``# -*- coding: ... -*-`` (first two lines only)

:param data: The raw byte data to scan.
:returns: A :class:`DetectionResult` with confidence 0.95, or ``None``.
Nr   r   ztext/xmlz	text/htmlr   )_SCAN_LIMIT_XML_ENCODING_RE_HTML5_CHARSET_RE_HTML4_CONTENT_TYPE_REr   r   r   r   r   r   r   r   r   r   r"   )r   headpatternr   r    r   r   s          r!   detect_markup_charsetr*   :   s     D$&79OPt$5 ;;q>009??A 'x0H#(G(G*15E*EJ;	&%7!'	  Q" $ '
3 s   .B==CCc                l     U S[          R                  U5        g! [        [        [        4 a     gf = f)zCheck that *data* can be decoded under *encoding* without errors.

Only validates the first ``_SCAN_LIMIT`` bytes to avoid decoding a
full 200 kB input just to verify a charset declaration found in the
header.
NFT)r$   r   r   LookupErrorr   )r   r   s     r!   r   r   `   s<    \k!!(+  Z8 s    33)r   bytesreturnzDetectionResult | None)r   r-   r   strr.   bool)__doc__
__future__r   rechardet.pipeliner   r   chardet.registryr   r$   compile
IGNORECASEr%   r&   r'   	MULTILINEr   r"   r*   r        r!   <module>r;      s    B " 	 F ,::6  JJ8"--  BBMM  ZZBBLLQ
># Lr:   