§
    |Øj¯2  ã                  ó¸  — 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d]dA„Z ee¦  «        Zd5e
dB<   d^dG„Zi Zd5e
dH<   e	                     ¦   «         D ]K\  ZZ ee¦  «        peZ edI„ eD ¦   «         ¦  «        Ze                     e e¦   «         ¦  «        ez  ee<   ŒL eedJ„ ¬K¦  «        Zd5e
dL<   d_dN„Zd_dO„Zd`dQ„Z edRdSh¦  «        ZdTe
dU<   dadX„Zdbd[„Zdbd\„ZdS )caÙ  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    ú‡/Users/tedpeters/Documents/Projects/Claude Projects/Misc Tools/notename-sheets/.venv/lib/python3.11/site-packages/chardet/evaluation.pyú<lambda>r6   w   s   € °€ ó    ÚgroupsÚ	normalizeúCallable[[str], str]Úreturnc                ór   ‡— i }| D ]0}t          ˆfd„|D ¦   «         ¦  «        }|D ]}|| ‰|¦  «        <   ŒŒ1|S )zJBuild a lookup: key -> frozenset of all equivalent keys in the same group.c              3  ó.   •K  — | ]} ‰|¦  «        V — Œd S r2   r3   )Ú.0Únr9   s     €r5   ú	<genexpr>z%_build_group_index.<locals>.<genexpr>|   s+   øè è € Ð7Ð7¨A˜9˜9 Q™<œ<Ð7Ð7Ð7Ð7Ð7Ð7r7   )Ú	frozenset)r8   r9   ÚresultÚgroupÚnormedÚnames    `    r5   Ú_build_group_indexrF   u   si   ø€ ð
 )+€FØð -ð -ˆÝÐ7Ð7Ð7Ð7°Ð7Ñ7Ô7Ñ7Ô7ˆØð 	-ð 	-ˆDØ&,ˆF�9�9˜T‘?”?Ñ#Ð#ð	-à€Mr7   Ú_LANGUAGE_EQUIVÚexpectedÚstrÚdetectedÚboolc                óV   — | |k    rdS t                                | ¦  «        }|duo||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)rG   Úget)rH   rJ   rC   s      r5   Úis_language_equivalentrN   …   s<   € ð �8ÒÐØˆtÝ×Ò Ñ)Ô)€EØ˜ÐÐ2 ¨UÐ!2Ð2r7   Ú_NORMALIZED_SUPERSETSc              #  ó8   K  — | ]}t          |¦  «        p|V — Œd S r2   r   )r>   Úss     r5   r@   r@   �   s/   è è € ÐDÐD°A�¨Ñ*Ô*Ð/¨aÐDÐDÐDÐDÐDÐDr7   c                ó$   — t          | ¦  «        p| S r2   r   )r?   s    r5   r6   r6   ¢   s   € ­o¸aÑ.@Ô.@Ð.EÀA€ r7   )r9   Ú_NORMALIZED_BIDIRú
