CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
models.cpython-310.pyc103 linesDownload Raw Back to __pycache__
1o

2��Yi�1�@s�ddlmZddlmZddlmZddlmZddlm	Z	ddl3mZmZm
Z
mZddlmZmZdd	lmZmZmZGd4d�d�ZGdd
�d
�ZeeefZe
eZGdd�d�ZdS)�)�annotations)�aliases)�sha256)�dumps)�sub)�Any�Iterator�List�Tuple�)�RE_POSSIBLE_ENCODING_INDICATION�TOO_BIG_SEQUENCE)�	iana_name�is_multi_byte_encoding�
unicode_rangec@sHeZdZ		dGdHdd�ZdIdd�ZdIdd�ZedJdd��ZdKdd�ZdKdd�Z	dLdd �Z5edKd!d"��ZedMd$d%��ZedNd&d'��Z
edNd(d)��ZedMd*d+��ZedKd,d-��ZedJd.d/��ZedJd0d1��ZedJd2d3��ZedJd4d5��ZedOd6d7��ZedPd9d:��ZedNd;d<��ZedMd=d>��ZedMd?d@��ZdQdRdCdD�ZedKdEdF��ZdS)S�CharsetMatchN�payload�bytes�guessed_encoding�str�mean_mess_ratio�float�has_sig_or_bom�bool�	languages�CoherenceMatches�decoded_payload�6str | None�preemptive_declarationcCsL||_||_||_||_||_d|_g|_d|_d|_d|_	||_7||_dS)N�)�_payload�	_encoding�_mean_mess_ratio�8_languages�_has_sig_or_bom�_unicode_ranges�_leavesZ_mean_coherence_ratio�_output_payload�_output_encoding�_string�_preemptive_declaration)�selfrrrrrrr�r,��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\charset_normalizer/models.py�__init__s910zCharsetMatch.__init__�other�object�returncCs>t|t�st|t�rt|�|jkSdS|j|jko|j|jkS)NF)�11isinstancerrr�encoding�fingerprint�r+r/r,r,r-�__eq__*s121314zCharsetMatch.__eq__cCs�t|t�st�t|j|j�}t|j|j�}|dkr%|dkr%|j|jkS|dkr@|dkr@t|j�tkr:|j|jkS|j	|j	kS|j|jkS)zQ15        Implemented to make sorted available upon CharsetMatches items.16        g{�G�z�?g{�G�z�?)17r2r�18ValueError�abs�chaos�	coherence�lenr r
�multi_byte_usage)r+r/Zchaos_differenceZcoherence_differencer,r,r-�__lt__1s19zCharsetMatch.__lt__cCsdtt|��t|j�S)Ng�?)r;r�raw�r+r,r,r-r<GszCharsetMatch.multi_byte_usagecCs"|jdurt|j|jd�|_|jS)N�strict)r)rr r!r?r,r,r-�__str__Ks20zCharsetMatch.__str__cCsd|j�d|j�d�S)Nz<CharsetMatch 'z' bytes(z)>)r3r4r?r,r,r-�__repr__QszCharsetMatch.__repr__�NonecCs8t|t�r	||krtd�|j���d|_|j�|�dS)Nz;Unable to add instance <{}> as a submatch of a CharsetMatch)r2rr7�format�	__class__r)r&�appendr5r,r,r-�add_submatchTs��zCharsetMatch.add_submatchcC�|jS�N)r!r?r,r,r-r3_�zCharsetMatch.encoding�	list[str]cCsDg}t��D]\}}|j|kr|�|�q|j|kr|�|�q|S)z�21        Encoding name are known by many name, using this could help when searching for IBM855 when it's listed as CP855.22        )r�itemsr3rF)r+Z
also_known_as�u�pr,r,r-�encoding_aliasescs232425�zCharsetMatch.encoding_aliasescCrHrI�r$r?r,r,r-�bomprJzCharsetMatch.bomcCrHrIrPr?r,r,r-�byte_order_marktrJzCharsetMatch.byte_order_markcCsdd�|jD�S)z�26        Return the complete list of possible languages found in decoded sequence.27        Usually not really useful. Returned list may be empty even if 'language' property return something != 'Unknown'.28        cSsg|]}|d�qS)rr,)�.0�er,r,r-�29<listcomp>~�z*CharsetMatch.languages.<locals>.<listcomp>�r#r?r,r,r-rxszCharsetMatch.languagescCsp|js1d|jvr30dSddlm}m}t|j�r||j�n||j�}t|�dks+d|vr-dS|dS|jddS)z�31        Most probable language found in decoded sequence. If none were detected or inferred, the property will return32        "Unknown".33        �asciiZEnglishr)�encoding_languages�mb_encoding_languageszLatin Based�Unknown)r#�could_be_from_charsetZcharset_normalizer.cdrYrZrr3r;)r+rYrZrr,r,r-�language�s34��zCharsetMatch.languagecCrHrI)r"r?r,r,r-r9�rJzCharsetMatch.chaoscCs|jsdS|jddS)NrrrrWr?r,r,r-r:�szCharsetMatch.coherencecC�t|jddd�S�N�d�)�ndigits)�roundr9r?r,r,r-�
percent_chaos��zCharsetMatch.percent_chaoscCr^r_)rcr:r?r,r,r-�percent_coherence�rezCharsetMatch.percent_coherencecCrH)z+35        Original untouched bytes.36        )r r?r,r,r-r>�szCharsetMatch.raw�list[CharsetMatch]cCrHrI)r&r?r,r,r-�submatch�rJzCharsetMatch.submatchcC�t|j�dkS�Nr)r;r&r?r,r,r-�has_submatch�szCharsetMatch.has_submatchcCs@|jdur|jSdd�t|�D�}ttdd�|D���|_|jS)NcSsg|]}t|��qSr,)r)rS�charr,r,r-rU�rVz*CharsetMatch.alphabets.<locals>.<listcomp>cSsh|]}|r|�qSr,r,)rS�rr,r,r-�	<setcomp>�rVz)CharsetMatch.alphabets.<locals>.<setcomp>)r%r�sorted�list)r+Zdetected_rangesr,r,r-�	alphabets�s3738zCharsetMatch.alphabetscCs|jgdd�|jD�S)z�39        The complete list of encoding that output the exact SAME str result and therefore could be the originating40        encoding.41        This list does include the encoding available in property 'encoding'.42        cSsg|]}|j�qSr,)r3)rS�mr,r,r-rU�sz6CharsetMatch.could_be_from_charset.<locals>.<listcomp>)r!r&r?r,r,r-r\�sz"CharsetMatch.could_be_from_charset�utf_8r3cs~�jdus43�j|kr<|�_t��}�jdur5�j��dvr5tt�fdd�|dd�dd�}||dd�}|�|d��_�jS)	z�44        Method to get re-encoded bytes payload using given target encoding. Default to UTF-8.45        Any errors will be simply ignored by the encoder NOT replaced.46        N)zutf-8�utf8rscs<|j|��d|��d��|��dt�j��dd��S)Nrr�_�-)�string�span�replace�groupsrr()rrr?r,r-�<lambda>�s47�z%CharsetMatch.output.<locals>.<lambda>i r)�country)r(rr*�lowerrr�encoder')r+r3�decoded_stringZpatched_headerr,r?r-�output�s 48�4950�51zCharsetMatch.outputcCst|�����S)zw52        Retrieve the unique SHA256 computed using the transformed (re-encoded) payload. Not the original one.53        )rr��	hexdigestr?r,r,r-r4�szCharsetMatch.fingerprint)NN)rrrrrrrrrrrrrr)r/r0r1r)r1r�r1r)r/rr1rC)r1rK�r1r)r1r)r1rg)rs)r3rr1r)�__name__�54__module__�__qualname__r.r6r=�propertyr<rArBrGr3rOrQrRrr]r9r:rdrfr>rhrkrqr\r�r4r,r,r,r-r
sX�5556575859	rc@sbeZdZdZdddd�Zd d	d60�Zd!dd�Zd"dd�Zd#dd�Zd$dd�Z	d%dd�Z61d%dd�ZdS)&�CharsetMatchesz�62    Container with every CharsetMatch items ordered by default from most probable to the less one.63    Act like a list(iterable) but does not implements all related methods.64    N�results�list[CharsetMatch] | NonecCs|r	t|�|_dSg|_dSrI)ro�_results)r+r�r,r,r-r.�szCharsetMatches.__init__r1�Iterator[CharsetMatch]ccs�|jEdHdSrI�r�r?r,r,r-�__iter__�s�zCharsetMatches.__iter__�item�	int | strrcCsJt|t�r65|j|St|t�r#t|d�}|jD]}||jvr"|Sqt�)z�66        Retrieve a single item either by its position or encoding name (alias may be used here).67        Raise KeyError upon invalid index or encoding not present in results.68        F)r2�intr�rrr\�KeyError)r+r��resultr,r,r-�__getitem__s697071727374�zCharsetMatches.__getitem__r�cCs75t|j�SrI�r;r�r?r,r,r-�__len__s76zCharsetMatches.__len__rcCrirjr�r?r,r,r-�__bool__szCharsetMatches.__bool__rCcCs|t|t�std�t|j����t|j�tkr0|j	D]}|j77|j78kr/|j|jkr/|�|�dSq|j	�
|�t|j	�|_	dS)z~79        Insert a single match. Will be inserted accordingly to preserve sort.80        Can be inserted as a submatch.81        z-Cannot append instance '{}' to CharsetMatchesN)r2rr7rDrrEr;r>r
r�r4r9rGrFro)r+r��matchr,r,r-rFs82��8384�zCharsetMatches.append�CharsetMatch | NonecCs|jsdS|jdS)zQ85        Simply return the first match. Strict equivalent to matches[0].86        Nrr�r?r,r,r-�best)s87zCharsetMatches.bestcCs|��S)zP88        Redundant method, call the method best(). Kept for BC reasons.89        )r�r?r,r,r-�first1szCharsetMatches.firstrI)r�r�)r1r�)r�r�r1r)r1r�r�)r�rr1rC)r1r�)r�r�r��__doc__r.r�r�r�r�rFr�r�r,r,r,r-r��s909192939495r�c@s.eZdZddd�Zeddd��Zddd�ZdS)�CliDetectionResult�pathrr3rrOrK�alternative_encodingsr]rqrrr9rr:�unicode_path�is_preferredcCsF||_|96|_||_||_||_||_||_||_||_|	|_	||_97dSrI)r�r�r3rOr�r]rqrr9r:r�)r+r�r3rOr�r]rqrr9r:r�r�r,r,r-r.=s98zCliDetectionResult.__init__r1�dict[str, Any]cCs2|j|j|j|j|j|j|j|j|j|j	|j99d�S)N�r�r3rOr�r]rqrr9r:r�r�r�r?r,r,r-�__dict__Ws�zCliDetectionResult.__dict__cCst|jddd�S)NT�)�ensure_ascii�indent)rr�r?r,r,r-�to_jsongszCliDetectionResult.to_jsonN)r�rr3rrOrKr�rKr]rrqrKrrr9rr:rr�rr�r)r1r�r�)r�r�r�r.r�r�r�r,r,r,r-r�<s100101r�N)�102__future__rZencodings.aliasesr�hashlibr�jsonr�rer�typingrrr	r103Zconstantrr
�utilsrrrrr�rrZCoherenceMatchrr�r,r,r,r-�<module>siC
Aluode/PerceptionLabPortable · CoolFace