§
    |Øj*ƒ  ã            
       óÞ  — U d Z ddlmZmZmZ ddlmZmZmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZ ddlmZ  eh d£¦  «        Zee         ed	<    eh d
£¦  «        Zee         ed<    eh d£¦  «        Zee         ed<    eh d£¦  «        Zee         ed<    eh d£¦  «        Z ee         ed<   eeee dœZ!e"eee         f         ed<    eh d£¦  «        Z#ee         ed<   d„ e! $                    ¦   «         D ¦   «         Z%e"ee&f         ed<    e&e#¦  «        Z'e&ed<   de&dedede(fd„Z)de*e         defd„Z+de&d e*e         de*e         fd!„Z,de&d e*e         de*e         fd"„Z-d#Z.d$d$d%d&œZ/e"eef         ed'<   eZ0d(Z1d)Z2d*Z3d+edefd,„Z4de&d+ed-d.de(fd/„Z5de&d e*e         de*e         fd0„Z6d e*e         d1ede*e         fd2„Z7de&d e*e         de*e         fd3„Z8d4Z9d5Z:d e*e         de*e         fd6„Z;de&d e*e         de*e         fd7„Z<de&d+ede(fd8„Z=de&d e*e         d9e(de*e         fd:„Z>e9d;ez  z   Z?d<e@d=e@de@fd>„ZAd?e*e         de*e         fd@„ZBdAdBœde&d e*e         d9e(de*e         fdC„ZCdDS )Eu\  Stage 13: post-processing rank corrections.

After statistical scoring produces a ranked list of candidates, a chain
of rank corrections fixes up the ranking when bigrams alone are
insufficient â€” see :func:`postprocess_results` for the order.  The steps:
dead-heat priors (superset preference, era prevalence), rare-language
arbitration (ADR-0005), confusion-group resolution (delegated to
:mod:`chardet.pipeline.confusion`), niche Latin demotion, KOI8-T
promotion, classic-Mac line-ending promotion, and last of all the
decode-safety flip, which hands a winner whose only multi-byte evidence
is an undecodable trailing sequence to the best rival that can decode
the caller's complete input.

Note: ``from __future__ import annotations`` is intentionally omitted because
this module is compiled with mypyc, which does not support PEP 563 string
annotations.
é    )Údangling_tail_with_ascii_prefixÚdecodes_completelyÚdecodes_without_error)ÚART_LANGUAGEÚRARE_LANGUAGESÚget_enc_index)Ú_COMPAT_NAMES)ÚDetectionResult)ÚCONFUSION_BANDÚCONFUSION_FLOOR_RATIOÚSTRICT_TIER_MAX_CONFÚ_comparable_languagesÚarbitrate_distinguishing_bytesÚconfusion_pair_winnerÚdiffering_high_bytesÚresolve_confusion_groups)ÚREGISTRY>   ú	iso8859-1ú
iso8859-15Úcp1252Ú_COMMON_LATIN_ENCODINGS>.   é¡   é¢   é£   é¤   é¥   é¦   é¨   é©   éª   é«   é¬   é®   é¯   é±   é²   é³   é´   éµ   é¶   é¸   é¹   éº   é»   é¼   é½   é¾   é¿   éÀ   éÇ   éÈ   éÊ   éÌ   éÑ   éÒ   é×   éÙ   éà   éç   éè   éê   éì   éñ   éò   é÷   éù   éÿ   Ú_ISO_8859_10_DISTINGUISHING>   r   r   r   r   r   r   r    r!   r"   r$   é°   r%   r&   r'   r(   r)   é·   r+   r,   r-   r.   r/   r0   r1   r2   éÐ   r:   éÞ   éð   rC   éþ   Ú_ISO_8859_14_DISTINGUISHING>   rI   éÝ   rJ   rK   éý   rL   Ú_WINDOWS_1254_DISTINGUISHING>   r3   éÁ   éÂ   éÃ   éÄ   éÅ   éÆ   r4   r5   éÉ   r6   éË   r7   éÍ   éÎ   éÏ   r8   éÔ   éÕ   éÖ   r;   rN   rJ   Ú_HP_ROMAN8_DISTINGUISHING)z
iso8859-10z
iso8859-14Úcp1254z	hp-roman8Ú_DEMOTION_CANDIDATES>   é€   é�   éƒ   éŠ   éŒ   é�   éŽ   é�   r   r   r   r)   Ú_KOI8_T_DISTINGUISHINGc                 ó4   — i | ]\  }}|t          |¦  «        “ŒS © )Úbytes)Ú.0ÚencÚbyte_sets      ú‘/Users/tedpeters/Documents/Projects/Claude Projects/Misc Tools/notename-sheets/.venv/lib/python3.11/site-packages/chardet/pipeline/postprocess.pyú
<dictcomp>rr   ×   s1   € ð &ð &ð &Ù*˜S (€C�ˆx‰Œð&ð &ð &ó    Ú_DEMOTION_DELETEÚ_KOI8_T_DELETEÚdataÚtopÚtargetÚreturnc           
      ó”  — |j         pd}t          |                      dt          |         ¦  «        ¦  «        t          | ¦  «        k    rdS |j        |j        z
  t
          k    rdS t          | ||j         pdt          |         |j        €dnt          |j        f¦  «        |j        €dnt          |j        f¦  «        ¬¦  «        }||k    S )u}  Return True if *top*, a demotion candidate, has no byte evidence over *target*.

    Callers guarantee ``top.encoding`` is in :data:`_DEMOTION_CANDIDATES`.
    Two questions, cheapest first.  Does *data* contain any byte the
    candidate decodes differently from ISO-8859-1?  If not, the data is
    equally valid under both encodings, nothing at the byte level favors
    the candidate, and it is demoted.

    If such bytes are present, do they favor the candidate?  Presence
    alone is symmetric evidence: a Windows-1252 file whose only non-ASCII
    letter is an ``Ã–`` carries 0xD6, which HP-Roman8 reads as ``Ã¸``, so
    both candidates "contain" the byte and the question is which reading
    holds up.  That is a confusion-style arbitration between the candidate
    and its swap target on the distinguishing bytes alone (see
    :func:`~chardet.pipeline.confusion.arbitrate_distinguishing_bytes`),
    each side scored under the variant that actually won its slot.  The
    models decide when they can: one Welsh ``Åµ`` keeps ISO-8859-14 because
    the Welsh model knows that bigram and the Windows-1252 reading is a
    ``Ã°`` no Welsh model has seen.  When the models are silent, word shape
    decides: a Kven ``Ä‘`` keeps a Finnish file on ISO-8859-10 because a
    letter between letters beats the superscript ``Â¹`` Windows-1252 reads
    there.  A lone ``Ã–`` mid-word decides nothing either way, and the more
    prevalent encoding takes the evidence-free tie.

    The arbitration is only asked when the candidate's lead over the swap
    target is within :data:`~chardet.pipeline.confusion.CONFUSION_BAND`.
    A win by more than the band was decided on the full statistics, and
    re-litigating it on a handful of bytes is neither sound nor free: the
    scan is Python level, and mainstream Turkish text tops as windows-1254
    with hundreds of distinguishing bytes and a lead of 0.2.
    Ú NTF©Úlanguages_aÚlanguages_b)