str | Nonec                ó®   — | €|du S |€dS t          | ¦  «        p|                      ¦   «         }t          |¦  «        p|                     ¦   «         }||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   rJ   Únorm_expÚnorm_dets       r5   Úis_exact_matchrZ   ¦   sc   € ð" ÐØ˜4ÐÐØÐØˆuÝ˜xÑ(Ô(Ð<¨H¯NªNÑ,<Ô,<€HÝ˜xÑ(Ô(Ð<¨H¯NªNÑ,<Ô,<€HØ�xÒÐr7   c                ó*  — | €|du S |€dS t          | |¦  «        rdS t          | ¦  «        p|                      ¦   «         }t          |¦  «        p|                     ¦   «         }|t          v r|t          |         v rdS |t          v o|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)rZ   r   rV   rS   rO   rW   s       r5   Ú
is_correctr\   À   s·   € ð ÐØ˜4ÐÐØÐØˆuõ �h Ñ)Ô)ð Øˆtå˜xÑ(Ô(Ð<¨H¯NªNÑ,<Ô,<€HÝ˜xÑ(Ô(Ð<¨H¯NªNÑ,<Ô,<€Hð Õ$Ð$Ð$¨Õ5FÀxÔ5PÐ)PÐ)PØˆtð 	Õ)Ð)ð 	8ØÕ-¨hÔ7Ð7ðr7   Útextc                ój   — t          j        d| ¦  «        }d                     d„ |D ¦   «         ¦  «        S )z4NFKD-normalize *text* and strip all combining marks.ÚNFKDÚ c              3  óB   K  — | ]}t          j        |¦  «        °|V — Œd S r2   )ÚunicodedataÚ	combining)r>   Úcs     r5   r@   z#_strip_combining.<locals>.<genexpr>é   s2   è è € ÐCÐC˜­+Ô*?ÀÑ*BÔ*BÐC�1ÐCÐCÐCÐCÐCÐCr7   )rb   r9   Újoin)r]   Únfkds     r5   Ú_strip_combiningrg   æ   s5   € åÔ  ¨Ñ.Ô.€DØ�7Š7ÐCÐC˜dÐCÑCÔCÑCÔCÐCr7   )õ   Â¤õ   â‚¬)ri   rh   zfrozenset[tuple[str, str]]Ú_EQUIVALENT_SYMBOL_PAIRSÚaÚbc                ól   — | |k    rdS | |ft           v rdS 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)rj   rg   )rk   rl   s     r5   Ú_chars_equivalentrn   ö   sC   € ð 	ˆA‚v€vØˆtØ	ˆ1€vÕ)Ð)Ð)Øˆtå˜AÑÔÕ"2°1Ñ"5Ô"5Ò5Ð5r7   ÚdataÚbytesc                óà  — |€|du S |€dS t          |¦  «        p|                     ¦   «         }t          |¦  «        p|                     ¦   «         }||k    rdS 	 |                      |¦  «        }|                      |¦  «        }n# t          t          f$ r Y dS w xY w||k    rdS t          |¦  «        t          |¦  «        k    rdS t          d„ t          ||d¬¦  «        D ¦   «         ¦  «        S )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          ||¦  «        V — Œd S r2   )rn   )r>   rk   rl   s      r5   r@   z*is_equivalent_detection.<locals>.<genexpr>4  s1   è è € ÐXÐX©4¨1¨aÕ   AÑ&Ô&ÐXÐXÐXÐXÐXÐXr7   )Ústrict)r   rV   ÚdecodeÚUnicodeDecodeErrorÚLookupErrorÚlenÚallÚzip)ro   rH   rJ   rX   rY   Útext_expÚtext_dets          r5   Úis_equivalent_detectionr|     s  € ð. ÐØ˜4ÐÐØÐØˆuå˜xÑ(Ô(Ð<¨H¯NªNÑ,<Ô,<€HÝ˜xÑ(Ô(Ð<¨H¯NªNÑ,<Ô,<€Hà�8ÒÐØˆtðØ—;’;˜xÑ(Ô(ˆØ—;’;˜xÑ(Ô(ˆˆøÝ¥Ð,ð ð ð Øˆuˆuðøøøð �8ÒÐØˆtå
ˆ8�}„}�˜H™œÒ%Ð%ØˆuåÐXÐXµ3°xÀÐRVÐ3WÑ3WÔ3WÐXÑXÔXÑXÔXÐXs   Á*B ÂBÂBc                óD   — t          ||¦  «        pt          | ||¦  «        S )uÄ  Check whether *detected* is an acceptable detection of *data* as *expected*.

    The composed predicate every accuracy consumer wants: name-level
    acceptance (:func:`is_correct` â€” exact match, byte-order group, or known
    superset) or byte-level equivalence on this particular input
    (:func:`is_equivalent_detection`).  Callers needing only one half, or
    the stricter :func:`is_exact_match`, should use the primitives directly.

    :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 the detection is acceptable for *data*.
    )r\   r|   )ro   rH   rJ   s      r5   Úis_acceptabler~   7  s/   € õ �h Ñ)Ô)ð Õ-DØˆh˜ñ.ô .ð r7   )r8   r#   r9   r:   r;   r!   )rH   rI   rJ   rI   r;   rK   )rH   rT   rJ   rT   r;   rK   )r]   rI   r;   rI   )rk   rI   rl   rI   r;   rK   )ro   rp   rH   rT   rJ   rT   r;   rK   )Ú__doc__Ú
