a ‚oe¼.ã@sªddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z m Z ddlmZddlmZmZmZGdd „d ƒZGd d „d ƒZe eefZe eZGd d „d ƒZdS)é)Úaliases)Úsha256)Údumps)ÚAnyÚDictÚIteratorÚListÚOptionalÚTupleÚUnioné)ÚTOO_BIG_SEQUENCE)Ú iana_nameÚis_multi_byte_encodingÚ unicode_rangec@sÎeZdZd8eeeedeedœdd„Ze edœdd„Z e edœd d „Z e ed œd d „ƒZ ed œdd„Zed œdd„Zdddœdd„Ze ed œdd„ƒZe eed œdd„ƒZe ed œdd„ƒZe ed œdd„ƒZe eed œdd„ƒZe ed œdd„ƒZe ed œd d!„ƒZe ed œd"d#„ƒZe ed œd$d%„ƒZe ed œd&d'„ƒZe ed œd(d)„ƒZe edd œd*d+„ƒZe ed œd,d-„ƒZe eed œd.d/„ƒZe eed œd0d1„ƒZ d9eed3œd4d5„Z!e ed œd6d7„ƒZ"dS):Ú CharsetMatchNÚCoherenceMatches)ÚpayloadÚguessed_encodingÚmean_mess_ratioÚhas_sig_or_bomÚ languagesÚdecoded_payloadcCsF||_||_||_||_||_d|_g|_d|_d|_d|_ ||_ dS)Nç) Ú_payloadÚ _encodingÚ_mean_mess_ratioÚ _languagesÚ_has_sig_or_bomÚ_unicode_rangesÚ_leavesZ_mean_coherence_ratioÚ_output_payloadÚ_output_encodingÚ_string)Úselfrrrrrr©r%ú:C:\Program Files\Certbot\pkgs\charset_normalizer\models.pyÚ__init__ s zCharsetMatch.__init__)ÚotherÚreturncCs>t|tƒs&td t|jƒt|jƒ¡ƒ‚|j|jko<|j|jkS)Nz&__eq__ cannot be invoked on {} and {}.)Ú isinstancerÚ TypeErrorÚformatÚstrÚ __class__ÚencodingÚ fingerprint©r$r(r%r%r&Ú__eq__$s ÿÿzCharsetMatch.__eq__cCsŒt|tƒst‚t|j|jƒ}t|j|jƒ}|dkrJ|dkrJ|j|jkS|dkr€|dkr€t|jƒtkrt|j|jkS|j |j kS|j|jkS)zQ Implemented to make sorted available upon CharsetMatches items. g{®Gáz„?g{®Gáz”?) r*rÚ ValueErrorÚabsÚchaosÚ coherenceÚlenrr Úmulti_byte_usage)r$r(Zchaos_differenceZcoherence_differencer%r%r&Ú__lt__-s    zCharsetMatch.__lt__©r)cCsdtt|ƒƒt|jƒS)Ngð?)r7r-Úraw©r$r%r%r&r8CszCharsetMatch.multi_byte_usagecCs"|jdurt|j|jdƒ|_|jS)NÚstrict)r#r-rrr<r%r%r&Ú__str__Gs zCharsetMatch.__str__cCsd |j|j¡S)Nz)r,r/r0r<r%r%r&Ú__repr__MszCharsetMatch.__repr__cCs8t|tƒr||kr"td |j¡ƒ‚d|_|j |¡dS)Nz;Unable to add instance <{}> as a submatch of a CharsetMatch)r*rr3r,r.r#r Úappendr1r%r%r&Ú add_submatchPsÿÿzCharsetMatch.add_submatchcCs|jS©N)rr<r%r%r&r/[szCharsetMatch.encodingcCsDg}t ¡D]2\}}|j|kr*| |¡q |j|kr | |¡q |S)z‚ Encoding name are known by many name, using this could help when searching for IBM855 when it's listed as CP855. )rÚitemsr/r@)r$Z also_known_asÚuÚpr%r%r&Úencoding_aliases_s    zCharsetMatch.encoding_aliasescCs|jSrB©rr<r%r%r&ÚbomlszCharsetMatch.bomcCs|jSrBrGr<r%r%r&Úbyte_order_markpszCharsetMatch.byte_order_markcCsdd„|jDƒS)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'. cSsg|] }|d‘qS)rr%)Ú.0Úer%r%r&Ú zóz*CharsetMatch.languages..©rr<r%r%r&rtszCharsetMatch.languagescCsp|jsbd|jvrdSddlm}m}t|jƒr8||jƒn||jƒ}t|ƒdksVd|vrZdS|dS|jddS)z’ Most probable language found in decoded sequence. If none were detected or inferred, the property will return "Unknown". ÚasciiZEnglishr)Úencoding_languagesÚmb_encoding_languagesz Latin BasedZUnknown)rÚcould_be_from_charsetZcharset_normalizer.cdrPrQrr/r7)r$rPrQrr%r%r&Úlanguage|s ÿ ýzCharsetMatch.languagecCs|jSrB)rr<r%r%r&r5˜szCharsetMatch.chaoscCs|js dS|jddS)Nrrr rNr<r%r%r&r6œszCharsetMatch.coherencecCst|jddd�S©Nédé)Úndigits)Úroundr5r<r%r%r&Ú percent_chaos¢szCharsetMatch.percent_chaoscCst|jddd�SrT)rXr6r<r%r%r&Úpercent_coherence¦szCharsetMatch.percent_coherencecCs|jS)z+ Original untouched bytes. )rr<r%r%r&r;ªszCharsetMatch.rawcCs|jSrB)r r<r%r%r&Úsubmatch±szCharsetMatch.submatchcCst|jƒdkS©Nr)r7r r<r%r%r&Ú has_submatchµszCharsetMatch.has_submatchcCs@|jdur|jSdd„t|ƒDƒ}ttdd„|Dƒƒƒ|_|jS)NcSsg|] }t|ƒ‘qSr%)r)rJÚcharr%r%r&rL¾sz*CharsetMatch.alphabets..cSsh|] }|r|’qSr%r%)rJÚrr%r%r&Ú ÂrMz)CharsetMatch.alphabets..)rr-ÚsortedÚlist)r$Zdetected_rangesr%r%r&Ú alphabets¹s ÿzCharsetMatch.alphabetscCs|jgdd„|jDƒS)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'. cSsg|] }|j‘qSr%)r/)rJÚmr%r%r&rLÌrMz6CharsetMatch.could_be_from_charset..)rr r<r%r%r&rRÅsz"CharsetMatch.could_be_from_charsetÚutf_8)r/r)cCs2|jdus|j|kr,||_t|ƒ |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Úreplace)r"r-Úencoder!)r$r/r%r%r&ÚoutputÎszCharsetMatch.outputcCst| ¡ƒ ¡S)zw Retrieve the unique SHA256 computed using the transformed (re-encoded) payload. Not the original one. )rrhZ hexdigestr<r%r%r&r0ÙszCharsetMatch.fingerprint)N)re)#Ú__name__Ú __module__Ú __qualname__Úbytesr-ÚfloatÚboolr r'Úobjectr2r9Úpropertyr8r>r?rAr/rrFrHrIrrSr5r6rYrZr;r[r]rcrRrhr0r%r%r%r&r sbùù      rc@s¢eZdZdZdeeedœdd„Zeedœdd„Z e e e fed œd d „Z e dœd d „Zedœdd„Zedd œdd„Zeddœdd„Zeddœdd„ZdS)Ú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. N)ÚresultscCs|r t|ƒng|_dSrB)raÚ_results)r$rrr%r%r&r'çszCharsetMatches.__init__r:ccs|jEdHdSrB©rsr<r%r%r&Ú__iter__êszCharsetMatches.__iter__)Úitemr)cCsNt|tƒr|j|St|tƒrFt|dƒ}|jD]}||jvr.|Sq.t‚dS)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. FN)r*Úintrsr-rrRÚKeyError)r$rvÚresultr%r%r&Ú __getitem__ís       zCharsetMatches.__getitem__cCs t|jƒSrB©r7rsr<r%r%r&Ú__len__ûszCharsetMatches.__len__cCst|jƒdkSr\r{r<r%r%r&Ú__bool__þszCharsetMatches.__bool__cCs|t|tƒstd t|jƒ¡ƒ‚t|jƒtkr`|j D],}|j |j kr2|j |j kr2|  |¡dSq2|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)r*rr3r,r-r.r7r;r rsr0r5rAr@ra)r$rvÚmatchr%r%r&r@s ÿÿ   zCharsetMatches.appendrcCs|js dS|jdS)zQ Simply return the first match. Strict equivalent to matches[0]. Nrrtr<r%r%r&ÚbestszCharsetMatches.bestcCs| ¡S)zP Redundant method, call the method best(). Kept for BC reasons. )rr<r%r%r&ÚfirstszCharsetMatches.first)N)rirjrkÚ__doc__r rrr'rrur rwr-rzr|rnr}r@rr€r%r%r%r&rqásrqc @sjeZdZeeeeeeeeeeeeeeeedœ dd„Ze e ee fdœdd„ƒZ edœdd„Z d S) ÚCliDetectionResult© Úpathr/rFÚalternative_encodingsrSrcrr5r6Ú unicode_pathÚ is_preferredc CsF||_| |_||_||_||_||_||_||_||_| |_ | |_ dSrB) r„r†r/rFr…rSrcrr5r6r‡) r$r„r/rFr…rSrcrr5r6r†r‡r%r%r&r')szCliDetectionResult.__init__r:c Cs2|j|j|j|j|j|j|j|j|j|j |j dœ S)Nrƒrƒr<r%r%r&Ú__dict__CsõzCliDetectionResult.__dict__cCst|jddd�S)NTé)Z ensure_asciiÚindent)rrˆr<r%r%r&Úto_jsonSszCliDetectionResult.to_jsonN)rirjrkr-r rrnrmr'rprrrˆr‹r%r%r%r&r‚(sô r‚N)Zencodings.aliasesrZhashlibrZjsonrÚtypingrrrrr r r Zconstantr Zutilsrrrrrqr-rmZCoherenceMatchrr‚r%r%r%r&Ús   $ XC