Ë
    Dü´j)2  ã                   óÖ   — U d Z ddlZddlmZmZmZ dZdZdZdZ	dZ
d	Zd
ZdZdez   Zeed<   dedede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dz  fd„Zdedefd„Zddededefd„Zy)a«  Stage 1a+: UTF-16/UTF-32 detection for data without BOM.

This stage runs after BOM detection but before binary detection.
UTF-16 and UTF-32 encoded text contains characteristic null-byte patterns
that would otherwise cause binary detection to reject the data.

Note: ``from __future__ import annotations`` is intentionally omitted because
this module is compiled with mypyc, which does not support PEP 563 string
annotations.
é    N)ÚASCII_TEXT_BYTESÚDETERMINISTIC_CONFIDENCEÚDetectionResulti   é   é
   g¸…ëQ¸ž?ç      à?gš™™™™™©?gffffffæ?g333333Ã?ó    Ú_NULL_SEPARATOR_ALLOWEDÚdataÚ	null_fracÚreturnc                 óD   — |t         k\  ry| j                  dt        «       S )u‹  Return True if the data looks like ASCII with null byte separators.

    :param data: The raw byte sample to examine.
    :param null_frac: The positional null fraction for this UTF-16 candidate
        (i.e. fraction of null bytes in even positions for BE, or odd positions
        for LE) â€” not the total null fraction across all bytes.

    Checks two conditions:
    1. The positional null fraction is below ``_NULL_SEPARATOR_MAX_FRACTION``
    2. Every non-null byte is printable ASCII or common whitespace

    When both conditions are met, the nulls are likely field separators
    (e.g. ``find -print0``), not UTF-16 encoding artifacts.
    FN)Ú_NULL_SEPARATOR_MAX_FRACTIONÚ	translater
   )r   r   s     úV/root/workspace/ytshorts/venv/lib/python3.12/site-packages/chardet/pipeline/utf1632.pyÚ_is_null_separator_patternr   =   s%   € ð Ô0Ò0ØØ�~‰~˜dÔ$;Ó<Ð<Ð<ó    c                 ón   — | dt          }t        |«      t        k  ryt        |«      }|�|S t	        |«      S )a  Detect UTF-32 or UTF-16 encoding from null-byte patterns.

    UTF-32 is checked before UTF-16 since UTF-32 patterns are more specific.

    :param data: The raw byte data to examine.
    :returns: A :class:`DetectionResult` if a strong pattern is found, or ``None``.
    N)Ú_SAMPLE_SIZEÚlenÚ_MIN_BYTES_UTF16Ú_check_utf32Ú_check_utf16)r   ÚsampleÚresults      r   Údetect_utf1632_patternsr   Q   sD   € ð �-”<Ð €Fä
ˆ6ƒ{Ô%Ò%Øô ˜&Ó!€FØÐØˆô ˜ÓÐr   c           	      óÔ  ‡ — t        ‰ «      t        ‰ «      dz  z
  }|t        k  ry‰ d| Š |dz  }t        ˆ fd„t        dt        ‰ «      d«      D «       «      }t        ˆ fd„t        dt        ‰ «      d«      D «       «      }||k(  r8||z  dkD  r0	 ‰ j	                  d«      }t        |«      rt        dt        d¬«      S 	 t        ˆ fd	„t        d
t        ‰ «      d«      D «       «      }t        ˆ fd„t        dt        ‰ «      d«      D «       «      }||k(  r9||z  dkD  r1	 ‰ j	                  d«      }t        |«      rt        dt        d¬«      S 	 yy# t        $ r Y Œšw xY w# t        $ r Y yw xY w)a’  Check for UTF-32 encoding based on 4-byte unit structure.

    For valid Unicode (U+0000 to U+10FFFF = 0x0010FFFF):
    - UTF-32-BE: the first byte of each 4-byte unit is always 0x00
    - UTF-32-LE: the last byte of each 4-byte unit is always 0x00

    For BMP characters (U+0000 to U+FFFF), additionally:
    - UTF-32-BE: the second byte is also 0x00
    - UTF-32-LE: the third byte is also 0x00
    é   Nc              3   ó4   •K  — | ]  }‰|   d k(  sŒd–— Œ y­w©r   é   N© ©Ú.0Úir   s     €r   ú	<genexpr>z_check_utf32.<locals>.<genexpr>{   ó   øè ø€ ÒJ˜a¸TÀ!¹WÈ»\œÑJùó   ƒ‘r   c              3   ó:   •K  — | ]  }‰|d z      dk(  sŒd –— Œ y­w)r!   r   Nr"   r#   s     €r   r&   z_check_utf32.<locals>.<genexpr>}   s    øè ø€ ÒO˜q¸dÀ1ÀqÁ5¹kÈQÓ>NœÑOùs   ƒ”r   z	utf-32-be©ÚencodingÚ
