Ë
    Dü´j/  ã                  óè  — U d Z ddlmZ ddlZddlmZ ddlmZ i d eddh«      “d	 ed
dh«      “d edh«      “d edh«      “d edh«      “d eddh«      “d eddh«      “d edh«      “d edh«      “d edh«      “d edh«      “d edh«      “d eh d£«      “d  ed!d"h«      “d# ed$h«      “d% edh«      “d& ed'h«      “ ed(h«       ed)h«       ed*h«       ed+h«       ed,h«       ed-h«       ed.d/h«       ed0h«       ed0h«       ed1d2h«       ed3h«       ed3h«      d4œ¥Z	d5e
d6<   d7Zd8e
d9<   d:Zd8e
d;<   d<„ f	 	 	 	 	 dNd=„Z ee«      Zd5e
d><   dOd?„Zi Zd5e
d@<   e	j#                  «       D ]=  \  ZZ ee«      xs eZ edA„ eD «       «      Zej-                  e e«       «      ez  ee<   Œ?  eedB„ ¬C«      Zd5e
dD<   dPdE„ZdPdF„ZdQdG„Z edHdIh«      ZdJe
dK<   dRdL„Z	 	 	 	 	 	 	 	 dSdM„Zy)TaÙ  Accuracy-evaluation tables and predicates.

Tools for asking *"is this detection acceptable, given what was expected?"*
Used by the test suite and by benchmarking/diagnostic scripts (e.g.,
``scripts/compare_detectors.py``, ``scripts/diagnose_accuracy.py``).

This module owns three kinds of tables:

1. **Directional supersets** (:data:`SUPERSETS`) -- detecting a superset
   encoding when the expected encoding is a subset is correct (e.g.,
   detecting UTF-8 when expected is ASCII), but not the reverse.

2. **Bidirectional encoding groups** (:data:`BIDIRECTIONAL_GROUPS`) --
   groups of encodings where any member is interchangeable with any other.

3. **Bidirectional language groups** (:data:`LANGUAGE_EQUIVALENCES`) --
   ISO 639-1 codes for languages that are nearly indistinguishable by
   statistical detection (e.g., Slovak/Czech, Malay/Indonesian).

