a ٓfh-@sddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z m Z ddlmZddlmZmZmZGdd d ZGd d d Ze eefZe eZGd d d ZdS))aliases)sha256)dumps)AnyDictIteratorListOptionalTupleUnion)TOO_BIG_SEQUENCE) iana_nameis_multi_byte_encoding unicode_rangec@seZdZd8eeeedeedddZe edddZ e edd d Z e ed d d Z ed ddZed ddZdddddZe ed ddZe eed ddZe ed ddZe ed ddZe eed ddZe ed ddZe 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 d0d1Z d9eed3d4d5Z!e ed d6d7Z"dS): CharsetMatchNCoherenceMatches)payloadguessed_encodingmean_mess_ratiohas_sig_or_bom languagesdecoded_payloadcCsF||_||_||_||_||_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)selfrrrrrrr&}/sparta/input/_build_configuration/image_build+validate/lib/bmcenv/lib64/python3.9/site-packages/charset_normalizer/models.py__init__ s zCharsetMatch.__init__)otherreturncCs>t|ts&tdt|jt|j|j|jko<|j|jkS)Nz&__eq__ cannot be invoked on {} and {}.) isinstancer TypeErrorformatstr __class__encoding fingerprintr%r)r&r&r'__eq__$s zCharsetMatch.__eq__cCst|tstt|j|j}t|j|j}|dkrJ|dkrJ|j|jkS|dkr|dkrt|jtkrt|j|jkS|j |j kS|j|jkS)zQ Implemented to make sorted available upon CharsetMatches items. g{Gz?g{Gz?) r+r ValueErrorabschaos coherencelenrr multi_byte_usage)r%r)chaos_differencecoherence_differencer&r&r'__lt__-s    zCharsetMatch.__lt__r*cCsdtt|t|jS)Ng?)r8r.rawr%r&r&r'r9CszCharsetMatch.multi_byte_usagecCs"|jdurt|j|jd|_|jS)Nstrict)r$r.rrr?r&r&r'__str__Gs zCharsetMatch.__str__cCsd|j|jS)Nz)r-r0r1r?r&r&r'__repr__MszCharsetMatch.__repr__cCs8t|tr||kr"td|jd|_|j|dS)Nz;Unable to add instance <{}> as a submatch of a CharsetMatch)r+rr4r-r/r$r appendr2r&r&r' add_submatchPszCharsetMatch.add_submatchcCs|jSN)rr?r&r&r'r0[szCharsetMatch.encodingcCsDg}tD]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. )ritemsr0rC)r% also_known_asupr&r&r'encoding_aliases_s    zCharsetMatch.encoding_aliasescCs|jSrErr?r&r&r'bomlszCharsetMatch.bomcCs|jSrErKr?r&r&r'byte_order_markpszCharsetMatch.byte_order_markcCsdd|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'. cSsg|] }|dqS)rr&).0er&r&r' zz*CharsetMatch.languages..rr?r&r&r'rtszCharsetMatch.languagescCsp|jsbd|jvrdSddlm}m}t|jr8||jn||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". asciiEnglishr)encoding_languagesmb_encoding_languagesz Latin BasedUnknown)rcould_be_from_charsetcharset_normalizer.cdrUrVrr0r8)r%rUrVrr&r&r'language|s  zCharsetMatch.languagecCs|jSrE)rr?r&r&r'r6szCharsetMatch.chaoscCs|js dS|jddS)Nrrr rRr?r&r&r'r7szCharsetMatch.coherencecCst|jdddSNd)ndigits)roundr6r?r&r&r' percent_chaosszCharsetMatch.percent_chaoscCst|jdddSr[)r_r7r?r&r&r'percent_coherenceszCharsetMatch.percent_coherencecCs|jS)z+ Original untouched bytes. )rr?r&r&r'r>szCharsetMatch.rawcCs|jSrE)r r?r&r&r'submatchszCharsetMatch.submatchcCst|jdkSNr)r8r r?r&r&r' has_submatchszCharsetMatch.has_submatchcCs@|jdur|jSddt|D}ttdd|D|_|jS)NcSsg|] }t|qSr&)r)rNcharr&r&r'rPsz*CharsetMatch.alphabets..cSsh|] }|r|qSr&r&)rNrr&r&r' rQz)CharsetMatch.alphabets..)rr.sortedlist)r%detected_rangesr&r&r' alphabetss zCharsetMatch.alphabetscCs|jgdd|jDS)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|] }|jqSr&)r0)rNmr&r&r'rPrQz6CharsetMatch.could_be_from_charset..)rr r?r&r&r'rXsz"CharsetMatch.could_be_from_charsetutf_8)r0r*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. Nreplace)r#r.encoder")r%r0r&r&r'outputszCharsetMatch.outputcCst|S)zw Retrieve the unique SHA256 computed using the transformed (re-encoded) payload. Not the original one. )rrp hexdigestr?r&r&r'r1szCharsetMatch.fingerprint)N)rm)#__name__ __module__ __qualname__bytesr.floatboolr r(objectr3r<propertyr9rArBrDr0rrJrLrMrrZr6r7r`rar>rbrdrkrXrpr1r&r&r&r'r sb      rc@seZdZdZdeeedddZeedddZ e e e fed d d Z e dd d ZedddZedd ddZeddddZeddddZdS)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|_dSrE)rh_results)r%r{r&r&r'r(szCharsetMatches.__init__r=ccs|jEdHdSrEr|r?r&r&r'__iter__szCharsetMatches.__iter__)itemr*cCsNt|tr|j|St|trFt|d}|jD]}||jvr.|Sq.tdS)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+intr|r.rrXKeyError)r%rresultr&r&r' __getitem__s       zCharsetMatches.__getitem__cCs t|jSrEr8r|r?r&r&r'__len__szCharsetMatches.__len__cCst|jdkSrcrr?r&r&r'__bool__szCharsetMatches.__bool__cCs|t|tstdt|jt|jtkr`|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+rr4r-r.r/r8r>r r|r1r6rDrCrh)r%rmatchr&r&r'rCs    zCharsetMatches.appendrcCs|js dS|jdS)zQ Simply return the first match. Strict equivalent to matches[0]. Nrr}r?r&r&r'bestszCharsetMatches.bestcCs|S)zP Redundant method, call the method best(). Kept for BC reasons. )rr?r&r&r'firstszCharsetMatches.first)N)rrrsrt__doc__r rrr(rr~r rr.rrrwrrCrrr&r&r&r'rzsrzc @sjeZdZeeeeeeeeeeeeeeeed ddZe e ee fdddZ edddZ d S) CliDetectionResult pathr0rJalternative_encodingsrZrkrr6r7 unicode_path is_preferredc CsF||_| |_||_||_||_||_||_||_||_| |_ | |_ dSrE) rrr0rJrrZrkrr6r7r) r%rr0rJrrZrkrr6r7rrr&r&r'r()szCliDetectionResult.__init__r=c Cs2|j|j|j|j|j|j|j|j|j|j |j d S)Nrrr?r&r&r'__dict__CszCliDetectionResult.__dict__cCst|jdddS)NT) ensure_asciiindent)rrr?r&r&r'to_jsonSszCliDetectionResult.to_jsonN)rrrsrtr.r rrwrvr(ryrrrrr&r&r&r'r(s rN)encodings.aliasesrhashlibrjsonrtypingrrrrr r r constantr utilsrrrrrzr.rvCoherenceMatchrrr&r&r&r's   $ XC