1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
U
M±dêJã @s\ddlZddlmZddlmZmZmZmZmZddl    m
Z
m Z m Z m Z ddlmZmZmZmZddlmZddlmZmZdd    lmZmZmZmZmZmZmZe  d
¡Z!e "¡Z#e# $e %d ¡¡de&e'e'e(eee)eee)e*e*e(edœ
dd„Z+dee'e'e(eee)eee)e*e*e(edœ
dd„Z,dde'e'e(eee)eee)e*e*e(edœ
dd„Z-dS)éN)ÚPathLike)ÚAnyÚBinaryIOÚListÚOptionalÚSeté)Úcoherence_ratioÚencoding_languagesÚmb_encoding_languagesÚmerge_coherence_ratios)ÚIANA_SUPPORTEDÚTOO_BIG_SEQUENCEÚTOO_SMALL_SEQUENCEÚTRACE)Ú
mess_ratio)Ú CharsetMatchÚCharsetMatches)Úany_specified_encodingÚcut_sequence_chunksÚ    iana_nameÚidentify_sig_or_bomÚ is_cp_similarÚis_multi_byte_encodingÚshould_strip_sig_or_bomZcharset_normalizerz)%(asctime)s | %(levelname)s | %(message)séé皙™™™™É?TF皙™™™™¹?)
Ú    sequencesÚstepsÚ
chunk_sizeÚ    thresholdÚ cp_isolationÚ cp_exclusionÚpreemptive_behaviourÚexplainÚlanguage_thresholdÚreturnc    . Cs    t|ttfƒs td t|ƒ¡ƒ‚|r>tj}    t t    ¡t 
t ¡t |ƒ}
|
dkrŽt  d¡|rvt t    ¡t 
|    prtj¡tt|dddgdƒgƒS|dk    rºt t d    d
 |¡¡d d „|Dƒ}ng}|dk    rêt t d d
 |¡¡dd „|Dƒ}ng}|