ÚencodingÚlenÚ	translatert   Ú
confidencer   r   ra   ÚlanguageÚ	frozenset)rv   rw   rx   r   Úwinners        rq   Ú_should_demoter†   Ý   sË   € ð@ Œ|Ð!˜r€HÝ
ˆ4�>Š>˜$Õ 0°Ô :Ñ;Ô;Ñ<Ô<ÅÀDÁ	Ä	ÒIÐIØˆtØ
„~˜Ô)Ñ)­NÒ:Ð:ØˆuÝ+ØØØŒÐ˜2Ý˜XÔ&ØœLÐ0�D�DµiÀÄÀÑ6PÔ6PØ"œOÐ3�D�D½ÀFÄOÐCUÑ9VÔ9Vðñ ô €Fð �XÒÐrs   Ú
candidatesc                 óv   ‡— t          d„ | D ¦   «         ¦  «        Šˆfd„| D ¦   «         }t          |d„ ¬¦  «        S )aS  Pick the common Latin candidate that replaces a demoted top.

    Among the candidates within :data:`_DEAD_HEAT_EPSILON` of the
    highest-scoring one, era prevalence chooses (windows-1252 over
    iso-8859-1): inside that band the confidence order is noise, the very
    premise of the demotion.  A candidate trailing the best common Latin
    by more than the epsilon lost to it on real evidence and stays put.
    Equal era ranks (iso-8859-1 against iso-8859-15, both legacy ISO) keep
    confidence order, since ``min`` returns the first of equals and the
    candidates arrive ranked.
    c              3   ó$   K  — | ]}|j         V — Œd S ©N)r‚   ©rn   Úrs     rq   ú	<genexpr>z_swap_target.<locals>.<genexpr>  s$   è è € Ð5Ð5 Q�A”LÐ5Ð5Ð5Ð5Ð5Ð5rs   c                 ó:   •— g | ]}‰|j         z
  t          k    ¯|‘ŒS rl   )r‚   Ú_DEAD_HEAT_EPSILON)rn   rŒ   Ú	lead_confs     €rq   ú
