Ë
    ^ãj²E  ã                   ó†  — U d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZmZ d	d
dœZeeeeef   f   ed<   dZ eh d£«      Z ej2                  dej4                  «      Z ej2                  dej4                  «      Z ej2                  dej4                  ej:                  z  «      Z ej2                  dej4                  «      Z ej2                  d«      Z  ej2                  d«      Z! ej2                  dej4                  «      Z" ej2                  dej4                  «      Z# e$ e%dd«      «      Z&dZ'de$de
dz  fd„Z(dededz  fd„Z)de$de
dz  fd„Z*d e$de$fd!„Z+dededz  fd"„Z,d#e$dee$e$f   fd$„Z-d e$dee$   fd%„Z.de$de
dz  fd&„Z/de$d'e
d(ee   de
fd)„Z0de$d*ede1fd+„Z2de$d*edz  dedz  fd,„Z3y)-zñStage 1b: charset declaration extraction (HTML/XML/PEP 263) and promotion.

Note: ``from __future__ import annotations`` is intentionally omitted because
this module is compiled with mypyc, which does not support PEP 563 string
annotations.
é    N)ÚIterator©Údecodes_without_error)ÚEncodingEra)ÚDETERMINISTIC_CONFIDENCEÚDetectionResultÚPipelineContext)Úcompute_structural_score)ÚREGISTRYÚlookup_encoding)Ú	shift_jisÚcp932)Úeuc_krÚcp949)Úshift_jis_2004r   Ú_MARKUP_SUPERSET_PROMOTIONSi   >   úutf-16úutf-32ú	utf-16-beú	utf-16-leú	utf-32-beú	utf-32-les-   <\?xml\s[^<>]*encoding\s*=\s*['"]([^'"]+)['"]s   <meta\b([^<>]*)>s4   ([^\s=/>]+)(?:\s*=\s*(?:(["'])(.*?)\2|([^\s>"']+)))?s@   charset[\t\n\f\r ]*=[\t\n\f\r ]*(?:(["'])([^"']+)\1|([^\s;"']+))s&   ^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)s   ^[ \t\f]*(?:[#\r]|$)z<(?:meta|\?xml)[^<>]*zM(?:charset|encoding)\s*=\s*(?:[^\sA-Za-z0-9._-]\s*)?([A-Za-z][A-Za-z0-9._-]+)é€   é   g      Ð?ÚdataÚreturnc                 ó`  — | dt          }t        |«      t        |j                  dt        «      «      z
  }|t        |«      t        z  k  ry|j                  dd¬«      }t        j                  |«      D ]¹  }t        j                  |j                  d«      «      D ]�  }t        |j                  d«      j                  «       «      }|€Œ.t        |   j                  t        j                  z  sŒSt!        | |«      sŒ`|j                  d«      d   dk(  }t#        |t$        d|rdnd	¬
«      c c S  Œ» y)u  Look for a charset declaration in EBCDIC-encoded markup.

    The ASCII regexes cannot see declarations in EBCDIC bytes, so when the
    head looks like EBCDIC text (dominated by high bytes), decode it through
    cp037 â€” the EBCDIC page whose letter and digit positions are shared by
    all variants â€” and scan the decoded text.  Only declarations naming a
    MAINFRAME-era encoding are honoured, and the declared encoding must
    decode the whole window.  The MIME type follows the tag the declaration
    sits in.
    NÚcp037Úreplace)Úerrorsr   é   ú?útext/xmlú	text/html©ÚencodingÚ
confidenceÚlanguageÚ	mime_type)Ú_SCAN_LIMITÚlenÚ	translateÚ_MARKUP_HIGH_BYTESÚ_EBCDIC_SCAN_MIN_HIGH_FRACTIONÚdecodeÚ_EBCDIC_TAG_REÚfinditerÚ_EBCDIC_DECL_REÚgroupr   Ústripr   Úerar   Ú	MAINFRAMEÚ_validate_bytesr   r   )r   ÚheadÚ
high_countÚdecodedÚtagÚmatchr&   Úis_xmls           úY/var/www/html/metafoliadorv2/venv/lib/python3.12/site-packages/chardet/pipeline/markup.pyÚ_detect_ebcdic_declarationr?   f   s  € ð �”Ð€DÜ�T“œS §¡°Ô6HÓ!IÓJÑJ€JØ”C˜“IÔ >Ñ>Ò>ØØ�k‰k˜'¨)ˆkÓ4€Gô
 ×&Ñ& wÓ/ò ˆÜ$×-Ñ-¨c¯i©i¸«lÓ;ò 	ˆEÜ& u§{¡{°1£~×';Ñ';Ó'=Ó>ˆHàÑ$Ü˜XÑ&×*Ñ*¬[×-BÑ-BÓBÜ# D¨(Õ3àŸ™ 1› a™¨CÑ/�Ü&Ø%Ü7Ø!Ù,2™j¸ô	ô ñ	ðð ó    Úraw_namec                 ó¸   — | dd j                  «       j                  dd«      }|dk(  s|j                  d«      ry|dv s|j                  d«      ry	t        | «      S )
a«  Resolve a coding cookie the way :func:`tokenize.detect_encoding` does.

    Python folds the ``utf-8-*`` spellings to UTF-8 and ``latin-1``,
    ``iso-8859-1``, and ``iso-latin-1`` (with or without a suffix) to
    Latin-1 before it consults the codec registry, so ``iso-latin-1`` is a
    valid cookie even though no codec answers to it, and ``utf-8-sig``
    names plain UTF-8 rather than a file that starts with a mark.
    Né   Ú_ú-úutf-8zutf-8-)zlatin-1z
iso-8859-1ziso-latin-1)zlatin-1-ziso-8859-1-ziso-latin-1-z	iso8859-1)Úlowerr   Ú
startswithr   )rA   Únames     r>   Ú_pep263_encodingrJ   Œ   sa   € ð �C�Rˆ=×ÑÓ ×(Ñ(¨¨cÓ2€DØˆw‚˜$Ÿ/™/¨(Ô3ØØÐ7Ñ7¸4¿?¹?Ø3ô<ð Ü˜8Ó$Ð$r@   c                 óÔ  — | dt          }d|vry|j                  dd«      }t        j                  |d   «      }|€>t	        |«      dkD  r0t
        j                  |d   «      rt        j                  |d   «      }|rY	 |j                  d«      j                  d«      j                  «       }t        | t        |«      «      }|�t        |t        dd¬	«      S y# t        t        f$ r Y yw xY w)
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.  Both lines have to start
    inside the first :data:`_SCAN_LIMIT` bytes, the same bound the markup
    scan uses.

    :param data: The raw byte data to scan.
    :returns: A :class:`DetectionResult` with confidence 0.95, or ``None``.
    Nó   #ó   
é   r   r!   Úasciiztext/x-pythonr%   )r*   ÚsplitÚ
_PEP263_REr<   r+   Ú_PEP263_BLANK_REr3   r/   r4   ÚUnicodeDecodeErrorÚ
ValueErrorÚ_declared_encodingrJ   r   r   )r   r8   Úlinesr<   rA   r&   s         r>   Ú_detect_pep263rW   Ÿ   sî   € ð �”Ð€Dà�4ÑØà�J‰J�u˜aÓ €EÜ×Ñ˜U 1™XÓ&€EØ€}œ˜U› ašÔ,<×,BÑ,BÀ5ÈÁ8Ô,LÜ× Ñ   q¡Ó*ˆÙð	Ø—{‘{ 1“~×,Ñ,¨WÓ5×;Ñ;Ó=ˆHô & dÔ,<¸XÓ,FÓGˆØÐÜ"Ø!Ü3ØØ)ô	ð ð øô #¤JÐ/ò 	Ùð	ús   Á<.C ÃC'Ã&C'r8   c                 óF  — | j                  d«      }|dk  r| S g }d}|dk\  r\|j                  | || «       | j                  d|dz   «      }|dk  rdj                  |«      S |dz   }| j                  d|«      }|dk\  rŒ\|j                  | |d «       dj                  |«      S )aT  Return *head* without its ``<!-- -->`` comments.

    A declaration inside a comment is not a declaration, and the WHATWG
    prescan skips comments for that reason.  As in the prescan, the dashes
    that open a comment may also close it (``<!-->`` is a whole comment),
    and a comment that never closes runs to the end of the head.
    s   <!--r   s   -->rN   r@   é   N)ÚfindÚappendÚjoin)r8   ÚstartÚpartsÚposÚends        r>   Ú_strip_commentsra   Ã   s®   € ð �I‰I�gÓ€EØˆq‚yØˆØ€EØ
€CØ
�1Š*Ø�‰�T˜#˜e�_Ô%Ø�i‰i˜ ¨¡	Ó*ˆØ�Š7Ø—8‘8˜E“?Ð"Ø�A‰gˆØ—	‘	˜' 3Ó'ˆð �1‹*ð 
‡L�L��c�d�ÔØ�8‰8�E‹?Ðr@   c                 óV   — | j                  «       dk(  ryt        | «      }|t        v ry|S )z9Resolve a charset label found in ASCII-compatible markup.zx-user-definedÚcp1252rF   )rG   r   Ú_SELF_CONTRADICTING_LABELS)rA   r&   s     r>   Ú_markup_encodingre   Û   s0   € à‡~�~ÓÐ+Ò+ØÜ˜xÓ(€HØÔ-Ñ-ØØ€Or@   Úbodyc                 óÞ   — i }t         j                  | «      D ]R  }|j                  d«      j                  «       }||v rŒ'|j                  d«      }|€|j                  d«      }|€ŒN|||<   ŒT |S )z:Return the attributes of one meta tag, lowercased by name.r!   rY   é   )Ú_ATTR_REr1   r3   rG   )rf   Úattrsr<   rI   Úvalues        r>   Ú_meta_attributesrl   å   sv   € à "€EÜ×"Ñ" 4Ó(ò  ˆØ�{‰{˜1‹~×#Ñ#Ó%ˆØ�5‰=ØØ—‘˜A“ˆØˆ=Ø—K‘K “NˆEØÑØˆE�$ŠKð ð €Lr@   c              #   ó  K  — t         j                  | «      D ]î  }t        |j                  d«      «      }|j	                  d«      }|�|j                  «       r|–— ŒE|j	                  d«      }|€|j	                  d«      }|j	                  d«      }|€Œ}|€Œ€|j                  «       j                  «       dk(  sŒ¢t        j                  |«      }|sŒº|j                  d«      r|j                  d«      n|j                  d	«      –— Œð y­w)
a‹  Yield charset labels from real meta declarations, in document order.

    ``charset=`` inside some other attribute (a refresh URL, a description)
    is not a declaration. A declaration is a ``charset`` attribute, or the
    ``charset`` parameter of an ``http-equiv="content-type"`` tag.
    ``name="content-type"`` is wrong by the spec but common enough in the
    wild that it counts too.
    r!   s   charsetNs
   http-equivs   names   contents   content-typerN   rY   )	Ú_META_TAG_REr1   rl   r3   Úgetr4   rG   Ú_CONTENT_CHARSET_REÚsearch)r8   r;   rj   ÚcharsetÚequivÚcontentÚfounds          r>   Ú_iter_html_charsetsrv   ô   sá   è ø€ ô ×$Ñ$ TÓ*ò KˆÜ  §¡¨1£Ó.ˆØ—)‘)˜JÓ'ˆØÐ 7§=¡=¤?ØŠMØØ—	‘	˜-Ó(ˆØˆ=Ø—I‘I˜gÓ&ˆEØ—)‘)˜JÓ'ˆàÑØÑ#Ø—‘“×#Ñ#Ó%¨Ó8ä'×.Ñ.¨wÓ7ˆEÚØ(-¯©°A¬�e—k‘k !”n¸E¿K¹KÈ»NÓJñ#Kùs   ‚BD
ÂD
Â!D
Â:D
Ã8D
c                 óL  — | syt        | dt         «      }t        j                  |«      }|r]	 |j	                  d«      j                  d«      j                  «       }t        | |rt        |«      nd«      }|�t        |t        dd¬«      S t        |«      D ]N  }	 |j                  d«      j                  «       }t        | t        |«      «      }|€Œ;t        |t        dd¬«      c S  t        | «      }|�|S t        | «      S # t        t        f$ r d}Y Œ·w xY w# t        $ r Y Œ�w xY w)aì  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=...">``
       (also with ``name`` in place of ``http-equiv``)
    4. PEP 263 ``# -*- coding: ... -*-`` (first two lines only)

    Markup inside ``<!-- -->`` comments is not scanned.  A UTF-16 or UTF-32
    label is read as UTF-8 and ``x-user-defined`` as windows-1252, as in the
    WHATWG prescan, since a declaration found in ASCII bytes cannot be
    describing UTF-16 text.

    A declaration counts only if the declared encoding decodes the whole of
    *data*, or, failing that, if its Windows superset does (see
    :func:`_declared_encoding`).  A declaration that fails is skipped and
    the next one is tried, so a stale prolog does not hide a correct meta.

    :param data: The raw byte data to scan.
    :returns: A :class:`DetectionResult` with confidence 0.95, or ``None``.
    Nr!   rO   Ú r#   r%   r$   )ra   r*   Ú_XML_ENCODING_RErq   r3   r/   r4   rS   rT   rU   re   r   r   rv   r?   rW   )r   r8   r<   rA   r&   ÚrawÚebcdic_results          r>   Údetect_markup_charsetr|     sF  € ñ0 Øä˜4 ¤Ð-Ó.€Dä×#Ñ# DÓ)€EÙð	Ø—{‘{ 1“~×,Ñ,¨WÓ5×;Ñ;Ó=ˆHô &Ø±Ô" 8Ô,¸dó
ˆð ÐÜ"Ø!Ü3ØØ$ô	ð ô # 4Ó(ò ˆð	Ø—z‘z 'Ó*×0Ñ0Ó2ˆHô & dÔ,<¸XÓ,FÓGˆØÑÜ"Ø!Ü3ØØ%ô	ò ðô /¨tÓ4€MØÐ ØÐä˜$ÓÐøô? #¤JÐ/ò 	ØŠHð	ûô  "ò 	Ùð	ús#   ®.D  ÂDÄ DÄDÄ	D#Ä"D#Úmarkup_resultÚallowedc                 óÂ  — |j                   €|S t        j                  |j                   «      }|€|S |\  }}||vr|S t        ||j                  |j
                  |j                  «      }| dt         }t        «       }t        |t        |j                      |«      }	t        |t        |   |«      }
|
|	kD  rt        | |«      r|S |S t        | |«      r|S t        | |«      r|S |S )aï  Promote a markup-declared encoding to its superset when structural evidence supports it.

    If the declared encoding has a known superset (per
    :data:`_MARKUP_SUPERSET_PROMOTIONS`), the superset validates the data,
    and the superset's structural score is materially better, return a new
    result using the superset encoding.  Otherwise return *markup_result*
    unchanged.

    The decode checks read the whole input: what a caller can actually
    ``.decode()`` is a fact about their entire input, and a declared
    Shift_JIS page typically reaches its first CP932-only byte well past
    the header.  The structural comparison reads only the first
    :data:`_SCAN_LIMIT` bytes, since multi-byte structure is uniform enough
    that the ranking has converged by then.  It runs first because it is
    cheap and settles which single decode the answer needs: a 200 kB
    window decodes in a few hundred microseconds, and every declared page
    of a promotable encoding comes through here.
    N)r&   r   ro   r   r'   r(   r)   r*   r	   r
   r   r   )r   r}   r~   Ú	promotionÚreported_codecÚsuperset_nameÚpromotedr8   ÚctxÚ
base_scoreÚsuperset_scores              r>   Úpromote_markup_supersetr‡   T  sÿ   € ð. ×ÑÐ%ØÐÜ+×/Ñ/°×0FÑ0FÓG€IØÐØÐØ$-Ñ!€N�MØ˜GÑ#ØÐÜØØ× Ñ Ø×ÑØ×Ñó	€Hð �”Ð€DÜ
Ó
€CÜ)¨$´¸×9OÑ9OÑ0PÐRUÓV€JÜ-¨d´H¸]Ñ4KÈSÓQ€NØ˜
Ò"ä   }Ô5ØˆOØÐô
 ˜T >Ô2ØÐÜ˜T =Ô1ØˆØÐr@   r&   c                 ó   — t        | |«      S )a}  Check that the whole of *data* decodes under *encoding*.

    A declaration is an answer only if the caller can decode what chardet
    examined with it.  The decoder stops at the first bad sequence, so a
    declaration that lies about the header fails as fast as a head-only
    check would, and a cut multi-byte sequence at the very end is tolerated
    as everywhere else.
    r   )r   r&   s     r>   r7   r7   �  s   € ô !  xÓ0Ð0r@   c                 ó|   — |€yt        | |«      r|S t        j                  |«      }|�t        | |d   «      r|d   S y)aÑ  Return the name to report for a declaration of *encoding*, or ``None``.

    When the declared encoding cannot decode the window but its Windows
    superset can (a declared EUC-KR page whose first CP949-only hangul sits
    past the header, a declared Shift_JIS page using NEC extensions), the
    superset is the answer the caller can use, so it is reported directly.
    :func:`promote_markup_superset` would reach the same name one window
    decode later.
    Nr!   )r7   r   ro   )r   r&   r€   s      r>   rU   rU   ™  sL   € ð ÐØÜ�t˜XÔ&ØˆÜ+×/Ñ/°Ó9€IØÐ¤°°yÀ±|Ô!DØ˜‰|ÐØr@   )4Ú__doc__ÚreÚcollections.abcr   Úchardet._utilsr   Úchardet.enumsr   Úchardet.pipeliner   r   r	   Úchardet.pipeline.structuralr
   Úchardet.registryr   r   r   ÚdictÚstrÚtupleÚ__annotations__r*   Ú	frozensetrd   ÚcompileÚ
IGNORECASEry   rn   ÚDOTALLri   rp   rQ   rR   r0   r2   ÚbytesÚranger-   r.   r?   rJ   rW   ra   re   rl   rv   r|   r‡   Úboolr7   rU   © r@   r>   ú<module>rž      s|  ðòó 
Ý $å 0Ý %ß WÑ WÝ @ß 6ð -Ø!ñ;Ð ˜T # u¨S°#¨X¡Ð"6Ñ7ó ð
 €ñ 'ÚLóÐ ð �2—:‘:Ø9¸2¿=¹=óÐ ð ˆr�z‰zÐ.°·±Ó>€àˆ2�:‰:Ø@Ø‡M�M�B—I‘IÑó€ð !�b—j‘jØLØ‡M�MóÐ ð ˆR�Z‰ZÐBÓC€
Ø�2—:‘:Ð6Ó7Ð ð* �—‘Ð4°b·m±mÓD€Ø�"—*‘*ØTØ‡M�Mó€ñ ™5  uÓ-Ó.Ð ð "&Ð ð# Uð #¨ÀÑ/Eó #ðL%˜sð % s¨T¡zó %ð&!˜ð ! ?°TÑ#9ó !ðH˜%ð  Eó ð0˜sð  s¨T¡zó ð˜5ð  T¨%°¨,Ñ%7ó ðK˜eð K¨°©ó Kð:@  ð @ ¨/¸DÑ*@ó @ ðF6Ø
ð6à"ð6ð �s‰^ð6ð ó	6ðr	1˜%ð 	1¨3ð 	1°4ó 	1ð˜Uð ¨c°D©jð ¸SÀ4¹Zô r@   