
    ޺i                    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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      
      asciiencoding
confidencelanguage)joinsplit
_PEP263_REsearchgroupdecodestripUnicodeDecodeError
ValueErrorr   _validate_bytesr   r   )datafirst_two_linesmatchraw_namer   s        V/var/www/piano.thomer.com/venv/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[        S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   r   )_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   s         r    detect_markup_charsetr)   9   s     D$&79OPt$5 ;;q>009??A 'x0H#(G(G&%7!  Q $ '
3 s   .B//CCc                b     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   LookupError)r   r   s     r    r   r   ]   s:    \k!!(+  , s    ..)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
<! Hr9   