Ë
    ^ãj�E  ã                   ó´  — U d Z ddlmZmZmZ ddlmZmZ  e e	dd«      «      Z
eed<   deded	ed
efd„ZdZeed<    ee«      Zee   ed<    ed«      Zee   ed<    ee«      D � �ci c]  \  } }|| “Œ
 c}} Zeeef   ed<   dZeed<   ded
efd„Zdeded
efd„Zded
efd„Zded
efd„Zdeded	ed
efd„Zded
eeef   dz  fd„Zded
edz  fd„Zyc c}} w ) a  Early detection of escape-sequence-based encodings (ISO-2022, HZ-GB-2312, UTF-7).

These encodings use ESC (0x1B), tilde (~), or plus (+) sequences to switch
character sets.  They must be detected before binary detection (ESC is a control
byte) and before ASCII detection (HZ-GB-2312 and UTF-7 use only printable ASCII
bytes plus their respective shift markers).

Note: ``from __future__ import annotations`` is intentionally omitted because
this module is compiled with mypyc, which does not support PEP 563 string
annotations.
é    )ÚEVIDENCE_CAP_BYTESÚcount_deletedÚdecodes_without_error)ÚDETERMINISTIC_CONFIDENCEÚDetectionResulté!   é   Ú_HZ_GB_BYTESÚdataÚ	max_startÚmax_endÚreturnc                 ó  — d}	 | j                  d|«      }|dk(  s||k\  ry| j                  d|dz   |«      }|dk(  ry| |dz   | }t        |«      dk\  r.t        |«      dz  dk(  rt        |t        «      t        |«      k(  ry|dz   }Œƒ)aF  Check that at least one ~{...~} region contains valid GB2312 byte pairs.

    In HZ-GB-2312 GB mode, characters are encoded as pairs of bytes in the
    0x21-0x7E range.  We require at least one region with a non-empty, even-
    length run of such bytes.

    *max_start* bounds where a region may open and *max_end* where it may
    close.  Keeping them separate is what lets a region that opens inside
    the evidence window close beyond it: bounding both at the same offset
    would cut a straddling region and hide the only escape evidence a
    document has (ADR-0006).
    r   Tó   ~{éÿÿÿÿFó   ~}é   )ÚfindÚlenr   r
   )r   r   r   ÚstartÚbeginÚendÚregions          úY/var/www/html/metafoliadorv2/venv/lib/python3.12/site-packages/chardet/pipeline/escape.pyÚ_has_valid_hz_regionsr      sŸ   € ð €EØ
Ø—	‘	˜% Ó'ˆØ�BŠ;˜% 9Ò,ØØ�i‰i˜˜u q™y¨'Ó2ˆØ�"Š9ØØ�e˜a‘i #Ð&ˆô �‹K˜1ÒÜ�F“˜a‘ 1Ò$Ü˜f¤lÓ3´s¸6³{ÒBàØ�a‘ˆð' ó    s@   ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/Ú
_B64_CHARSÚ_UTF7_BASE64s   ABCDEFGHIJKLMNOPQRSTUVWXYZÚ_B64_UPPERCASEÚ_B64_DECODEé   Ú_EMBEDDED_B64_RUNÚ	b64_bytesc                 ó¸  — t        | «      }|dz  }|dz  }|dkD  rt        | d      }d|z  dz
  }||z  ry|dz  }t        |«      }d}d}	d}
| D ]1  }|dz  t        |   z  }|	dz  }	|	dk\  sŒ|	dz  }	||	z	  dz  ||
<   |
dz  }
Œ3 d}t        d|dz
  d	«      D ]C  }||   dz  ||dz      z  }d
