7,j3ddlmZddlmZddlmZddlmZddlm Z m Z m Z m Z ddl mZmZddlmZmZmZGd d ZGd d Ze eefZe eZGd dZdS)) annotations)aliases)dumps)sub)AnyIteratorListTuple)RE_POSSIBLE_ENCODING_INDICATIONTOO_BIG_SEQUENCE) iana_nameis_multi_byte_encoding unicode_rangeceZdZ d1d2dZd3dZd3dZed4dZd5dZd5dZ d6dZ ed5dZ ed7dZ ed8dZ ed8dZed7dZed5d Zed4d!Zed4d"Zed4d#Zed4d$Zed9d%Zed:d'Zed8d(Zed7d)Zed7d*Zd;d CharsetMatchNpayloadbytes | bytearrayguessed_encodingstrmean_mess_ratiofloathas_sig_or_bombool languagesCoherenceMatchesdecoded_payload str | Nonepreemptive_declarationc||_||_||_||_||_d|_g|_d|_d|_d|_ ||_ ||_ dS)N) _payload _encoding_mean_mess_ratio _languages_has_sig_or_bom_unicode_ranges_leaves_mean_coherence_ratio_output_payload_output_encoding_string_preemptive_declaration)selfrrrrrrrs IC:\PYTHON\GemmaClient\venv\Lib\site-packages\charset_normalizer/models.py__init__zCharsetMatch.__init__ se,3 .'6,5%315+- ,/"-1,0#2 3I$$$otherobjectreturnct|ts/t|trt||jkSdS|j|jko|j|jkS)NF) isinstancerrrencoding fingerprintr.r2s r/__eq__zCharsetMatch.__eq__)s_%.. %%% 9 ''4=885}.X43CuGX3XXr1ct|tstt|j|jz }t|j|jz }|dkr|dkr|j|jkS|dkrC|dkr=t |jtkr|j|jkS|j |j kS|j|jkS)zQ Implemented to make sorted available upon CharsetMatches items. g{Gzt?g{Gz?) r6r ValueErrorabschaos coherencelenr"r multi_byte_usage)r.r2chaos_differencecoherence_differences r/__lt__zCharsetMatch.__lt__0s%..  "%dj5;&>"?"?&)$.5?*J&K&K e # #(EO3 3  % %*>$*F*F4=!!%555zEK//(5+AA AzEK''r1cjdtt|t|jz z S)Ng?)r@rrawr.s r/rAzCharsetMatch.multi_byte_usageFs&c#d))nns48}}455r1c|j^t|j|jd|_|jr7|jdkr,|jr%|jddkr|jdd|_|jS)Nstrictutf_7rur )r,rr"r#r&rGs r/__str__zCharsetMatch.__str__Jsp < t}dnhGGDL $ 0Ng--L.LOx//#|ABB/ |r1c(d|jd|jdS)Nz)r7r8rGs r/__repr__zCharsetMatch.__repr__Zs IIIT5EIIIIr1Nonect|tr||kr'td|jd|_|j|dS)Nz;Unable to add instance <{}> as a submatch of a CharsetMatch)r6rr<format __class__r,r(appendr9s r/ add_submatchzCharsetMatch.add_submatch]sk%.. %4--MTTO    E"""""r1c|jSN)r#rGs r/r7zCharsetMatch.encodinghs ~r1 list[str]cg}tjD]F\}}|j|kr||&|j|kr||G|S)z Encoding name are known by many name, using this could help when searching for IBM855 when it's listed as CP855. )ritemsr7rR)r. also_known_asups r/encoding_aliaseszCharsetMatch.encoding_aliaseslsn $& MOO ( (DAq}!!$$Q''''!##$$Q'''r1c|jSrUr&rGs r/bomzCharsetMatch.bomy ##r1c|jSrUr^rGs r/byte_order_markzCharsetMatch.byte_order_mark}r`r1c$d|jDS)z Return the complete list of possible languages found in decoded sequence. Usually not really useful. Returned list may be empty even if 'language' property return something != 'Unknown'. cg|] }|d S)r).0es r/ z*CharsetMatch.languages..s...!...r1r%rGs r/rzCharsetMatch.languagess /.do....r1c|jshd|jvrdSddlm}m}t |jr||jn||j}t|dksd|vrdS|dS|jddS)z Most probable language found in decoded sequence. If none were detected or inferred, the property will return "Unknown". asciiEnglishr)encoding_languagesmb_encoding_languagesz Latin BasedUnknown)r%could_be_from_charsetcharset_normalizer.cdrmrnrr7r@)r.rmrnrs r/languagezCharsetMatch.languages  $444 y X W W W W W W W*$-887%%dm444'' 66  9~~""my&@&@ yQ< q!!$$r1c|jSrU)r$rGs r/r>zCharsetMatch.chaoss $$r1c:|jsdS|jddS)Nr!rr rirGs r/r?zCharsetMatch.coherences# 3q!!$$r1c4t|jdzdSNd)ndigits)roundr>rGs r/ percent_chaoszCharsetMatch.percent_chaossTZ#%q1111r1c4t|jdzdSrv)rzr?rGs r/percent_coherencezCharsetMatch.percent_coherencesT^c)15555r1c|jS)z+ Original untouched bytes. )r"rGs r/rFzCharsetMatch.raws }r1list[CharsetMatch]c|jSrU)r(rGs r/submatchzCharsetMatch.submatchs |r1c2t|jdkSNr)r@r(rGs r/ has_submatchzCharsetMatch.has_submatchs4<  1$$r1c|j|jSdt|D}ttd|D|_|jS)Nc,g|]}t|Sre)r)rfchars r/rhz*CharsetMatch.alphabets..s ,W,W,WT]4-@-@,W,W,Wr1ch|]}||Srere)rfrs r/ z)CharsetMatch.alphabets..s+L+L+L!!+LA+L+L+Lr1)r'rsortedlist)r.detected_rangess r/ alphabetszCharsetMatch.alphabetss^   +' ',W,WSQUYY,W,W,W%d+L+L+L+L+L&M&MNN##r1c6|jgd|jDzS)z The complete list of encoding that output the exact SAME str result and therefore could be the originating encoding. This list does include the encoding available in property 'encoding'. cg|] }|j Sre)r7)rfms r/rhz6CharsetMatch.could_be_from_charset..s"D"D"D!1:"D"D"Dr1)r#r(rGs r/rpz"CharsetMatch.could_be_from_charsets%"D"Dt|"D"D"DDDr1utf_8r7bytesc<j j|kr|_t}jKjdvr0t t fd|ddd}||ddz}||d_jS)z Method to get re-encoded bytes payload using given target encoding. Default to UTF-8. Any errors will be simply ignored by the encoder NOT replaced. N)zutf-8utf8rc&|j|d|d|dt jddS)Nrr _-)stringspanreplacegroupsrr+)rr.s r/z%CharsetMatch.output..shahqvvxx{QVVXXa['@AII 1 !$"788@@cJJr1i r )countr)r+rr-lowerrr encoder*)r.r7decoded_stringpatched_headers` r/outputzCharsetMatch.outputs  (D,AX,M,M$,D ! YYN,806688122"%3#5D5)""""0.2G!G#1#8#89#M#MD ##r1intc:tt|S)z] Retrieve a hash fingerprint of the decoded payload, used for deduplication. )hashrrGs r/r8zCharsetMatch.fingerprints CIIr1)NN)rrrrrrrrrrrrrr)r2r3r4r)r4rr4r)r2rr4rN)r4rVr4r)r4r)r4r)r)r7rr4rr4r)__name__ __module__ __qualname__r0r:rDpropertyrArKrMrSr7r\r_rbrrrr>r?r{r}rFrrrrprr8rer1r/rr s'+-1JJJJJ8YYYY((((,666X6 JJJJ # # # #X   X $$$X$$$$X$///X/%%%X%6%%%X%%%%X% 222X2666X6X X%%%X%$$$X$EEEXE$$$$$:Xr1rcTeZdZdZdddZddZdd ZddZddZddZ ddZ ddZ dS)CharsetMatchesz Container with every CharsetMatch items ordered by default from most probable to the less one. Act like a list(iterable) but does not implements all related methods. Nresultslist[CharsetMatch] | Nonec6|rt|ng|_dSrU)r_results)r.rs r/r0zCharsetMatches.__init__s?F,NF7OOOB r1r4Iterator[CharsetMatch]c#$K|jEd{VdSrUrrGs r/__iter__zCharsetMatches.__iter__s&=         r1item int | strrct|tr |j|St|tr't |d}|jD]}||jvr|cSt )z Retrieve a single item either by its position or encoding name (alias may be used here). Raise KeyError upon invalid index or encoding not present in results. F)r6rrrrrpKeyError)r.rresults r/ __getitem__zCharsetMatches.__getitem__ sv dC  '=& & dC  "T5))D- " "6777!MMM8r1rc*t|jSrUr@rrGs r/__len__zCharsetMatches.__len__s4=!!!r1rc2t|jdkSrrrGs r/__bool__zCharsetMatches.__bool__s4=!!A%%r1rNct|ts4tdt |jt |jtkrB|j D]:}|j |j kr(|j |j kr| |dS;|j |t|j |_ dS)z~ Insert a single match. Will be inserted accordingly to preserve sort. Can be inserted as a submatch. z-Cannot append instance '{}' to CharsetMatchesN)r6rr<rPrrQr@rFr rr8r>rSrRr)r.rmatchs r/rRzCharsetMatches.appends $ -- ?FF''  tx==+ + +  $(888U[DJ=V=V&&t,,,FF T"""t}-- r1CharsetMatch | Nonec.|jsdS|jdS)zQ Simply return the first match. Strict equivalent to matches[0]. NrrrGs r/bestzCharsetMatches.best2s } 4}Qr1c*|S)zP Redundant method, call the method best(). Kept for BC reasons. )rrGs r/firstzCharsetMatches.first:syy{{r1rU)rr)r4r)rrr4rrr)rrr4rN)r4r) rrr__doc__r0rrrrrRrrrer1r/rrs OOOOO!!!!    """"&&&&....(    r1rc6eZdZddZeddZddZdS)CliDetectionResultpathrr7rr\rValternative_encodingsrrrrrr>rr? unicode_path is_preferredc ||_| |_||_||_||_||_||_||_||_| |_ | |_ dSrU) rrr7r\rrrrrr>r?r) r.rr7r\rrrrrr>r?rrs r/r0zCliDetectionResult.__init__Fs\ (4$, +;0E"% $-$2! )".r1r4dict[str, Any]c |j|j|j|j|j|j|j|j|j|j |j d S)N rr7r\rrrrrr>r?rrrrGs r/__dict__zCliDetectionResult.__dict__`sOI $ 5%)%? "1Z - -   r1c0t|jddS)NT) ensure_asciiindent)rrrGs r/to_jsonzCliDetectionResult.to_jsonpsT]a@@@@r1N)rrr7rr\rVrrVrrrrrVrrr>rr?rrrrr)r4rr)rrrr0rrrrer1r/rrEsb////4    X  AAAAAAr1rN) __future__rencodings.aliasesrjsonrrertypingrrr r constantr r utilsrrrrrrrCoherenceMatchrrrer1r/rs`""""""%%%%%%------------GGGGGGGGCCCCCCCCCCooooooood@@@@@@@@FsEz"',A,A,A,A,A,A,A,A,A,Ar1