HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/charset_normalizer/__pycache__/cd.cpython-310.pyc
o

�N�g
1�
@s�ddlZddlmZddlmZddlmZddlmZm	Z	m
Z
mZmZddl
mZddlmZmZmZmZdd	lmZdd
lmZddlmZmZmZmZmZded
e
efdd�Zded
e
efdd�Z e�ded
e
efdd��Z!e�ded
e
efdd��Z"eed�ded
ee#e#ffdd��Z$	d1de
ede#d
e
efdd�Z%ded e
ed
e&fd!d"�Z'd#ed
e
efd$d%�Z(d&e
ed
efd'd(�Z)d&ed
efd)d*�Z*ed+d�	d2d#ed-e&d.eed
efd/d0��Z+dS)3�N)�IncrementalDecoder)�Counter)�	lru_cache)r�Dict�List�Optional�Tuple�)�FREQUENCIES)�KO_NAMES�LANGUAGE_SUPPORTED_COUNT�TOO_SMALL_SEQUENCE�ZH_NAMES)� is_suspiciously_successive_range)�CoherenceMatches)�is_accentuated�is_latin�is_multi_byte_encoding�is_unicode_range_secondary�
unicode_range�	iana_name�returncs�t|�rtd��t�d�|��j}|dd�}i�d�tdd�D]/}|�t|g��}|rNt	|�}|dur4qt
|�d	urN|�vrBd�|<�|d
7<�d
7�qt��fdd��D��S)
zF
    Return associated unicode ranges in a single byte code page.
    z.Function not supported on multi-byte code pagezencodings.{}�ignore)�errorsr�@�NFr	cs g|]}�|�dkr|�qS)g333333�?�)�.0�character_range��character_countZseen_rangesr�I/opt/saltstack/salt/lib/python3.10/site-packages/charset_normalizer/cd.py�
<listcomp>3s
�z*encoding_unicode_range.<locals>.<listcomp>)r�IOError�	importlib�
import_module�formatr�range�decode�bytesrr�sorted)r�decoder�p�i�chunkrrrr!�encoding_unicode_ranges6��
���r/�
primary_rangecCs>g}t��D]\}}|D]}t|�|kr|�|�nqq|S)z>
    Return inferred languages used with a unicode range.
    )r
