Ë
    Dü´j+  ã                   ór   — d Z ddlmZmZmZmZmZmZ ddlm	Z	 dZ
dedededz  fd	„Zded
ee	   dee	   fd„Zy)aß  Three-tier language detection for filling DetectionResult languages.

Tier 1: hardcoded mapping for single-language encodings (e.g. Big5 -> Chinese).
Tier 2: statistical bigram scoring against the encoding's language-model variants.
Tier 3: decode to UTF-8 and score against the UTF-8 byte-level language models.

Note: ``from __future__ import annotations`` is intentionally omitted because
this module is compiled with mypyc, which does not support PEP 563 string
annotations.
é    )Ú_THIN_RARE_MAX_BYTESÚRARE_LANGUAGESÚBigramProfileÚhas_model_variantsÚinfer_languageÚscore_best_language)ÚDetectionResulti   ÚdataÚencodingÚreturnNc                 óŽ   — |dk(  r| S 	 | j                  |d¬«      j                  dd¬«      S # t        t        t        f$ r Y yw xY w)aP  Decode data from encoding and re-encode as UTF-8 for language scoring.

    Returns None if the encoding is unknown. For UTF-8, returns data as-is.
    Uses ``errors="ignore"`` because the data already passed byte-validity
    filtering for the detected encoding; any residual invalid bytes are
    irrelevant for language scoring.
    úutf-8Úignore)ÚerrorsÚsurrogatepassN)ÚdecodeÚencodeÚLookupErrorÚ	TypeErrorÚ
ValueError)r
   r   s     úW/root/workspace/ytshorts/venv/lib/python3.12/site-packages/chardet/pipeline/language.pyÚ_to_utf8r      s[   € ð �7ÒØˆðØ�{‰{˜8¨Hˆ{Ó5×<Ñ<Ø˜Oð =ó 
ð 	
øô œ¤JÐ/ò Ùðús   ‰#- ­AÁAÚresultsc           	      óZ  — | dt          } dt        | «      cxk  xr	 t        k  nc }g }d}d}d}|D �]v  }|xr2 |j                  duxr" |j                  t        v xr |j
                  du}|j
                  �|j                  �|s|j                  |«       Œf|j
                  }	|rdn
t        |	«      }
|
€,| r*t        |	«      r|€t        | «      }t        | |	||¬«      \  }}
|xr |
duxr |
t        v }|
�|rM| rKt        d«      r@t        | |	«      }|r2||k7  rt        |«      }|}t        |d||¬«      \  }}|
�
|�
|t        vr|}
|r|
�|
t        v r|j                  |«       �Œ1|
€|j                  |«       �ŒF|j                  t        |	|j                  |
|j                  «      «       �Œy |S )ub  Fill missing ``language`` fields on text results via the three-tier algorithm.

    Tier 1: single-language encodings via hardcoded map (instant).
    Tier 2: multi-language encodings via statistical bigram scoring (lazy).
    Tier 3: decode to UTF-8, score against UTF-8 language models (universal fallback).

    Binary results (``encoding is None``) are passed through unchanged, as
    are results that already have a non-``None`` language â€” except a
    :data:`~chardet.models.RARE_LANGUAGES` label on a thin input, which is
    re-derived through the same scoring so the thin-rare demotion band
    applies to statistically-attached labels too, not only to labels this
    function computes.  A re-derivation can only *demote* to a prevalent
    language; it never swaps one rare label for another.

    :param data: The raw byte data the results were produced from.  Truncated
        to the first 2 KB internally â€” bigram language models converge quickly.
    :param results: A list of :class:`DetectionResult` from the pipeline.
    :returns: A list of results with ``language`` filled in where possible.
    Nr   )ÚprofileÚdemote_thin_rarer   )Ú_LANG_SCORE_MAX_BYTESÚlenr   Úlanguager   r   Úappendr   r   r   r   r   r	   Ú
confidenceÚ	mime_type)r
   r   ÚthinÚfilledr   Úutf8_profileÚutf8_profile_srcÚresultÚrecheckr   ÚlangÚ_ÚescalateÚ	utf8_dataÚ	utf8_langs                  r   Úfill_languagesr.   .   sÝ  € ð, Ð&Ô&Ð'€Dð
 Œs�4‹yÖ/Ô/Ô/€DØ$&€FØ$(€GØ)-€LØ%)ÐØó 3ˆàò ,Ø—‘ tÐ+ò,à—‘¤>Ð1ò,ð —‘ tÐ+ð	 	ð �?‰?Ð" v§¡Ð'BÉ7Ø�M‰M˜&Ô!ØØ—?‘?ˆñ ‰t¤N°8Ó$<ˆàˆ<™DÔ%7¸Ô%AØˆÜ'¨Ó-�Ü)Ø�h¨À$ô‰GˆAˆtð ÒG˜D¨Ð,ÒG°¼Ð1GˆØˆL™H©$Ô3EÀgÔ3NÜ   xÓ0ˆIÙØÐ 0Ò0Ü#0°Ó#;�LØ'0Ð$Ü2Ø˜w°Ètô ‘��9ð �<ØÐ)¨i¼~Ñ.Mà$�DÙ˜˜¨´Ñ(>ð �M‰M˜&Ö!Øˆ\Ø�M‰M˜&Ö!à�M‰MÜ ¨&×*;Ñ*;¸TÀ6×CSÑCSÓTöðc3ðh €Mó    )Ú__doc__Úchardet.modelsr   r   r   r   r   r   Úchardet.pipeliner	   r   ÚbytesÚstrr   Úlistr.   © r/   r   ú<module>r7      sj   ðñ	÷÷ õ -ð
 Ð ð�5ð  Cð ¨E°D©Ló ð$TØ
ðTØ˜Ñ/ðTà	ˆ/ÑôTr/   