confidenceÚlanguagec              3   ó4   •K  — | ]  }‰|   d k(  sŒd–— Œ y­wr    r"   r#   s     €r   r&   z_check_utf32.<locals>.<genexpr>Œ   s   øè ø€ ÒI˜Q¸DÀ¹GÀq»L”qÑIùr(   é   c              3   ó4   •K  — | ]  }‰|   d k(  sŒd–— Œ y­wr    r"   r#   s     €r   r&   z_check_utf32.<locals>.<genexpr>Ž   r'   r(   é   z	utf-32-le)	r   Ú_MIN_BYTES_UTF32ÚsumÚrangeÚdecodeÚ_looks_like_textr   r   ÚUnicodeDecodeError)r   Útrimmed_lenÚ	num_unitsÚbe_first_nullÚbe_second_nullÚtextÚle_last_nullÚle_third_nulls   `       r   r   r   g   sx  ø€ ô �d“)œs 4›y¨1™}Ñ-€KØÔ%Ò%ØØ��Ð€Dà˜qÑ €Iô ÓJ¤5¨¬C°«I°qÓ#9ÔJÓJ€MäÓO¤E¨!¬S°«Y¸Ó$:ÔOÓO€Nà˜	Ò! n°yÑ&@À3Ò&Fð		Ø—;‘;˜{Ó+ˆDÜ Ô%Ü&Ø(Ü7Ø!ôð ð &ô ÓI¤%¨¬3¨t«9°aÓ"8ÔIÓI€LäÓJ¤5¨¬C°«I°qÓ#9ÔJÓJ€Mà�yÒ  ]°YÑ%>ÀÒ%Dð		Ø—;‘;˜{Ó+ˆDÜ Ô%Ü&Ø(Ü7Ø!ôð ð &ñ øô) "ò 	Ùð	ûô" "ò 	Øàð	ús$   Â-E Ä-E Å	EÅEÅ	E'Å&E'c                 óþ  ‡ — t        t        ‰ «      t        «      }||dz  z  }|t        k  ry|dz  }t	        ˆ fd„t        d|d«      D «       «      }t	        ˆ fd„t        d|d«      D «       «      }||z  }||z  }|t        k\  xr t        ‰ d| |«       }|t        k\  xr t        ‰ d| |«       }|s|syd||fd||fg}	||kD  r|	j                  «        d}
d	}d
}d}d
}|	D ]U  \  }}}	 ‰ d| j                  |«      }|rd}t        |«      sŒ,|dz  }t        |«      }|||dkD  rt        ndz   kD  sŒP|}|}
|}ŒW |
€y|r|dk(  xs	 |t        k\  }n|xr	 |t        k\  }|rt        |
t         d¬«      S y# t        $ r Y Œ›w xY w)a  Check for UTF-16 via null-byte patterns in alternating positions.

    UTF-16 encodes each BMP character as two bytes.  For characters whose
    code-point high byte is 0x00 (Latin, digits, basic punctuation, many
    control structures), one of the two bytes in each unit will be a null.
    Even for non-Latin scripts (Arabic, CJK, Cyrillic, etc.) a significant
    fraction of code units still contain at least one null byte.

    Non-UTF-16 single-byte encodings never contain null bytes, so even a
    small null-byte fraction in alternating positions is a strong signal.

    The null pattern only establishes that the data is UTF-16-like.  Byte
    order is always chosen by decoding both ways and comparing text-quality
    scores, with the null signal breaking near-ties (see below).
    r1   Nc              3   ó4   •K  — | ]  }‰|   d k(  sŒd–— Œ y­wr    r"   r#   s     €r   r&   z_check_utf16.<locals>.<genexpr>·   ó   øè ø€ ÒK˜a¸dÀ1¹gÈ»lœÑKùr(   r   c              3   ó4   •K  — | ]  }‰|   d k(  sŒd–— Œ y­wr    r"   r#   s     €r   r&   z_check_utf16.<locals>.<genexpr>¹   rA   r(   r!   z	utf-16-lez	utf-16-beg       ÀFTg        r*   )Úminr   r   r   r3   r4   Ú_UTF16_MIN_NULL_FRACTIONr   Úreverser5   r7   r6   Ú_text_qualityÚ_QUALITY_TIE_MARGINÚ_MIN_TEXT_QUALITYr   r   )r   Ú
sample_lenr9   Úbe_null_countÚle_null_countÚbe_fracÚle_fracÚle_qualifiedÚbe_qualifiedÚsidesÚbest_encodingÚbest_qualityÚbest_qualifiedÚviableÚqualified_side_decodedr+   Ú_fracÚ	qualifiedr<   ÚqualityÚaccepteds   `                    r   r   r   Ÿ   s  ø€ ô  ”S˜“Y¤Ó-€JØ�*˜q‘.Ñ €JØÔ$Ò$Øà˜a‘€Iô ÓK¤5¨¨J¸Ó#:ÔKÓK€MäÓK¤5¨¨J¸Ó#:ÔKÓK€Mà˜iÑ'€GØ˜iÑ'€Gð 	Ô+Ñ+ò 	GÜ*¨4°°Ð+<¸gÓFÐFð ð
 	Ô+Ñ+ò 	GÜ*¨4°°Ð+<¸gÓFÐFð ñ
 ™LØð ˜7 LÐ1°KÀÈ,Ð3WÐX€EØ�ÒØ�‰Œà $€MØ€LØ€NØ€FØ"Ðà&+ò 'Ñ"ˆ�%˜ð	Ø˜˜Ð$×+Ñ+¨HÓ5ˆDñ Ø%)Ð"Ü Ô%ØØ�!‰ˆÜ Ó%ˆØ�\¸FÀQºJÕ%8ÈCÑPÓPØ"ˆLØ$ˆMØ&‰Nð'ð  ÐØáð ˜Q‘;ÒC ,Ô2CÑ"C‰ð *ÒO¨lÔ>OÑ.OˆÙÜØ"Ü/Øô
ð 	
ð øôI "ò 	Ùð	ús   Ã(E0Å0	E<Å;E<r<   c                 ó`   — | sy| dd }t        d„ |D «       «      }|t        |«      z  t        kD  S )z9Quick check: is decoded text mostly printable characters.FNéô  c              3   óJ   K  — | ]  }|j                  «       s|d v sŒd–— Œ y­w)ú
	r!   N)Úisprintable)r$   Úcs     r   r&   z#_looks_like_text.<locals>.<genexpr>  s   è ø€ ÒJ˜!¨¯©¬¸AÀºM”AÑJùs   ‚#œ#)r3   r   Ú_MIN_PRINTABLE_FRACTION)r<   r   Ú	printables      r   r6   r6     s8   € áØØ�$�3ˆZ€FÜÑJ˜vÔJÓJ€IØ”s˜6“{Ñ"Ô%<Ñ<Ð<r   Úlimitc                 óz  — | d| }t        |«      }|dk(  ryd}d}d}d}d}|D ]d  }	t        j                  |	«      }