<listcomp>z _swap_target.<locals>.<listcomp>  s+   ø€ ÐWÐWÐW�Q¨	°A´LÑ(@ÕDVÒ(VÐ(VˆqÐ(VÐ(VÐ(Vrs   c                 ó.   — t          | j        pd¦  «        S )Nr{   )Ú	_era_rankr   )rŒ   s    rq   ú<lambda>z_swap_target.<locals>.<lambda>  s   € ¥i°´
Ð0@¸bÑ&AÔ&A€ rs   )Úkey)ÚmaxÚmin)r‡   Úin_bandr�   s     @rq   Ú_swap_targetr™     sQ   ø€ õ Ð5Ð5¨*Ð5Ñ5Ô5Ñ5Ô5€IØWÐWÐWÐW˜*ÐWÑWÔW€GÝˆwÐAÐAÐBÑBÔBÐBrs   Úresultsc                 ó¼  ‡‡‡	— t          |¦  «        dk     s|d         j        t          vr|S d„ |dd…         D ¦   «         }|s|S t          |¦  «        Š	t	          | |d         ‰	¦  «        s|S |d         j        Š|d         j        }t          ‰	j        |‰	j        ‰	j        ¦  «        }ˆˆ	fd„|D ¦   «         }|r|d         j        n|Šˆˆfd„|D ¦   «         }|g|¢|¢S )	a÷  Demote a niche Latin top that its distinguishing bytes do not support.

    Some bigram models (iso-8859-10, iso-8859-14, windows-1254, hp-roman8)
    can win on data that contains only bytes shared with the common Western
    Latin encodings, or on a lone shared byte the models cannot arbitrate.
    When :func:`_should_demote` finds no byte-level evidence for the
    winning encoding, promote the swap target :func:`_swap_target` picks
    among the common Latin candidates and push the demoted encoding to
    last.

    The demoted entries take the confidence of the candidate they now sit
    behind.  Rank position alone does not survive the trip out to callers:
    ``detect_all`` re-sorts by confidence, and a stable sort hands an entry
    that kept the top score its old place back.

    :param data: The raw byte data the results were produced from.
    :param results: A list of :class:`DetectionResult` ranked by confidence.
    :returns: A new list (or the same list) with the demotion applied.
    é   r   c                 ó.   — g | ]}|j         t          v ¯|‘ŒS rl   )r   r   r‹   s     rq   r‘   z'_demote_niche_latin.<locals>.<listcomp>7  s%   € ÐRÐRÐR˜¨A¬JÕ:QÐ,QÐ,Q�!Ð,QÐ,QÐ,Qrs   é   Nc                 ó2   •— g | ]}|j         ‰k    ¯|‰u¯|‘ŒS rl   ©r   )rn   ÚxÚdemoted_encodingrx   s     €€rq   r‘   z'_demote_niche_latin.<locals>.<listcomp>B  s,   ø€ ÐWÐWÐW�A A¤JÐ2BÒ$BÐ$BÀqÐPVÀÀˆaÀÀÀrs   éÿÿÿÿc           	      óŽ   •— g | ]A}|j         ‰k    ¯t          |j         t          |j        ‰¦  «        |j        |j        ¦  «        ‘ŒBS rl   )r   r
   r—   r‚   rƒ   Ú	mime_type)rn   r¡   r¢   Ú	tail_confs     €€rq   r‘   z'_demote_niche_latin.<locals>.<listcomp>D  s]   ø€ ð 	ð 	ð 	ð ØŒ:Ð)Ò)Ð)õ 	ØŒJÝ�”˜iÑ(Ô(ØŒJØŒKñ		
ô 	
ð *Ð)Ð)rs   )	r€   r   ra   r™   r†   r‚   r
   rƒ   r¥   )
