HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/site-packages/charset_normalizer/__pycache__/cd.cpython-37.pyc
B

���g�0�@stddlmZddlZddlmZddlmZddlmZddl	mZ
ddlmZm
Z
mZmZmZddlmZdd	lmZdd
lmZmZmZmZmZddd
�dd�Zddd�dd�Ze�ddd
�dd��Ze�ddd
�dd��Zeed�ddd�dd��Zd5dddd�dd �Z ddd!d"�d#d$�Z!ddd%�d&d'�Z"d(d)d*�d+d,�Z#d)d)d*�d-d.�Z$ed/d�d6dd!d1d)d2�d3d4��Z%dS)7�)�annotationsN)�IncrementalDecoder)�Counter)�	lru_cache�)�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�strz	list[str])�	iana_name�returncs�t|�rtd��t�d|���j}|dd�}i�d�xltdd�D]^}|�t|g��}|r@t|�}|dkrjq@t	|�d	kr@|�kr�d�|<�|d
7<�d
7�q@Wt
��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�@�NFrcs g|]}�|�dkr|�qS)g333333�?�)�.0�character_range)�character_count�seen_rangesr�?/usr/local/lib/python3.7/site-packages/charset_normalizer/cd.py�
<listcomp>9sz*encoding_unicode_range.<locals>.<listcomp>)r�OSError�	importlib�
import_moduler�range�decode�bytesrr�sorted)r�decoder�p�i�chunkrr)rrr�encoding_unicode_ranges(
r,)�
primary_rangercCsDg}x:t��D].\}}x$|D]}t|�|kr|�|�PqWqW|S)z>
    Return inferred languages used with a unicode range.
    )r�itemsr�append)r-�	languages�language�
characters�	characterrrr�unicode_range_languages@s


r4cCs>t|�}d}x|D]}d|kr|}PqW|dkr6dgSt|�S)z�
    Single-byte encoding language association. Some code page are heavily linked to particular language(s).
    This function does the correspondence.
    NZLatinzLatin Based)r,r4)rZunicode_rangesr-Zspecified_rangerrr�encoding_languagesOs
r5cCs`|�d�s&|�d�s&|�d�s&|dkr,dgS|�d�s>|tkrDdgS|�d�sV|tkr\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�cp932�Japanese�gb�Chinese�
iso2022_kr�Korean)�
startswithrr)rrrr�mb_encoding_languagescs


r>)�maxsizeztuple[bool, bool])r1rcCsFd}d}x4t|D](}|s&t|�r&d}|rt|�dkrd}qW||fS)zg
    Determine main aspects from a supported language if it contains accents and if is pure Latin.
    FT)rrr)r1�target_have_accents�target_pure_latinr3rrr�get_target_featuresxsrBF�bool)r2�ignore_non_latinrcs�g}tdd��D��}xxt��D]l\}}t|�\}}|rB|dkrBq |dkrP|rPq t|�}t�fdd�|D��}	|	|}
|
dkr |�||
f�q Wt|dd�d	d
�}dd�|D�S)zE
    Return associated languages associated to given characters.
    css|]}t|�VqdS)N)r)rr3rrr�	<genexpr>�sz%alphabet_languages.<locals>.<genexpr>Fcsg|]}|�kr|�qSrr)r�c)r2rrr �sz&alphabet_languages.<locals>.<listcomp>g�������?cSs|dS)Nrr)�xrrr�<lambda>��z$alphabet_languages.<locals>.<lambda>T)�key�reversecSsg|]}|d�qS)rr)rZcompatible_languagerrrr �s)�anyrr.rB�lenr/r')r2rDr0Zsource_have_accentsr1Zlanguage_charactersr@rArZcharacter_match_count�ratior)r2r�alphabet_languages�s rO�float)r1�ordered_charactersrcCs�|tkrt|�d���d}tt|�}t|�}tt|�}|dk}�xZt|td|��D�]D\}}||krjqVt|�|�}	||}
t||
�}|dkr�t||	�dkr�qV|dkr�t||	�|dkr�|d7}qVt|d|	�}t||	d	�}
|d|�}||d	�}tt|�t|�@�}tt|�t|
�@�}t|�dk�rN|dk�rN|d7}qVt|
�dk�rp|dk�rp|d7}qV|t|�d
k�s�|t|
�d
krV|d7}qVqVW|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�rNg�������?)	r�
ValueError�setrM�zipr$�index�int�abs)r1rQZcharacter_approved_countZFREQUENCIES_language_setZordered_characters_countZ target_language_characters_countZlarge_alphabetr3Zcharacter_rankZcharacter_rank_in_languageZexpected_projection_ratioZcharacter_rank_projectionZcharacters_before_sourceZcharacters_after_sourceZcharacters_beforeZcharacters_afterZbefore_match_countZafter_match_countrrr�characters_popularity_compare�sV



r[)�decoded_sequencercCs�i}x�|D]�}|��dkrq
t|�}|dkr.q
d}x |D]}t||�dkr8|}Pq8W|dkr`|}||krv|��||<q
|||��7<q
Wt|���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)r\Zlayersr3rZlayer_target_rangeZdiscovered_rangerrr�alpha_unicode_split�s(

razlist[CoherenceMatches]r
)�resultsrcsni�xD|D]<}x6|D].}|\}}|�kr4|g�|<q�|�|�qWq
W�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)rS)�round�sumrM)rr1)�per_language_ratiosrrr 2sz*merge_coherence_ratios.<locals>.<listcomp>cSs|dS)Nrr)rGrrrrH<rIz(merge_coherence_ratios.<locals>.<lambda>T)rJrK)r/r')rb�resultZ
sub_resultr1rN�merger)rer�merge_coherence_ratios#s



rhcs�t��x>|D]6}|\}}|�dd�}|�kr4g�|<�|�|�qWt�fdd��D��r�g}x"�D]}|�|t�|�f�qfW|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)rN)rM)r�e)�
index_resultsrrrEOsz/filter_alt_coherence_matches.<locals>.<genexpr>)�dict�replacer/rL�max)rbrfr1rNZ
no_em_nameZfiltered_resultsr)rkr�filter_alt_coherence_matches?s

roi皙�����?z
str | None)r\�	threshold�lg_inclusionrcCs�g}d}d}|dk	r|�d�ng}d|kr8d}|�d�x�t|�D]�}t|�}|��}	tdd�|	D��}
|
tkrrqBd	d
�|	D�}xZ|p�t||�D]H}t||�}
|
|kr�q�n|
dkr�|d7}|�	|t
|
d
�f�|dkr�Pq�WqBWtt|�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�,zLatin BasedTcss|]\}}|VqdS)Nr)rrF�orrrrEqsz"coherence_ratio.<locals>.<genexpr>cSsg|]\}}|�qSrr)rrFrtrrrr vsz#coherence_ratio.<locals>.<listcomp>g�������?rrSrTcSs|dS)Nrr)rGrrrrH�rIz!coherence_ratio.<locals>.<lambda>)rJrK)
�split�removerar�most_commonrdr
rOr[r/rcr'ro)r\rqrrrbrDZsufficient_match_countZlg_inclusion_list�layerZsequence_frequenciesrwrZpopular_character_orderedr1rNrrr�coherence_ratioZs6	

ry)F)rpN)&�
__future__rr"�codecsr�collectionsr�	functoolsr�typingZTypeCounterZconstantrrr	r
r�mdr�modelsr
�utilsrrrrrr,r4r5r>rBrOr[rarhroryrrrr�<module>s*	%"P'