||krt t d|||
¡d}|
}|dkr:|
||kr:t|
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t||gƒSq6t |ƒdkr¶|s&|s&|r2t t d4¡|rRt  d5|j1¡| |¡nd|rb|dks†|r||r||j2|j2ks†|dk    rœt  d6¡| |¡n|r¶t  d7¡| |¡|rÚt  d8| 3¡j1t |ƒd¡n
t  d9¡|rþt t    ¡t 
|    ¡|S):af
    Given a raw bytes sequence, return the best possibles charset usable to render str objects.
    If there is no results, it is a strong indicator that the source is binary/not text.
    By default, the process will extract 5 blocks of 512o each to assess the mess and coherence of a given sequence.
    And will give up a particular code page after 20% of measured mess. Those criteria are customizable at will.
 
    The preemptive behavior DOES NOT replace the traditional detection workflow, it prioritize a particular code page
    but never take it for granted. Can improve the performance.
 
    You may want to focus your attention to some code page or/and not others, use cp_isolation and cp_exclusion for that
    purpose.
 
    This function will strip the SIG in the payload/sequence every time except on UTF-16, UTF-32.
    By default the library does not setup any handler other than the NullHandler, if you choose to set the 'explain'
    toggle to True it will alter the logger configuration to add a StreamHandler that is suitable for debugging.
    Custom logging format and handler can be set manually.
    z4Expected object of type bytes or bytearray, got: {0}rz<Encoding detection on empty bytes, assuming utf_8 intention.Úutf_8gFÚNz`cp_isolation is set. use this flag for debugging purpose. limited list of encoding allowed : %s.z, cSsg|]}t|dƒ‘qS©F©r©Ú.0Úcp©r0úMd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\charset_normalizer/api.pyÚ
<listcomp>Zszfrom_bytes.<locals>.<listcomp>zacp_exclusion is set. use this flag for debugging purpose. limited list of encoding excluded : %s.cSsg|]}t|dƒ‘qSr+r,r-r0r0r1r2esz^override steps (%i) and chunk_size (%i) as content does not fit (%i byte(s) given) parameters.rz>Trying to detect encoding from a tiny portion of ({}) byte(s).zIUsing lazy str decoding because the payload is quite large, ({}) byte(s).z@Detected declarative mark in sequence. Priority +1 given for %s.zIDetected a SIG or BOM mark on first %i byte(s). Priority +1 given for %s.Úascii>Úutf_16Úutf_32z\Encoding %s won't be tested as-is because it require a BOM. Will try some sub-encoder LE/BE.>Úutf_7zREncoding %s won't be tested as-is because detection is unreliable without BOM/SIG.z2Encoding %s does not provide an IncrementalDecoderg€„A)Úencodingz9Code page %s does not fit given bytes sequence at ALL. %sTzW%s is deemed too similar to code page %s and was consider unsuited already. Continuing!zpCode page %s is a multi byte encoding table and it appear that at least one character was encoded using n-bytes.éééÿÿÿÿzaLazyStr Loading: After MD chunk decode, code page %s does not fit given bytes sequence at ALL. %sgjè@Ústrict)Úerrorsz^LazyStr Loading: After final lookup, code page %s does not fit given bytes sequence at ALL. %szc%s was excluded because of initial chaos probing. Gave up %i time(s). Computed mean chaos is %f %%.édé)Úndigitsz=%s passed initial chaos probing. Mean measured chaos is %f %%z&{} should target any language(s) of {}ú,z We detected language {} using {}rz.Encoding detection: %s is most likely the one.zoEncoding detection: %s is most likely the one as we detected a BOM or SIG within the beginning of the sequence.zONothing got out of the detection process. Using ASCII/UTF-8/Specified fallback.z7Encoding detection: %s will be used as a fallback matchz:Encoding detection: utf_8 will be used as a fallback matchz:Encoding detection: ascii will be used as a fallback matchz]Encoding detection: Found %s as plausible (best-candidate) for content. With %i alternatives.z=Encoding detection: Unable to determine any suitable charset.)4Ú
isinstanceÚ    bytearrayÚbytesÚ    TypeErrorÚformatÚtypeÚloggerÚlevelÚ
addHandlerÚexplain_handlerÚsetLevelrÚlenÚdebugÚ removeHandlerÚloggingÚWARNINGrrÚlogÚjoinÚintrrrÚappendÚsetrr ÚaddrrÚModuleNotFoundErrorÚ ImportErrorÚstrÚUnicodeDecodeErrorÚ LookupErrorrÚrangeÚmaxrrÚdecodeÚsumÚroundr
r r    r r7Ú fingerprintÚbest).rr r!r"r#r$r%r&r'Zprevious_logger_levelÚlengthZis_too_small_sequenceZis_too_large_sequenceZprioritized_encodingsZspecified_encodingZtestedZtested_but_hard_failureZtested_but_soft_failureZfallback_asciiZ fallback_u8Zfallback_specifiedÚresultsZ sig_encodingZ sig_payloadZ encoding_ianaZdecoded_payloadZbom_or_sig_availableZstrip_sig_or_bomZis_multi_byte_decoderÚeZsimilar_soft_failure_testZencoding_soft_failedZr_Zmulti_byte_bonusZmax_chunk_gave_upZearly_stop_countZlazy_str_hard_failureZ    md_chunksZ    md_ratiosÚchunkZmean_mess_ratioZfallback_entryZtarget_languagesZ    cd_ratiosZchunk_languagesZcd_ratios_mergedr0r0r1Ú
from_bytes!sîÿÿ
 
 
 
üüû   ÿþÿþÿ
 
ý 
 
ü
 
 
 
 
ÿýý ý ÿüÿü
 ü
 
ü
ýÿ
ýü
÷
&ýÿ
ÿÿÿüÿþýü
 
ú
ÿþÿ
 
ü
ÿþ
ýÿþúÿ ÿþÿ
 
 
ý
 
þþ ÿÿýü
ûù    
 
 
 
ý
 
 
rg)
Úfpr r!r"r#r$r%r&r'r(c        
Cst| ¡||||||||ƒ    S)z†
    Same thing than the function from_bytes but using a file pointer that is already ready.
    Will not close the file pointer.
    )rgÚread)    rhr r!r"r#r$r%r&r'r0r0r1Úfrom_fpôs÷rjz PathLike[Any])
Úpathr r!r"r#r$r%r&r'r(c    
Cs:t|dƒ&}    t|    ||||||||ƒ    W5QR£SQRXdS)z•
    Same thing than the function from_bytes but with one extra step. Opening and reading given file path in binary mode.
    Can raise IOError.
    ÚrbN)Úopenrj)
rkr r!r"r#r$r%r&r'rhr0r0r1Ú    from_paths ÷rn)rrrNNTFr)rrrNNTFr)rrrNNTFr).rOÚosrÚtypingrrrrrZcdr    r
r r Zconstantr rrrZmdrÚmodelsrrÚutilsrrrrrrrÚ    getLoggerrGÚ StreamHandlerrJÚ setFormatterÚ    FormatterrCrSÚfloatrYÚboolrgrjrnr0r0r0r1Ú<module>s–  $
ÿ÷
 
ö X÷
 
ö ÷
 
ö