rv   rš   r‡   Útop_confÚpromotedÚothersÚdemoted_entriesr¢   r¦   rx   s
          @@@rq   Ú_demote_niche_latinr«     s2  øøø€ õ. ˆ7�|„|�aÒÐ˜7 1œ:Ô.Õ6JÐJÐJØˆØRÐR˜W Q R Rœ[ÐRÑRÔR€JØð ØˆÝ˜*Ñ%Ô%€FÝ˜$ ¨¤
¨FÑ3Ô3ð ØˆØ˜q”zÔ*ÐØ�qŒzÔ$€HÝØŒ˜ 6¤?°FÔ4Dñô €Hð XÐWÐWÐWÐW˜ÐWÑWÔW€FØ)/Ð=��r”
Ô%Ð%°X€Ið	ð 	ð 	ð 	ð 	ð ð	ñ 	ô 	€Oð Ð0�vÐ0 Ð0Ð0rs   c                 ó  — |r|d         j         dk    r|S t          d„ t          |¦  «        D ¦   «         d¦  «        }|€|S t          |                      dt
          ¦  «        ¦  «        t          | ¦  «        k    rt          ||¦  «        S |S )a  Promote KOI8-T over KOI8-R when Tajik-specific bytes are present.

    KOI8-T and KOI8-R share the entire 0xC0-0xFF Cyrillic letter block,
    making statistical discrimination difficult.  However, KOI8-T maps 12
    bytes in 0x80-0xBF to Tajik-specific Cyrillic letters where KOI8-R has
    box-drawing characters.  If any of these bytes appear, KOI8-T is the
    better match.
    r   úkoi8-rc              3   ó6   K  — | ]\  }}|j         d k    ¯|V — ŒdS )úkoi8-tNr    )rn   ÚirŒ   s      rq   r�   z!_promote_koi8t.<locals>.<genexpr>`  s2   è è € ÐQÐQ™D˜A˜q¸!¼*ÈÒ:PÐ:P�aÐ:PÐ:PÐ:PÐ:PÐQÐQrs   N)r   ÚnextÚ	enumerater€   r�   ru   Ú_promote_to_top)rv   rš   Ú	koi8t_idxs      rq   Ú_promote_koi8trµ   Q  s�   € ð ð �g˜a”jÔ)¨XÒ5Ð5ØˆåÐQÐQ¥I¨gÑ$6Ô$6ÐQÑQÔQÐSWÑXÔX€IØÐØˆå
ˆ4�>Š>˜$¥Ñ/Ô/Ñ0Ô0µC¸±I´IÒ=Ð=Ý˜w¨	Ñ2Ô2Ð2Ø€Nrs   g-Cëâ6?Úcp932Úcp949)Ú	shift_jisÚshift_jis_2004Úeuc_krÚ_DEAD_HEAT_SUPERSETSé   é   i @  r   c                 óf   — t          j        | ¦  «        }|€dS t          |j        ¦  «        }|| z  S )zHReturn the lowest era bit for *encoding* (lower = more prevalent today).Ni   @)r   ÚgetÚintÚera)r   ÚinforÁ   s      rq   r“   r“   Ž  s4   € åŒ<˜Ñ!Ô!€DØ€|ØˆwÝ
ˆdŒh‰-Œ-€CØ�#�‰:Ðrs   rƒ   z
str | Nonec                 óŠ  — t          ¦   «                              |¦  «        }|sdS | dt          …         }t          ¦   «         }|d         }t	          dt          |¦  «        ¦  «        D ]3}||         }|dk    s|dk    r|                     |dz  |z  ¦  «         |}Œ4|sdS |D ] \  }	}
}|�|	|k    rŒ|D ]}|
|         r  dS ŒŒ!dS )u0  Return True if *encoding*'s winning model weights a high-byte bigram present in *data*.

    A candidate whose model assigns zero weight to every non-ASCII bigram in
    the data earned its statistical score purely from ASCII bigrams â€” noise
    that cannot distinguish encodings.  Only the variant that actually won
    (*language*) counts: another language's variant having weight for those
    bytes says nothing about why *this* result is on top.  Only called on
    dead heats, so the Python-level scan of the (capped) data is off the
    hot path.
    FNr   rž   rb   é   T)r   r¿   Ú_EVIDENCE_SCAN_MAX_BYTESÚsetÚranger€   Úadd)rv   r   rƒ   ÚvariantsÚwindowÚseenÚprevr°   ÚbÚlangÚtableÚ_keyÚidxs                rq   Ú_has_high_byte_evidencerÒ   —  s  € õ ‰Œ×"Ò" 8Ñ,Ô,€HØð ØˆuØÐ+Õ+Ð+Ô,€FÝ‘U”U€DØ�!Œ9€DÝ�1•c˜&‘k”kÑ"Ô"ð ð ˆØ�1ŒIˆØ�4Š<ˆ<˜1 š9˜9Ø�HŠH�d˜a‘i 1‘_Ñ%Ô%Ð%ØˆˆØð ØˆuØ%ð ð Ñˆˆe�TØÐ D¨HÒ$4Ð$4ØØð 	ð 	ˆCØ�SŒzð Ø�t�t�tðð	ð ˆ5rs   c           
      óÞ  — |r|d         nd}|�|j         �t          |¦  «        dk     r|S d}t          |j         ¦  «        }t          dt          |¦  «        ¦  «        D ]J}||         }|j         €Œ|j        |j        z
  t
          k    r nt          |j         ¦  «        }||k     r|}|}ŒK|dk    r|S t          | |j         |j        ¦  «        st          ||¦  «        S ||         j         pd}t          |j         |t          d„ |j        ||         j        fD ¦   «         ¦  «        ¦  «        }	t          | |j         |t          |j         |¦  «        |	|	¬¦  «        }
|
|k    rt          ||¦  «        S |S )u]  Break statistical dead heats in favor of the more prevalent era.

    When several encodings score within :data:`_DEAD_HEAT_EPSILON` of the
    top result, the ranking among them is mostly an artifact of
    ASCII-bigram noise.  Promote the candidate from the most prevalent era
    (modern web > legacy ISO > Mac > regional > DOS > mainframe) so
    evidence-free dead heats resolve to the likeliest real-world answer.

    A top result whose models carry no weight for any high-byte bigram in
    the data has no evidence at all and yields outright.  One whose models
    do weight an observed bigram is not thereby safe: an English file with
    one capital ``Ã‰`` ranks MacRoman first because the MacRoman model
    reads 0xC9 as the ellipsis English text is full of, a lead worth
    2e-5.  Such a top is arbitrated against the prevalent candidate on the
    bytes the two read differently, under the languages the two can be
    compared in (see :func:`~chardet.pipeline.confusion.arbitrate_distinguishing_bytes`
    and confusion's ``_comparable_languages``): the Windows-1252 French
    model knows ``Ã‰cole`` even when the English one does not, while its
    Icelandic model may not read a Welsh ``dÅµr`` as ``dÃ°r`` against an
    encoding that models no Icelandic.  The prevalent candidate is
    promoted only when it wins outright; a tie keeps the top, so an
    ISO-8859-1 result tied with Windows-1252 on data without C1 bytes
    stays where the statistics put it.  Genuine MacRoman text never
    reaches the arbitration, since its hundreds of distinguishing bytes
    put Windows-1252 far outside the band.
    r   Nrœ   rž   r{   c              3   ó   K  — | ]}|®|V — Œ	d S rŠ   rl   ©rn   rÎ   s     rq   r�   z1_prefer_prevalent_on_dead_heat.<locals>.<genexpr>í  s4   è è € ð 
ð 
àØÐð àÐÐÐð
ð 
rs   r|   )r   r€   r“   rÇ   r‚   r�   rÒ   rƒ   r³   r   r„   r   r   )rv   rš   rw   Úbest_idxÚ	best_rankr°   rŒ   ÚrankÚrivalÚ
comparabler…   s              rq   Ú_prefer_prevalent_on_dead_heatrÛ   ¸  sª  € ð<  Ð
)ˆ'�!Œ*ˆ* T€CØ
€{�c”lÐ*­c°'©l¬l¸QÒ.>Ð.>ØˆØ€HÝ˜#œ,Ñ'Ô'€IÝ�1•c˜'‘l”lÑ#Ô#ð 	ð 	ˆØ�AŒJˆØŒ:ÐØØŒ>˜AœLÑ(Õ+=Ò=Ð=ØˆEÝ˜œÑ$Ô$ˆØ�)ÒÐØˆIØˆHøØ�1‚}€}ØˆÝ" 4¨¬°s´|ÑDÔDð 2Ý˜w¨Ñ1Ô1Ð1Ø�HÔÔ&Ð,¨"€EÝ&ØŒØÝð 
ð 
àœ w¨xÔ'8Ô'AÐBð
ñ 
ô 
ñ 	
ô 	
ñô €Jõ ,ØØŒØÝ˜Sœ\¨5Ñ1Ô1ØØðñ ô €Fð �‚€Ý˜w¨Ñ1Ô1Ð1Ø€Nrs   r°   c                 ó¬   ‡— | ‰         }t          |j        | d         j        |j        |j        ¦  «        }ˆfd„t          | ¦  «        D ¦   «         }|g|¢S )zDMove ``results[i]`` to the top, carrying the current top confidence.r   c                 ó&   •— g | ]\  }}|‰k    ¯|‘ŒS rl   rl   )rn   Újr¡   r°   s      €rq   r‘   z#_promote_to_top.<locals>.<listcomp>  s"   ø€ Ð7Ð7Ð7‘$�!�Q°°Q²°ˆA°°°rs   )r
   r   r‚   rƒ   r¥   r²   )rš   r°   rŒ   r¨   Úrests    `   rq   r³   r³      sb   ø€ à�Œ