__future__r   rb   Úcollections.abcr   Úchardet.registryr   rA   r"   Ú__annotations__r$   r0   rF   rG   rN   rO   ÚitemsÚ_subsetÚ
_supersetsÚ_keyÚ_normedrM   rS   rZ   r\   rg   rj   rn   r|   r~   r3   r7   r5   ú<module>r‰      s  ððð ð ð. #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $à ,Ð ,Ð ,Ð ,Ð ,Ð ,ð+(ØˆYˆY˜ Ð*Ñ+Ô+ð+(àˆyˆy˜,¨Ð0Ñ1Ô1ð+(ð �9�9˜g˜YÑ'Ô'ð+(ð ˆiˆi˜˜Ñ$Ô$ð	+(ð
 
ˆ9ˆ9�i�[Ñ!Ô!ð+(ð ˆIˆI�{ GÐ,Ñ-Ô-ð+(ð ��˜GÐ%5Ð6Ñ7Ô7ð+(ð �i�iÐ!1Ð 2Ñ3Ô3ð+(ð ˆiˆi˜Ð(Ñ)Ô)ð+(ð �I�I˜~Ð.Ñ/Ô/ð+(ð ˆiˆi˜˜	Ñ"Ô"ð+(ð ˆYˆY˜�zÑ"Ô"ð+(ð. �9�9ÐRÐRÐRÑSÔSð/+(ð0 �I�I˜~Ð/?Ð@ÑAÔAð1+(ð2 �I�IÐ0Ð1Ñ2Ô2ð3+(ð6 �)�)˜X˜JÑ'Ô'ð7+(ð8 �)�)˜X˜JÑ'Ô'ð9+(ð: �)˜X˜JÑ'Ô'Ø�)˜X˜JÑ'Ô'Ø�)˜X˜JÑ'Ô'Ø�)˜X˜JÑ'Ô'Ø�)˜X˜JÑ'Ô'Ø�9˜h˜ZÑ(Ô(ð ˆi˜ kÐ2Ñ3Ô3Ø�˜H˜:Ñ&Ô&Ø�˜H˜:Ñ&Ô&Øˆi˜ kÐ2Ñ3Ô3Ø�˜H˜:Ñ&Ô&Ø�˜H˜:Ñ&Ô&ðU+(ð +(ð +(€	ð +ð +ð +ñ +ðh5Ð ð ð ð ñ ð6Ð ð ð ð ñ ð& '2 kð
ð 
ð 
ð 
ð 
ð .@Ð-?Ð@UÑ-VÔ-V€Ð VÐ VÐ VÑ Vð3ð 3ð 3ð 3ð* 46Ð Ð 5Ð 5Ð 5Ñ 5Ø$Ÿ?š?Ñ,Ô,ð Yð YÑ€GˆZØˆ?˜7Ñ#Ô#Ð. w€DØˆiÐDÐD¸ÐDÑDÔDÑDÔD€GØ"7×";Ò";¸DÀ)À)Á+Ä+Ñ"NÔ"NÐQXÑ"XÐ˜$ÑÐð 0BÐ/AØÐ$EÐ$Eð0ñ 0ô 0Ð ð ð ð ñ ð
 ð  ð  ð  ð4#ð #ð #ð #ðLDð Dð Dð Dð 8A°yàØðñ8ô 8Ð ð ð ð ñ ð6ð 6ð 6ð 6ð .Yð .Yð .Yð .Yðbð ð ð ð ð r7   