HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/charset_normalizer/__pycache__/cd.cpython-310.pyc
o

;��g�0�@s.ddlmZddlZddlmZddlmZddlmZddl	mZ
ddlmZm
Z
mZmZmZddlmZdd	lmZdd
lmZmZmZmZmZd8dd�Zd9dd�Ze�d8dd��Ze�d8dd��Zeed�d:dd��Z	d;d<d!d"�Z d=d%d&�Z!d>d(d)�Z"d?d-d.�Z#d@d/d0�Z$ed1d�	dAdBd6d7��Z%dS)C�)�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�	iana_name�str�return�	list[str]cs�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�@�NFrcs g|]}�|�dkr|�qS)g333333�?�)�.0�character_range��character_count�seen_rangesr�@/usr/local/lib/python3.10/dist-packages/charset_normalizer/cd.py�
<listcomp>8s
�z*encoding_unicode_range.<locals>.<listcomp>)r�OSError�	importlib�
import_moduler�range�decode�bytesrr�sorted)r�decoder�p�i�chunkrrrr!�encoding_unicode_ranges.
���r.�
primary_rangecCs>g}t��D]\}}|D]}t|�|kr|�|�nqq|S)z>
    Return inferred languages used with a unicode range.
    )r�itemsr�append)r/�	languages�language�
characters�	characterrrr!�unicode_range_languages@s
��r6cCs<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.
    N�Latin�Latin Based)r.r6)r�unicode_rangesr/�specified_rangerrr!�encoding_languagesOs�r;cCs`|�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.
    �shift_�
iso2022_jp�euc_j�cp932�Japanese�gb�Chinese�
iso2022_kr�Korean)�
startswithrr)rrrr!�mb_encoding_languagescs���rF)�maxsizer3�tuple[bool, bool]cCsBd}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)rrr)r3�target_have_accents�target_pure_latinr5rrr!�get_target_featuresxs�rKFr4�ignore_non_latin�boolcs�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)rr5rrr!�	<genexpr>���z%alphabet_languages.<locals>.<genexpr>Fcsg|]}|�vr|�qSrr)r�c�r4rr!r"�sz&alphabet_languages.<locals>.<listcomp>g�������?cS�|dS�Nrr��xrrr!�<lambda>��z$alphabet_languages.<locals>.<lambda>T��key�reversecSsg|]}|d�qS)rr)r�compatible_languagerrr!r"��)�anyrr0rK�lenr1r))r4rLr2�source_have_accentsr3�language_charactersrIrJr�character_match_count�ratiorrRr!�alphabet_languages�s$��rd�ordered_characters�floatcCs�|tvrt|�d���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�rNg�������?)	r�
ValueError�setr_�zipr&�index�int�abs)r3re�character_approved_count�FREQUENCIES_language_set�ordered_characters_count� target_language_characters_count�large_alphabetr5�character_rank�character_rank_in_language�expected_projection_ratio�character_rank_projection�characters_before_source�characters_after_source�characters_before�characters_after�before_match_count�after_match_countrrr!�characters_popularity_compare�sf
��
������r�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)r��layersr5r�layer_target_range�discovered_rangerrr!�alpha_unicode_split�s,��r��results�list[CoherenceMatches]r
csfi�|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)rh)�round�sumr_)rr3��per_language_ratiosrr!r"1s����z*merge_coherence_ratios.<locals>.<listcomp>cSrSrTrrUrrr!rW<rXz(merge_coherence_ratios.<locals>.<lambda>TrY)r1r))r��result�
sub_resultr3rc�mergerr�r!�merge_coherence_ratios#s
�
�r�cs�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)rN)r_)r�e��
index_resultsrr!rOOs�z/filter_alt_coherence_matches.<locals>.<genexpr>)�dict�replacer1r^�max)r�r�r3rc�
no_em_name�filtered_resultsrr�r!�filter_alt_coherence_matches?sr�i皙�����?�	threshold�lg_inclusion�
str | NonecCs�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�|]\}}|VqdSrNr�rrQ�orrr!rOqrPz"coherence_ratio.<locals>.<genexpr>cSsg|]\}}|�qSrrr�rrr!r"vr]z#coherence_ratio.<locals>.<listcomp>g�������?rrhricSrSrTrrUrrr!rW�rXz!coherence_ratio.<locals>.<lambda>rY)
�split�remover�r�most_commonr�r
rdrr1r�r)r�)r�r�r�r�rL�sufficient_match_count�lg_inclusion_list�layer�sequence_frequenciesr�r�popular_character_orderedr3rcrrr!�coherence_ratioZs@	
�����r�)rrrr)r/rrr)r3rrrH)F)r4rrLrMrr)r3rrerrrf)r�rrr)r�r�rr
)r�r
rr
)r�N)r�rr�rfr�r�rr
)&�
__future__rr$�codecsr�collectionsr�	functoolsr�typing�TypeCounter�constantrrr	r
r�mdr�modelsr
�utilsrrrrrr.r6r;rFrKrdrr�r�r�r�rrrr!�<module>s6
	
%�
#
P
'