€AÝØ	Œ
�G˜A”JÔ)¨1¬:°q´{ñô €Hð 8Ð7Ð7Ð7�) GÑ,Ô,Ð7Ñ7Ô7€DØÐ�tÐÐrs   c                 ó~  — |r|d         nd}|�|j         �t          |¦  «        dk     r|S t                               |j         ¦  «        }|€|S t	          dt          |¦  «        ¦  «        D ]Q}||         }|j        |j        z
  t          k    r n.|j         |k    r"t          | |¦  «        rt          ||¦  «        c S ŒR|S )zAPromote a Windows superset over its base encoding on a dead heat.r   Nrœ   rž   )	r   r€   r»   r¿   rÇ   r‚   r�   r   r³   )rv   rš   rw   Úsupersetr°   rŒ   s         rq   Ú_promote_superset_on_dead_heatrâ   
  sÒ   € ð
  Ð
)ˆ'�!Œ*ˆ* T€CØ
€{�c”lÐ*­c°'©l¬l¸QÒ.>Ð.>ØˆÝ#×'Ò'¨¬Ñ5Ô5€HØÐØˆÝ�1•c˜'‘l”lÑ#Ô#ð /ð /ˆØ�AŒJˆØŒ>˜AœLÑ(Õ+=Ò=Ð=ØˆEØŒ:˜Ò!Ð!Õ&;¸DÀ(Ñ&KÔ&KÐ!Ý" 7¨AÑ.Ô.Ð.Ð.Ð.øØ€Nrs   g{®Gáz”?g333333Ã?c                 óx  — | r| d         nd}|�8|j         �1|j        t          vs#|j        t          k    st          | ¦  «        dk     r| S t          dt          | ¦  «        ¦  «        D ]S}| |         }|j        |j        z
  t          k    r n0|j         �|j        €Œ3|j        t          vrt          | |¦  «        c S ŒT| S )aÒ  Demote a rare-language winner that leads a prevalent rival by a coin flip.

    Fires only when the winner's language is in
    :data:`~chardet.models.RARE_LANGUAGES`, its absolute confidence is
    inside the evidence-free zone, and a prevalent-language candidate sits
    within :data:`_RARE_ARBITRATION_MARGIN`.  Genuine rare-language text fails
    both gates: even short files score confidently, and their entire
    neighborhood is same-language variants.
    r   Nrœ   rž   )	r   rƒ   r   r‚   Ú _RARE_ARBITRATION_MAX_CONFIDENCEr€   rÇ   Ú_RARE_ARBITRATION_MARGINr³   )rš   rw   r°   rŒ   s       rq   Ú_arbitrate_rare_languageræ   7  sÕ   € ð  Ð
)ˆ'�!Œ*ˆ* T€CàˆØŒ<ÐØŒ<�~Ð-Ð-ØŒ>Õ=Ò=Ð=Ýˆw‰<Œ<˜!ÒÐàˆÝ�1•c˜'‘l”lÑ#Ô#ð /ð /ˆØ�AŒJˆØŒ>˜AœLÑ(Õ+CÒCÐCØˆEØŒ:Ð ¤Ð!3ØØŒ:�^Ð+Ð+Ý" 7¨AÑ.Ô.Ð.Ð.Ð.ð ,à€Nrs   c                 ó¶  — |r|d         nd}|�|j         �t          |¦  «        dk     r|S t          |j         ¦  «        t          k    r|S |j        t
          k    r|S |                      d¦  «        dk    s|                      d¦  «        t          k     r|S t          dt          |¦  «        ¦  «        D ]¦}||         }|j
        |j
        z
  t          k    r nƒ|j         �{t          |j         ¦  «        t          k    r^t          d„ |j        |j        fD ¦   «         ¦  «        }t          | |j         |j         |¦  «        |j         k    r nt          ||¦  «        c S Œ§|S )uN  Promote a classic-Mac candidate when line endings are bare ``\r``.

    Classic Mac OS is the only platform that terminated lines with a lone
    carriage return, so data with several ``\r`` bytes and no ``\n`` is
    near-certainly Mac-era text.  When a LEGACY_MAC candidate scores within
    :data:`_CR_MAC_BAND` of a non-Mac top result, promote it â€” unless the
    pair has a distinguishing-byte map and the byte-level evidence says the
    current top wins: a platform prior must not overturn direct evidence
    that confusion resolution may have just used to establish the top.
    r   Nrœ   ó   