|cxk  rdk  r
n n|r yd}Œ)d|cxk  rdk  r
n n|s yd}Œ>|r yd}ŒE | S )uØ  Check if base64 bytes decode to valid UTF-16BE with correct padding.

    A valid UTF-7 shifted sequence must:
    1. Contain at least 3 Base64 characters (18 bits, enough for one 16-bit
       UTF-16 code unit).
    2. Have zero-valued trailing padding bits (the unused low bits of the last
       Base64 sextet after the last complete 16-bit code unit).
    3. Decode to valid UTF-16BE â€” no lone surrogates.

    This rejects accidental ``+<alphanum>-`` patterns found in URLs, MIME
    boundaries, hex-encoded hashes (e.g. SHA-1 git refs), and other ASCII data.

    The caller (``_has_valid_utf7_sequences``) already checks ``b64_len >= 3``
    before calling this function, so *b64_bytes* is always at least 3 bytes.
    é   é   r   r   é   Fé   éÿ   r   i Ø  iÿÛ  Ti Ü  iÿß  )r   r    Ú	bytearrayÚrange)r#   ÚnÚ
total_bitsÚpadding_bitsÚlast_valÚmaskÚ	num_bytesÚrawÚbit_bufÚ	bit_countÚout_idxÚcÚ	prev_highÚiÚ	code_units                  r   Ú_is_valid_utf7_b64r:   G   sL  € ô  	ˆI‹€AØ�Q‘€Jð  ‘?€LØ�aÒÜ˜y¨™}Ñ-ˆà�\Ñ! QÑ&ˆØ�dŠ?Øð
 ˜a‘€IÜ
�IÓ
€CØ€GØ€IØ€GØò ˆØ˜a‘<¤;¨q¡>Ñ1ˆØ�Q‰ˆ	Ø˜‹>Ø˜‰NˆIØ# yÑ0°DÑ8ˆC�‰LØ�q‰L‰Gðð €IÜ�1�i !‘m QÓ'ò ˆØ˜‘V˜q‘[ C¨¨A©¡JÑ.ˆ	Ø�YÔ( &Õ(ÙÙØ‰IØ�yÔ* FÕ*ÙÙØ‰IáÙØ‰Iðð ˆ=Ðr   Úposc                 ó    — t         t        d«      z  }d}|dz
  }|dk\  r0| |   }|dv r|dz  }Œ||v r|dz  }|t        k\  ry|dz  }n	 y|dk\  rŒ0y)u  Return True if the ``+`` at *pos* is embedded in a base64 stream.

    Walks backward from *pos*, skipping CR/LF, and counts consecutive base64
    characters (including ``=`` for padding).  If 4 or more are found, the
    ``+`` is likely part of a PEM certificate, email attachment, or similar
    base64 blob rather than a real UTF-7 shift character.

    The walk stops at the fourth character rather than running to the start
    of the run.  Only the ``>= 4`` verdict is used, and newlines are
    skipped rather than ending the walk, so without the early exit a
    line-wrapped base64 blob â€” a PEM file, a MIME attachment, exactly what
    this guard exists to recognize â€” makes each ``+`` rescan everything
    before it, and the caller quadratic in the size of the blob.
    ó   =r   r'   >   é
   é   TF)r   Ú	frozensetr"   )r   r;   Úb64_with_padÚcountr8   Úbs         r   Ú_is_embedded_in_base64rD   „   s~   € ô $0´)¸D³/Ñ#A€LØ€EØˆa‰€AØ