|
d   dk(  r|dz  }t        |	«      dk  sŒ4|dz  }Œ:|
d   dk(  r|dz  }ŒH|
dk(  s|	d	v r|dz  }ŒW|
d   d
k(  sŒ`|dz  }Œf ||z  dkD  ry||z  dkD  ry||z  }|||z  dz  z  }|dkD  r
|dkD  r|dz  }|S )uØ  Score how much *text* looks like real human-readable content.

    Returns a score in the range [-1.0, ~1.6).  Higher values indicate
    more natural text.  The practical maximum is 1.5 for all-ASCII-letter
    input (1.6 approaches as sample size grows with all ASCII letters plus
    whitespace).  A score of -1.0 means the content is almost certainly not
    valid text (too many control characters or combining marks).

    Scoring factors:

    * Base score: ratio of Unicode letters (category ``L*``) to sample length.
    * ASCII bonus: additional 0.5x weight for ASCII letters.  This is the
      primary signal for disambiguating endianness â€” correct decoding of
      Latin-heavy text produces ASCII letters, wrong decoding produces CJK.
    * Space bonus: +0.1 when the sample contains at least one whitespace
      character and is longer than 20 characters.
    * Rejection: returns -1.0 if >10% control characters or >20% combining
      marks (category ``M*``).
    Nr   g      ð¿ÚLr!   é€   ÚMÚZsr]   ÚCgš™™™™™¹?gš™™™™™É?r   é   )r   ÚunicodedataÚcategoryÚord)r<   rb   r   ÚnÚlettersÚmarksÚspacesÚcontrolsÚascii_lettersr_   ÚcatÚscores               r   rF   rF     s  € ð( �&�5ˆ\€FÜˆF‹€AØˆA‚vØà€GØ€EØ€FØ€HØ€Màò ˆÜ×"Ñ" 1Ó%ˆØˆq‰6�SŠ=Ø�q‰LˆGÜ�1‹v˜‹|Ø Ñ"‘Ø�‰V�sŠ]Ø�Q‰J‰EØ�DŠ[˜A ™MØ�a‰K‰FØ�‰V�s‹]Ø˜‰M‰Hðð �!�|�cÒØØˆq�y�3‚Øà�a‰K€Eà	ˆm˜aÑ 3Ñ&Ñ&€Eàˆ2‚v�&˜1’*Ø�‰ˆà€Lr   )r[   )Ú__doc__rj   Úchardet.pipeliner   r   r   r   r2   r   rD   rH   rG   r`   r   r
   ÚbytesÚ__annotations__ÚfloatÚboolr   r   r   r   Ústrr6   ÚintrF   r"   r   r   ú<module>r}      sù   ðò	ó ç XÑ Xð €ð Ð ØÐ ð  Ð ð Ð ð Ð ð Ð ð  $Ð ð ")Ð+;Ñ!;Ð ˜Ó ;ð= Uð =°uð =Àó =ð(  %ð  ¨O¸dÑ,Bó  ð,5�uð 5 °4Ñ!7ó 5ðpd�uð d °4Ñ!7ó dðN=˜3ð = 4ó =ñ9˜ð 9 Cð 9°%ô 9r   