The corresponding predicates are :func:`is_correct`,
:func:`is_equivalent_detection`, and :func:`is_language_equivalent`.
é    )ÚannotationsN)ÚCallable©Úlookup_encodingÚASCIIzutf-8Úcp1252zTIS-620z
iso8859-11Úcp874zISO-8859-11ÚGB2312Úgb18030ÚGBKÚBig5Ú	big5hkscsÚcp950Ú	Shift_JISÚcp932Úshift_jis_2004zShift-JISX0213zEUC-JPÚeuc_jis_2004zEUC-JISX0213zEUC-KRÚcp949ÚCP037Úcp1140zISO-2022-JP>   Úiso2022_jp_2Úiso2022_jp_extÚiso2022_jp_2004zISO2022-JP-1r   r   zISO2022-JP-3r   z
ISO-8859-1z
ISO-8859-2Úcp1250Úcp1251Úcp1256Úcp1253Úcp1255Úcp1254Úcp1257z	utf-16-lez	utf-16-bezutf-16z	utf-32-lez	utf-32-bezutf-32)z
ISO-8859-5z
ISO-8859-6z
ISO-8859-7z
ISO-8859-8z
ISO-8859-9zISO-8859-13zUTF-16z	UTF-16-LEz	UTF-16-BEzUTF-32z	UTF-32-LEz	UTF-32-BEúdict[str, frozenset[str]]Ú	SUPERSETS))r   r   r   útuple[tuple[str, ...], ...]ÚBIDIRECTIONAL_GROUPS))ÚskÚcs)ÚukÚruÚbgÚbe)ÚmsÚid)ÚnoÚdaÚsvÚLANGUAGE_EQUIVALENCESc                ó   — | S ©N© )Úxs    úP/root/workspace/ytshorts/venv/lib/python3.12/site-packages/chardet/evaluation.pyú<lambda>r6   w   s   € °€ ó    c                óf   ‡— i }| D ](  }t        ˆfd„|D «       «      }|D ]  }|| ‰|«      <   Œ Œ* |S )zJBuild a lookup: key -> frozenset of all equivalent keys in the same group.c              3  ó.   •K  — | ]  } ‰|«      –— Œ y ­wr2   r3   )Ú.0ÚnÚ	normalizes     €r5   ú	<genexpr>z%_build_group_index.<locals>.<genexpr>|   s   øè ø€ Ò7¨A™9 QŸ<Ñ7ùs   ƒ)Ú	frozenset)Úgroupsr<   ÚresultÚgroupÚnormedÚnames    `    r5   Ú_build_group_indexrD   u   sM   ø€ ð
 )+€FØò -ˆÜÓ7°Ô7Ó7ˆØò 	-ˆDØ&,ˆF‘9˜T“?Ò#ñ	-ð-ð €Mr7   Ú_LANGUAGE_EQUIVc                óL   — | |k(  ryt         j                  | «      }|duxr ||v S )a’  Check whether *detected* is an acceptable language for *expected*.

    Returns ``True`` when *expected* and *detected* are the same ISO 639-1
    code, or belong to the same equivalence group in
    :data:`LANGUAGE_EQUIVALENCES`.

    :param expected: Expected ISO 639-1 language code.
    :param detected: Detected ISO 639-1 language code.
    :returns: ``True`` if the languages are equivalent.
    TN)rE   Úget)ÚexpectedÚdetectedrA   s      r5   Úis_language_equivalentrJ   …   s4   € ð �8ÒØÜ×Ñ Ó)€EØ˜ÐÒ2 ¨UÐ!2Ð2r7   Ú_NORMALIZED_SUPERSETSc              #  ó:   K  — | ]  }t        |«      xs |–— Œ y ­wr2   r   )r:   Úss     r5   r=   r=   �   s   è ø€ ÒD°Aœ¨Ó*Ò/¨aÓ/ÑDùó   ‚c                ó    — t        | «      xs | S r2   r   )r;   s    r5   r6   r6   ¢   s   € ¬o¸aÓ.@Ò.EÀA€ r7   )r<   Ú_NORMALIZED_BIDIRc                ó’   — | €|du S |€yt        | «      xs | j                  «       }t        |«      xs |j                  «       }||k(  S )aô  Check whether *detected* names the very same encoding as *expected*.

    Only alias and case differences are normalized away, so
    ``windows-1252`` matches ``cp1252``. Unlike :func:`is_correct`, this
    credits neither supersets nor byte-order variants: detecting UTF-8
    for an ASCII file is ``False`` here.

    This is the stricter convention some other detectors score
    themselves against. Reporting it alongside :func:`is_correct` makes
    the two conventions directly comparable instead of leaving the
    difference implicit.

    :param expected: The expected encoding name, or ``None`` for binary files.
    :param detected: The detected encoding name, or ``None``.
    :returns: ``True`` if both names resolve to the same encoding.
    NF)r   Úlower©rH   rI   Únorm_expÚnorm_dets       r5   Úis_exact_matchrV   ¦   sU   € ð" ÐØ˜4ÐÐØÐØÜ˜xÓ(Ò<¨H¯N©NÓ,<€HÜ˜xÓ(Ò<¨H¯N©NÓ,<€HØ�xÑÐr7   c                óô   — | €|du S |€yt        | |«      ryt        | «      xs | j                  «       }t        |«      xs |j                  «       }|t        v r|t        |   v ry|t        v xr |t        |   v S )a  Check whether *detected* is an acceptable answer for *expected*.

    Acceptable means:

    1. Exact match (after normalization), OR
    2. Both belong to the same bidirectional byte-order group, OR
    3. *detected* is a known superset of *expected*.

    See :func:`is_exact_match` for the stricter exact-only predicate.

    :param expected: The expected encoding name, or ``None`` for binary files.
    :param detected: The detected encoding name, or ``None``.
    :returns: ``True`` if the detection is acceptable.
    NFT)rV   r   rR   rP   rK   rS   s       r5   Ú
is_correctrX   À   s—   € ð ÐØ˜4ÐÐØÐØô �h Ô)Øä˜xÓ(Ò<¨H¯N©NÓ,<€HÜ˜xÓ(Ò<¨H¯N©NÓ,<€Hð Ô$Ñ$¨Ô5FÀxÑ5PÑ)PØð 	Ô)Ð)ò 	8ØÔ-¨hÑ7Ð7ðr7   c                ó^   — t        j                  d| «      }dj                  d„ |D «       «      S )z4NFKD-normalize *text* and strip all combining marks.ÚNFKDÚ c              3  óL   K  — | ]  }t        j                  |«      rŒ|–— Œ y ­wr2   )ÚunicodedataÚ	combining)r:   Úcs     r5   r=   z#_strip_combining.<locals>.<genexpr>é   s   è ø€ ÒC˜¬+×*?Ñ*?ÀÕ*B”1ÑCùs   ‚$�$)r]   r<   Újoin)ÚtextÚnfkds     r5   Ú_strip_combiningrc   æ   s)   € ä× Ñ  ¨Ó.€DØ�7‰7ÑC˜dÔCÓCÐCr7   )õ   Â¤õ   â‚¬)re   rd   zfrozenset[tuple[str, str]]Ú_EQUIVALENT_SYMBOL_PAIRSc                óR   — | |k(  ry| |ft         v ryt        | «      t        |«      k(  S )uò   Return True if characters *a* and *b* are functionally equivalent.

    Equivalent means:
    - Same character, OR
    - Same base letter after stripping combining marks, OR
    - An explicitly listed symbol equivalence (e.g. Â¤ â†” â‚¬)
    T)rf   rc   )ÚaÚbs     r5   Ú_chars_equivalentrj   ö   s4   € ð 	ˆA‚vØØ	ˆ1€vÔ)Ñ)Øä˜AÓÔ"2°1Ó"5Ñ5Ð5r7   c                ó|  — |€|du S |€yt        |«      xs |j                  «       }t        |«      xs |j                  «       }||k(  ry	 | j                  |«      }| j                  |«      }||k(  ryt        |«      t        |«      k7  ryt        d„ t        ||d¬«      D «       «      S # t        t        f$ r Y yw xY w)u‘  Check whether *detected* produces functionally identical text to *expected*.

    Returns ``True`` when:

    1. *detected* is not ``None`` and both encoding names normalize to the same
       codec, OR
    2. Decoding *data* with both encodings yields identical strings, OR
    3. Every differing character pair is functionally equivalent: same base
       letter after stripping combining marks, or an explicitly listed symbol
       equivalence (e.g. Â¤ â†” â‚¬).

    Returns ``False`` if *detected* is ``None``, either encoding is unknown,
    or either encoding cannot decode *data*.

    :param data: The raw byte data that was detected.
    :param expected: The expected encoding name, or ``None`` for binary files.
    :param detected: The detected encoding name, or ``None``.
    :returns: ``True`` if decoding with *detected* yields functionally identical
        text to decoding with *expected*.
    NFTc              3  ó:   K  — | ]  \  }}t        ||«      –— Œ y ­wr2   )rj   )r:   rh   ri   s      r5   r=   z*is_equivalent_detection.<locals>.<genexpr>4  s   è ø€ ÒX©4¨1¨aÔ   A×&ÑXùrN   )Ústrict)r   rR   ÚdecodeÚUnicodeDecodeErrorÚLookupErrorÚlenÚallÚzip)ÚdatarH   rI   rT   rU   Útext_expÚtext_dets          r5   Úis_equivalent_detectionrw     sÊ   € ð. ÐØ˜4ÐÐØÐØä˜xÓ(Ò<¨H¯N©NÓ,<€HÜ˜xÓ(Ò<¨H¯N©NÓ,<€Hà�8ÒØðØ—;‘;˜xÓ(ˆØ—;‘;˜xÓ(ˆð �8ÒØä
ˆ8ƒ}œ˜H›Ò%ØäÑX´3°xÀÐRVÔ3WÔXÓXÐXøô ¤Ð,ò Ùðús   Á"B) Â)B;Â:B;)r?   r#   r<   zCallable[[str], str]Úreturnr!   )rH   ÚstrrI   ry   rx   Úbool)rH   ú
str | NonerI   r{   rx   rz   )ra   ry   rx   ry   )rh   ry   ri   ry   rx   rz   )rt   ÚbytesrH   r{   rI   r{   rx   rz   )Ú__doc__Ú
__future__r   r]   Úcollections.abcr   Úchardet.registryr   r>   r"   Ú__annotations__r$   r0   rD   rE   rJ   rK   ÚitemsÚ_subsetÚ
_supersetsÚ_keyÚ_normedrG   rP   rV   rX   rc   rf   rj   rw   r3   r7   r5   ú<module>r‡      sI  ðòõ. #ã Ý $å ,ð+(Ø‰Y˜ Ð*Ó+ð+(à‰y˜,¨Ð0Ó1ð+(ð ‘9˜g˜YÓ'ð+(ð ‰i˜˜Ó$ð	+(ð
 
‰9�i�[Ó!ð+(ð ‰I�{ GÐ,Ó-ð+(ð ‘˜GÐ%5Ð6Ó7ð+(ð ‘iÐ!1Ð 2Ó3ð+(ð ‰i˜Ð(Ó)ð+(ð ‘I˜~Ð.Ó/ð+(ð ‰i˜˜	Ó"ð+(ð ‰Y˜�zÓ"ð+(ð. ‘9ÒRÓSð/+(ð0 ‘I˜~Ð/?Ð@ÓAð1+(ð2 ‘IÐ0Ð1Ó2ð3+(ð6 ‘)˜X˜JÓ'ð7+(ð8 ‘)˜X˜JÓ'ð9+(ñ: ˜X˜JÓ'Ù˜X˜JÓ'Ù˜X˜JÓ'Ù˜X˜JÓ'Ù˜X˜JÓ'Ù˜h˜ZÓ(ñ ˜ kÐ2Ó3Ù˜H˜:Ó&Ù˜H˜:Ó&Ù˜ kÐ2Ó3Ù˜H˜:Ó&Ù˜H˜:Ó&òU+(€	Ð$ó +ðh5Ð Ð1ó ð6Ð Ð2ó ñ& '2ð
Ø'ð
à#ð
ð ó
ñ .@Ð@UÓ-V€Ð*Ó Vó3ð* 46Ð Ð0Ó 5Ø$Ÿ?™?Ó,ò YÑ€GˆZÙ˜7Ó#Ò. w€DÙÑD¸ÔDÓD€GØ"7×";Ñ";¸DÁ)Ã+Ó"NÐQXÑ"XÐ˜$ÒðYñ 0BØÑ$Eô0Ð Ð,ó ó
 ó4#óLDñ 8AàØðó8Ð Ð4ó ó6ð .YØ
ð.YØ%ð.YØ1;ð.Yà	ô.Yr7   