ˆqŠ&Ø�‰GˆØ�ÑØ�‰FˆAØØ�ÑØ�Q‰JˆEØÔ)Ò)ØØ�‰F‰AàØð ˆq‹&ð r   Úb64_datac                 ó`   — t         | d      dz  t         | d      dz  z  t         | d      z  dz	  S )z@Decode the first (only) UTF-16 code unit of a single-unit block.r   é   r'   r%   r   )r    )rE   s    r   Ú_single_unitrH   ¥   sK   € ô 
�X˜a‘[Ñ	! RÑ	'Ü�x ‘{Ñ# qÑ(ñ	*ä
�h˜q‘kÑ
"ñ	#ð 
ñ	ð r   Úunitc                 óú   — d| cxk  xr dk  nc xsj d| cxk  xr dk  nc xsX d| cxk  xr dk  nc xsF d| cxk  xr dk  nc xs4 d	| cxk  xr d
k  nc xs" d| cxk  xr dk  nc xs d| cxk  xr dk  S c S )z>Script ranges where a lone shifted character plausibly occurs.é€   iÿ  i   iÿ  i    iÿ+  i 0  iÿ0  i N  iÿŸ  i ¬  i£×  i ÿ  iïÿ  © )rI   s    r   Ú_plausible_lone_unitrM   ®   s”   € ð 	�$Ö ˜&Ô ò 	$Ø�TÖ#˜VÔ#ò	$à�TÖ#˜VÔ#ò	$ð �TÖ#˜VÔ#ò	$ð �TÖ#˜VÔ#ò		$ð
 �TÖ#˜VÔ#ò	$ð �TÖ#˜VÑ#ðñ $ðr   c                 ó"  — d}t        t        | «      |«      }	 | j                  t        d«      |«      }|dk(  s||k\  ry|dz   }|t        | «      k  r| |   t        d«      k(  r|dz   }ŒQ|t        | «      k  rX| |   t        d«      k(  rG|t        | «      k  r6| |   t        d«      k(  r%|dz  }|t        | «      k  r| |   t        d«      k(  rŒ%|}Œ·t	        | |«      r|}ŒÆ|}||k  r!| |   t
        v r|dz  }||k  r| |   t
        v rŒ||k(  r|t        | «      k  r| |   t
        v r|}�Œ||z
  }| || }	|dk\  rt        d	„ |	D «       «      s|}�Œ5|dk\  r1t        |	«      r&|d
z  dz  dk(  rt        |	«      }
t        |
«      s|}�Œjyt        ||«      }�Œx)a&  Check that *data* contains at least one valid UTF-7 shifted sequence.

    A valid shifted sequence is ``+<base64 chars>`` terminated by either an
    explicit ``-`` or any non-Base64 character (per RFC 2152).  The base64
    portion must decode to valid UTF-16BE with correct zero-padding bits.
    The sequence ``+-`` is a literal plus sign and is **not** counted.

    *max_start* bounds where a shift may occur and *max_end* how far its
    base64 run may reach, so a run that begins inside the evidence window
    can finish beyond it (ADR-0006).  A run that outruns *max_end* is
    skipped rather than judged on the part that fits: the padding and
    surrogate checks read a cut run as a different run, and accepting on
    evidence we did not see is the one direction this must never fail in.
    r   Tú+r   Fr'   ú-é   c              3   ó,   K  — | ]  }|t         v –— Œ y ­w)N)r   )Ú.0rC   s     r   ú	<genexpr>z,_has_valid_utf7_sequences.<locals>.<genexpr>û   s   è ø€ Ò#J¸A A¬Ô$7Ñ#Jùs   ‚r%   r&   )Úminr   r   ÚordrD   r   Úanyr:   rH   rM   Úmax)r   r   r   r   ÚlimitÚ	shift_posr;   r8   Úb64_lenrE   rI   s              r   Ú_has_valid_utf7_sequencesr\   »   sÄ  € ð €EÜ”�D“	˜7Ó#€EØ
Ø—I‘Iœc #›h¨Ó.ˆ	Ø˜Š?˜i¨9Ò4ØØ˜!‰mˆà”�T“Š?˜t C™y¬C°«HÒ4Ø˜!‘GˆEØð ”�T“Š?˜t C™y¬C°«HÒ4Øœ˜D›	’/ d¨3¡i´3°s³8Ò&;Ø�q‘�ð œ˜D›	’/ d¨3¡i´3°s³8Ó&;àˆEØô " $¨	Ô2ØˆEØàˆØ�%Ši˜D ™G¤|Ñ3Ø�‰FˆAð �%Ši˜D ™G¤|Ò3à�Š:˜%¤# d£)Ò+°°Q±¼<Ñ0GàˆEÙØ�c‘'ˆØ˜˜A�;ˆð �aŠ<¤Ñ#JÀÔ#JÔ JØˆEÙð �aŠ<Ô.¨xÔ8ð ˜!‘ Ñ" aÒ'Ü# HÓ-�Ü+¨DÔ1Ø�EÙØÜ�C˜“ˆñO r   Nc                 óf   — d| v sd| v sd| v ryd| v ryd| v sd| v sd	| v sd
| v r
d| v rd| v ryyd| v ryy)zŸName the ISO-2022 variant whose designations appear in *data*.

    :returns: ``(encoding, language)`` or ``None`` when no designation is
        present.
    s   $(Os   $(Ps   $(Q)Úiso2022_jp_2004Újas   (I)Úiso2022_jp_extr_   s   $Bs   $@s   (Js   $(Dó   ó   )Úiso2022_jp_2r_   s   $)C)Ú
iso2022_krÚkoNrL   )r   s    r   Ú_iso2022_variantrf     ss   € ð �TÑ˜Z¨4Ñ/°:ÀÑ3EØ&ð �DÑØ%ð 	�TÑØ˜ÑØ˜ÑØ˜Ñð �d‰?˜w¨$™Ø)ð $ð �TÑØ!àr   c                 óä  — d| v }d| v }d| v }|s|s|sy|r4t        | «      }|�'t        | |d   «      rt        |d   t        |d   ¬«      S t	        t        | «      t        «      }t	        t        | «      dt        z  «      }|r3d	| v r/d
| v r+t        | ||«      rt        | d«      rt        dt        d¬«      S |r;| j                  «       r+t        | ||«      rt        | d«      rt        dt        d¬«      S y)aõ  Detect ISO-2022, HZ-GB-2312, and UTF-7 from escape/tilde/plus sequences.

    Every answer this stage returns decodes the whole window: a designation
    is three bytes that ordinary text can contain (``log: ESC $ B is the
    escape``), and a genuine ISO-2022 or HZ stream can still carry a bad
    byte past the header.  The gate costs one decode per hit only.

    :param data: The raw byte data to examine.
    :returns: A :class:`DetectionResult` if an escape encoding is found, or ``None``.
    ó   ó   ~ó   +Nr   r'   )ÚencodingÚ
confidenceÚlanguager   r   r   ÚhzÚzhzutf-7)
rf   r   r   r   rU   r   r   r   Úisasciir\   )r   Úhas_escÚ	has_tildeÚhas_plusÚvariantr   r   s          r   Údetect_escape_encodingru   =  s  € ð ˜ˆo€GØ˜�€IØ�tˆ|€Há™9©XØáÜ" 4Ó(ˆØÐÔ#8¸¸wÀq¹zÔ#JÜ"Ø  ™Ü3Ø  ™ôð ô  ”C˜“IÔ1Ó2€IÜ”#�d“)˜QÔ!3Ñ3Ó4€Gñ 	Ø�T‰MØ�T‰MÜ! $¨	°7Ô;Ü! $¨Ô-äØÜ/Øô
ð 	
ñ< 	Ø�L‰LŒNÜ% d¨I°wÔ?Ü! $¨Ô0äØÜ/Øô
ð 	
ð r   ) Ú__doc__Úchardet._utilsr   r   r   Úchardet.pipeliner   r   Úbytesr+   r
   Ú__annotations__ÚintÚboolr   r   r@   r   r   Ú	enumerater    Údictr"   r:   rD   rH   rM   r\   ÚtupleÚstrrf   ru   )r8   r6   s   00r   ú<module>r�      s~  ðò
÷ TÑ Sß Fñ ™E $¨Ó-Ó.€ˆeÓ .ð! ð !°#ð !Àð !Èó !ðJ X€
ˆEÓ WÙ(¨Ó4€ˆi˜‰nÓ 4ñ "+Ð+HÓ!I€�	˜#‘Ó Iñ 1:¸*Ó0E×F©¨¨1˜q !™tÓF€ˆT�#�s�(‰^Ó Fð Ð �3Ó ð: %ð :¨Dó :ðz ð ¨Sð °Tó ðB˜5ð  Só ð
˜sð 
 tó 
ðX Eð X°cð XÀCð XÈDó Xðv$˜5ð $ U¨3°¨8¡_°tÑ%;ó $ðN[ ð [¨?¸TÑ+Aô [ùó{ Gs   Á(C