ó   rž   c              3   ó   K  — | ]}|®|V — Œ	d S rŠ   rl   rÕ   s     rq   r�   z2_promote_mac_on_cr_line_endings.<locals>.<genexpr>y  s0   è è € ð ð Ø¸tÐ?O�Ð?OÐ?OÐ?OÐ?Oðð rs   )r   r€   r“   Ú_LEGACY_MAC_ERArƒ   r   ÚfindÚcountÚ_CR_MAC_MIN_LINESrÇ   r‚   Ú_CR_MAC_BANDr„   r   r³   )rv   rš   rw   r°   rŒ   Úlangss         rq   Ú_promote_mac_on_cr_line_endingsrñ   W  st  € ð  Ð
)ˆ'�!Œ*ˆ* T€CØ
€{�c”lÐ*­c°'©l¬l¸QÒ.>Ð.>ØˆÝ�”ÑÔ¥/Ò1Ð1Øˆð
 „|•|Ò#Ð#ØˆØ‡y‚y�ÑÔ˜1ÒÐ §
¢
¨5Ñ 1Ô 1Õ4EÒ EÐ EØˆÝ�1•c˜'‘l”lÑ#Ô#ð /ð /ˆØ�AŒJˆØŒ>˜AœLÑ(­<Ò7Ð7ØˆEØŒ:Ð!¥i°´
Ñ&;Ô&;½Ò&NÐ&Nõ ð ð Ø"%¤,°´
Ð!;ðñ ô ñ ô ˆEõ & d¨C¬L¸!¼*ÀeÑLÔLØ”<ò ð  ð �Ý" 7¨AÑ.Ô.Ð.Ð.Ð.øØ€Nrs   c                 óv   — t          | |¦  «        sdS t          j        |¦  «        }|du pt          | |¦  «        S )a3  Check that *data* decodes completely under *encoding* and its output name.

    The flip's promise is that the caller's ``data.decode(result)`` works,
    and the caller sees the *public* name: ``compat_names=True`` (the
    default) can remap to a strictly narrower codec (``euc_jis_2004`` is
    reported as ``EUC-JP``), so a rival must decode under both names to be
    promoted.  ``prefer_superset=True`` can also narrow (cp125x leaves
    codepoints undefined that iso-8859-x maps), but that output transform
    checks the data itself before remapping.
    FN)r   r	   r¿   )rv   r   Údisplays      rq   Ú_decodes_under_public_namesrô   ‰  sE   € õ ˜d HÑ-Ô-ð ØˆuÝÔ Ñ)Ô)€GØ�dˆ?Ð?Õ0°°wÑ?Ô?Ð?rs   Úinput_truncatedc                óv  — |r|d         nd}|sR|�P|j         �It          |¦  «        dk     s6t          d„ | dd…         D ¦   «         ¦  «        rt          | |j         ¦  «        s|S t	          dt          |¦  «        ¦  «        D ]8}||         }|j         �t          | |j         ¦  «        sŒ't          ||¦  «        c S |S )a‹  Promote a strictly decoding rival over a winner with no real evidence.

    Byte-validity filtering runs incremental decoders with ``final=False``,
    tolerating an incomplete multi-byte sequence at the end because detection
    input is often a prefix of a larger whole.  When chardet examined the
    caller's *entire* input, that tolerance can hand back an encoding the
    caller's very next ``data.decode()`` will reject --- a four-byte
    ``iso-8859-1`` word ending in ``0xE1`` detected as utf-8 (issue #380).

    Fires only when *data* is the whole of what the caller handed over ---
    *input_truncated* is False --- the tail can actually hold a
    dangling sequence (a high byte in the final four, multi-byte winner),
    and the winner's tolerant decode is **non-empty pure ASCII** --- its
    only multi-byte evidence is the dangling tail itself.  An empty
    tolerant decode (the whole input is one clipped sequence) is zero
    evidence, not ASCII evidence, and disqualifies the flip.  The
    best-ranked rival that decodes the input completely under both its
    internal and public names then takes the top slot, regardless of the
    confidence gap: an all-ASCII-evidence winner detected nothing the
    rival did not also detect, and any statistical lead it holds comes
    from ASCII bigrams the rival matched equally well.  The scan sees the
    ranking as given, which under ``full_ranking=False`` is pruned; if no
    listed rival decodes, the winner stands (measured across a 648-case
    accent-final sweep, the pruned ranking always carried a decodable
    rival).

    The pure-ASCII condition is what makes the unconditional flip safe.  A
    short mid-character CJK cut has a correct answer that cannot decode the
    input --- flipping it to whichever single-byte codec happens to decode
    the bytes trades a right answer for a wrong one, and a 5-40 byte sweep
    measured exactly that under a gap-based rule (34 correct CJK answers
    lost, Big5 becoming cp1125).  Such a winner has decoded real multi-byte
    characters and keeps its ranking; with the pure-ASCII condition in
    place, the same sweep measures zero lost answers at any gap.
    r   Nrœ   c              3   ó"   K  — | ]
}|d k    V — ŒdS )rb   Nrl   )rn   rÍ   s     rq   r�   z+_prefer_decodable_on_tie.<locals>.<genexpr>Ð  s&   è è € Ð0Ð0 �1˜’9Ð0Ð0Ð0Ð0Ð0Ð0rs   éüÿÿÿrž   )r   r€   Úanyr   rÇ   rô   r³   )rv   rš   rõ   rw   r°   rŒ   s         rq   Ú_prefer_decodable_on_tierú   š  sã   € ðR  Ð
)ˆ'�!Œ*ˆ* T€Càðàˆ;ØŒ<ÐÝˆw‰<Œ<˜!ÒÐõ Ð0Ð0 d¨2¨3¨3¤iÐ0Ñ0Ô0Ñ0Ô0ð õ /¨t°S´\ÑBÔBð ð ˆÝ�1•c˜'‘l”lÑ#Ô#ð +ð +ˆØ�AŒJˆØŒ:ÐÕ%@ÀÀqÄzÑ%RÔ%RÐØÝ˜w¨Ñ*Ô*Ð*Ð*Ð*Ø€Nrs   rœ   Útop1Útop2c                 ó`   — |t           z
  }| t          k     rt          || t          z  ¦  «        }|S )uS  Return the score below which the rank corrections cannot examine a candidate.

    One half of the pruning contract statistical scoring consumes: given
    the running top two encoding scores, every candidate at or above this
    floor must carry its exact full-ranking score, or a correction could
    fire on an understated (or missing) entry and ``detect()`` would
    diverge from the unpruned full ranking.  The floor trails the
    second-best score by the corrections' reach; while the top is low
    enough for confusion resolution's strict tier to open, it extends down
    to that tier's floor, because a strict-tier promotion may raise any
    candidate above the tier floor into position 0 before the other
    corrections evaluate their triggers.

    One correction sits deliberately outside this floor: the decode-safety
    flip (:func:`_prefer_decodable_on_tie`) scans the ranking *as given*,
    including pruned-path tails whose entries may be understated or absent
    â€” a measured trade-off documented in its own docstring, not a floor
    violation to fix by widening the reach.
    )Ú_CORRECTION_REACHr   r—   r   )rû   rü   Úfloors      rq   Úscoring_floorr   ç  s5   € ð( Õ$Ñ$€EØÕ"Ò"Ð"Ý�E˜4Õ"7Ñ7Ñ8Ô8ˆØ€Lrs   Únear_topc                 ó¢   — g }t          d„ | D ¦   «         ¦  «        r|                     t          ¦  «         d| v r|                     d¦  «         |S )u  Return the encodings the corrections look up by name, given the near-top set.

    The other half of the pruning contract: :func:`postprocess_results`
    inspects some encodings wherever they rank (the common Western Latin
    trio for niche Latin demotion, KOI8-T for the KOI8-R promotion), so
    pruning must score every variant of these whenever a trigger encoding
    sits at or above the :func:`scoring_floor` â€” confusion resolution may
    promote any such candidate to the top before those triggers are
    evaluated.
    c              3   ó(   K  — | ]}|t           v V — Œd S rŠ   )ra   )rn   Úes     rq   r�   z#forced_encodings.<locals>.<genexpr>  s(   è è € Ð