�itemsr�append)r0�	languages�language�
characters�	characterrrr!�unicode_range_languages;s
��r7cCs<t|�}d}|D]
}d|vr|}nq|durdgSt|�S)z�
    Single-byte encoding language association. Some code page are heavily linked to particular language(s).
    This function does the correspondence.
    NZLatin�Latin Based)r/r7)rZunicode_rangesr0Zspecified_rangerrr!�encoding_languagesJs�r9cCs`|�d�s|�d�s|�d�s|dkrdgS|�d�s|tvr"dgS|�d�s+|tvr.d	gSgS)
z�
    Multi-byte encoding language association. Some code page are heavily linked to particular language(s).
    This function does the correspondence.
    Zshift_�
iso2022_jpZeuc_j�cp932ZJapaneseZgbZChinese�
iso2022_krZKorean)�
startswithrr)rrrr!�mb_encoding_languages^s���r>)�maxsizer4cCsBd}d}t|D]}|st|�rd}|rt|�durd}q||fS)zg
    Determine main aspects from a supported language if it contains accents and if is pure Latin.
    FT)r
rr)r4�target_have_accents�target_pure_latinr6rrr!�get_target_featuresss�rBFr5�ignore_non_latincs�g}tdd��D��}t��D]6\}}t|�\}}|r |dur q|dur'|r'qt|�}t�fdd�|D��}	|	|}
|
dkrE|�||
f�qt|dd�d	d
�}dd�|D�S)zE
    Return associated languages associated to given characters.
    css�|]}t|�VqdS�N)r)rr6rrr!�	<genexpr>���z%alphabet_languages.<locals>.<genexpr>Fcsg|]}|�vr|�qSrr)r�c�r5rr!r"�sz&alphabet_languages.<locals>.<listcomp>g�������?cS�|dS�Nr	r��xrrr!�<lambda>��z$alphabet_languages.<locals>.<lambda>T��key�reversecSsg|]}|d�qS)rr)rZcompatible_languagerrr!r"��)�anyr
r1rB�lenr2r*)r5rCr3Zsource_have_accentsr4Zlanguage_charactersr@rAr Zcharacter_match_count�ratiorrHr!�alphabet_languages�s$��rV�ordered_characterscCs�|tvrtd�|���d}tt|�}t|�}tt|�}|dk}t|td|��D]�\}}||vr2q)t|�|�}	||}
t||
�}|durPt	||	�dkrPq)|durct	||	�|dkrc|d7}q)t|d|	�}t||	d	�}
|d|�}||d	�}tt|�t|�@�}tt|�t|
�@�}t|�dkr�|dkr�|d7}q)t|
�dkr�|dkr�|d7}q)|t|�d
ks�|t|
�d
kr�|d7}q)q)|t|�S)aN
    Determine if a ordered characters list (by occurrence from most appearance to rarest) match a particular language.
    The result is a ratio between 0. (absolutely no correspondence) and 1. (near perfect fit).
    Beware that is function is not strict on the match in order to ease the detection. (Meaning close match is 1.)
    z{} not availabler�F�T�r	Ng�������?)
r
�
ValueErrorr&�setrT�zipr'�index�int�abs)r4rWZcharacter_approved_countZFREQUENCIES_language_setZordered_characters_countZ target_language_characters_countZlarge_alphabetr6Zcharacter_rankZcharacter_rank_in_languageZexpected_projection_ratioZcharacter_rank_projectionZcharacters_before_sourceZcharacters_after_sourceZcharacters_beforeZcharacters_afterZbefore_match_countZafter_match_countrrr!�characters_popularity_compare�sf
��
������ra�decoded_sequencecCs�i}|D]?}|��dur
qt|�}|durqd}|D]
}t||�dur'|}nq|dur.|}||vr9|��||<q|||��7<qt|���S)a
    Given a decoded text sequence, return a list of str. Unicode range / alphabet separation.
    Ex. a text containing English/Latin with a bit a Hebrew will return two items in the resulting list;
    One containing the latin letters and the other hebrew.
    FN)�isalpharr�lower�list�values)rbZlayersr6rZlayer_target_rangeZdiscovered_rangerrr!�alpha_unicode_split�s,��rg�resultscsfi�|D]}|D]}|\}}|�vr|g�|<q�|�|�qq�fdd��D�}t|dd�dd�S)z�
    This function merge results previously given by the function coherence_ratio.
    The return type is the same as coherence_ratio.
    cs.g|]}|tt�|�t�|�d�f�qS)rY)�round�sumrT)rr4�Zper_language_ratiosrr!r",s����z*merge_coherence_ratios.<locals>.<listcomp>cSrIrJrrKrrr!rM7rNz(merge_coherence_ratios.<locals>.<lambda>TrO)r2r*)rh�resultZ
sub_resultr4rU�mergerrkr!�merge_coherence_ratioss
�
�rncs�t��|D]}|\}}|�dd�}|�vrg�|<�|�|�qt�fdd��D��r@g}�D]
}|�|t�|�f�q0|S|S)u�
    We shall NOT return "English—" in CoherenceMatches because it is an alternative
    of "English". This function only keeps the best match and remove the em-dash in it.
    u—�c3s �|]}t�|�dkVqdS)r	N)rT)r�e�Z
index_resultsrr!rEJs�z/filter_alt_coherence_matches.<locals>.<genexpr>)�dict�replacer2rS�max)rhrlr4rUZ
no_em_nameZfiltered_resultsrrqr!�filter_alt_coherence_matches:srui皙�����?�	threshold�lg_inclusioncCs�g}d}d}|dur|�d�ng}d|vrd}|�d�t|�D]K}t|�}|��}	tdd�|	D��}
|
tkr8q d	d
�|	D�}|pEt||�D]$}t||�}
|
|krRqF|
dkrZ|d7}|�	|t
|
d
�f�|dkrjnqFq tt|�dd�dd�S)z�
    Detect ANY language that can be identified in given sequence. The sequence will be analysed by layers.
    A layer = Character extraction by alphabets/ranges.
    FrN�,r8Tcss�|]\}}|VqdSrDr�rrG�orrr!rElrFz"coherence_ratio.<locals>.<genexpr>cSsg|]\}}|�qSrrrzrrr!r"qrRz#coherence_ratio.<locals>.<listcomp>g�������?r	rYrZcSrIrJrrKrrr!rM�rNz!coherence_ratio.<locals>.<lambda>rO)
�split�removergr�most_commonrjr
rVrar2rir*ru)rbrwrxrhrCZsufficient_match_countZlg_inclusion_listZlayerZsequence_frequenciesr~r Zpopular_character_orderedr4rUrrr!�coherence_ratioUs@	
�����r)F)rvN),r$�codecsr�collectionsr�	functoolsr�typingZTypeCounterrrrrZassetsr
Zconstantrrr
rZmdrZmodelsr�utilsrrrrr�strr/r7r9r>�boolrBrV�floatrargrnrurrrrr!�<module>s^	'���
�#��
�P'�����