7Ð
7¨ˆ1Õ$Ð$Ð
7Ð
7Ð
7Ð
7Ð
7Ð
7rs   r­   r¯   )rù   Úextendr   Úappend)r  Úforceds     rq   Úforced_encodingsr    s]   € ð €FÝ
Ð
7Ð
7¨hÐ
7Ñ
7Ô
7Ñ7Ô7ð /Ø�ŠÕ-Ñ.Ô.Ð.Ø�8ÐÐØ�Š�hÑÔÐØ€Mrs   F©rõ   c                ó  — t          | |¦  «        }t          | |¦  «        }t          |¦  «        }t          | |¦  «        }t	          | |¦  «        }t          | |¦  «        }t          | |¦  «        }t          | ||¬¦  «        S )aì  Apply rank corrections to the statistically scored results.

    Steps run in sequence, weakest evidence first: dead-heat priors
    (superset preference, era prevalence), then confusion-group resolution,
    niche Latin demotion, and KOI8-T promotion (byte-level evidence), and
    finally the classic-Mac line-ending promotion (platform evidence that
    should override the priors).  The decode-safety tiebreak runs last of
    all: whatever the ranking settled on, a winner that cannot decode the
    caller's complete input, and whose own evidence is nothing but the
    undecodable tail, yields to the best-ranked rival that can decode it.

    :param data: The raw byte data the results were produced from.
    :param results: A list of :class:`DetectionResult` ranked by confidence.
    :param input_truncated: True when *data* is a chardet-made slice rather
        than the caller's whole input --- the ``max_bytes`` slice, the
        evidence-cap slice, or ``UniversalDetector``'s buffer cap.  Any of
        them means the bytes here are not the whole story, so the
        decode-safety tiebreak, which reasons about what the caller will
        decode, stands down.
    :returns: A new list (or the same list) with rank corrections applied.
    r	  )râ   rÛ   ræ   r   r«   rµ   rñ   rú   )rv   rš   rõ   s      rq   Úpostprocess_resultsr    s€   € õ6 -¨T°7Ñ;Ô;€GÝ,¨T°7Ñ;Ô;€GÝ& wÑ/Ô/€GÝ& t¨WÑ5Ô5€GÝ! $¨Ñ0Ô0€GÝ˜T 7Ñ+Ô+€GÝ-¨d°GÑ<Ô<€GÝ# D¨'À?ÐSÑSÔSÐSrs   N)DÚ__doc__Úchardet._utilsr   r   r   Úchardet.modelsr   r   r   Úchardet.output_namesr	   Úchardet.pipeliner
   Úchardet.pipeline.confusionr   r   r   r   r   r   r   r   Úchardet.registryr   r„   r   ÚstrÚ__annotations__rF   rÀ   rM   rP   r_   ra   Údictrj   Úitemsrt   rm   ru   Úboolr†   Úlistr™   r«   rµ   r�   r»   rï   rî   rë   rÅ   r“   rÒ   rÛ   r³   râ   rå   rä   ræ   rñ   rô   rú   rþ   Úfloatr   r  r  rl   rs   rq   ú<module>r     sÄ  ððð ð ð$ð ð ð ð ð ð ð ð ð ð
 GÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ .Ð .Ð .Ð .Ð .Ð .Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð &Ð %Ð %Ð %Ð %Ð %ð +4¨)ðð ð ñ+ô +Ð ˜ 3œð ð ñ ð /8¨ið/ð /ð /ñ1/ô 1/Ð ˜Y sœ^ð 1ð 1ñ 1ðn /8¨ið ð  ð  ñ"/ô "/Ð ˜Y sœ^ð "ð "ñ "ðT 09¨yØ(Ð(Ð(ñ0ô 0Ð ˜i¨œnð ð ñ ð -6¨Iðð ð ñ-ô -Ð ˜9 Sœ>ð ð ñ ðB .Ø-Ø*Ø*ð	3ð 3Ð �d˜3 	¨#¤Ð.Ô/ð ð ñ ð *3¨ØLÐLÐLñ*ô *Ð ˜	 #œð ð ñ ð&ð &Ø.B×.HÒ.HÑ.JÔ.Jð&ñ &ô &Ð �$�s˜E�zÔ"ð ð ñ ð ˜Ð4Ñ5Ô5€�Ð 5Ð 5Ñ 5ð-˜ð - _ð -¸oð -ÐRVð -ð -ð -ð -ð`C˜T /Ô2ð C°ð Cð Cð Cð Cð"01Ø
ð01à�/Ô"ð01ð 
ˆ/Ôð01ð 01ð 01ð 01ðfØ
ðà�/Ô"ðð 
ˆ/Ôðð ð ð ð8 Ð ð ØØð(ð (Ð �d˜3 ˜8”nð ð ñ ð €ð Ð ð €ð !Ð ð˜ð  ð ð ð ð ð %ð °3ð À,ð ÐSWð ð ð ð ðBEØ
ðEà�/Ô"ðEð 
ˆ/ÔðEð Eð Eð EðP˜T /Ô2ð °sð ¸tÀOÔ?Tð ð ð ð ðØ
ðà�/Ô"ðð 
ˆ/Ôðð ð ð ðJ  Ð ð
 $(Ð  ðØ�/Ô"ðà	ˆ/Ôðð ð ð ð@/Ø
ð/à�/Ô"ð/ð 
ˆ/Ôð/ð /ð /ð /ðd@ eð @°sð @¸tð @ð @ð @ð @ð"?Ø
ð?à�/Ô"ð?ð ð	?ð
 
ˆ/Ôð?ð ?ð ?ð ?ðT -¨q°>Ñ/AÑAÐ ð˜ð  Uð ¨uð ð ð ð ð4˜t Cœyð ¨T°#¬Yð ð ð ð ð. "ð	"Tð "Tð "TØ
ð"Tà�/Ô"ð"Tð ð	"Tð
 
ˆ/Ôð"Tð "Tð "Tð "Tð "Tð "Trs   