
    *pj4                        S SK Jr  S SKJr  S SKJr  S SKJrJrJ	r	J
r
  SSKJrJr  SSKJrJrJr   " S S	5      r " S
 S5      r\
\\4   r\	\   r " S S5      rg)    )annotations)aliases)sub)AnyIteratorListTuple   )RE_POSSIBLE_ENCODING_INDICATIONTOO_BIG_SEQUENCE)	iana_nameis_multi_byte_encodingunicode_rangec                     \ rS rSr  S             SS jjrSS jrSS jr\SS j5       rS S jr	S S jr
S!S	 jr\S S
 j5       r\S"S j5       r\S#S j5       r\S#S j5       r\S"S j5       r\S S j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       r\S$S j5       r\S%S j5       r\S#S j5       r\S"S j5       r\S"S j5       rS&S'S jjr\S(S j5       rSrg))CharsetMatch   Nc                    Xl         X l        X0l        XPl        X@l        S U l        / U l        SU l        S U l        S U l	        X`l
        Xpl        g )N        )_payload	_encoding_mean_mess_ratio
_languages_has_sig_or_bom_unicode_ranges_leaves_mean_coherence_ratio_output_payload_output_encoding_string_preemptive_declaration)selfpayloadguessed_encodingmean_mess_ratiohas_sig_or_bom	languagesdecoded_payloadpreemptive_declarations           U/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/charset_normalizer/models.py__init__CharsetMatch.__init__   sQ     ,3.'6,5%315+-,/"-1,0#23I$    c                    [        U[        5      (       d/  [        U[        5      (       a  [        US5      U R                  :H  $ gU R                  UR                  :H  =(       a    U R
                  UR
                  :H  $ )NF)
isinstancer   strr   encodingfingerprintr!   others     r)   __eq__CharsetMatch.__eq__(   s`    %..%%%
 !.$--??}}.X43C3CuGXGX3XXr,   c                   [        U[        5      (       d  [        e[        U R                  UR                  -
  5      n[        U R
                  UR
                  -
  5      nUS:  a  US:  a  U R
                  UR
                  :  $ US:  aU  US::  aO  [        U R                  5      [        :  a  U R                  UR                  :  $ U R                  UR                  :  $ U R                  UR                  :  $ )zA
Implemented to make sorted available upon CharsetMatches items.
g{Gzt?g{Gz?)
r.   r   
ValueErrorabschaos	coherencelenr   r   multi_byte_usage)r!   r3   chaos_differencecoherence_differences       r)   __lt__CharsetMatch.__lt__3   s     %.."%djj5;;&>"?&)$..5??*J&K e#(<t(C>>EOO33%*>$*F 4==!%55zzEKK//((5+A+AAAzzEKK''r,   c                n    [        U R                  5      nUS:X  a  gS[        [        U 5      5      U-  -
  $ )Nr   r   g      ?)r;   rawr/   )r!   raw_lens     r)   r<   CharsetMatch.multi_byte_usageI   s3     dhh-a<c#d)nw.//r,   c                2   U R                   c  [        U R                  U R                  S5      U l         U R                  (       aH  U R                  S:X  a8  U R                   (       a'  U R                   S   S:X  a  U R                   SS  U l         U R                   $ )Nstrictutf_7r   u   ﻿r
   )r   r/   r   r   r   r!   s    r)   __str__CharsetMatch.__str__Q   sn    <<t}}dnnhGDL
 $$NNg-LLLLOx/#||AB/||r,   c                <    SU R                    SU R                   S3$ )Nz<CharsetMatch 'z' fp(z)>)r0   r1   rH   s    r)   __repr__CharsetMatch.__repr__a   s"     uT5E5E4FbIIr,   c                    [        U[        5      (       a  X:X  a$  [        SR                  UR                  5      5      eS Ul        U R                  R                  U5        g )Nz;Unable to add instance <{}> as a submatch of a CharsetMatch)r.   r   r7   format	__class__r   r   appendr2   s     r)   add_submatchCharsetMatch.add_submatchd   sP    %..%-MTTOO  E"r,   c                    U R                   $ N)r   rH   s    r)   r0   CharsetMatch.encodingo   s    ~~r,   c                    / n[         R                  " 5        HK  u  p#U R                  U:X  a  UR                  U5        M(  U R                  U:X  d  M:  UR                  U5        MM     U$ )zr
Encoding name are known by many name, using this could help when searching for IBM855 when it's listed as CP855.
)r   itemsr0   rQ   )r!   also_known_asups       r)   encoding_aliasesCharsetMatch.encoding_aliasess   sW    
 $&MMODA}}!$$Q'!#$$Q'	 $
 r,   c                    U R                   $ rU   r   rH   s    r)   bomCharsetMatch.bom       ###r,   c                    U R                   $ rU   r_   rH   s    r)   byte_order_markCharsetMatch.byte_order_mark   rb   r,   c                J    U R                    Vs/ s H  oS   PM	     sn$ s  snf )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'.
r   r   )r!   es     r)   r&   CharsetMatch.languages   s"     #oo.o!o...s    c                ,   U R                   (       dr  SU R                  ;   a  gSSKJnJn  [        U R                  5      (       a  U" U R                  5      OU" U R                  5      n[        U5      S:X  d  SU;   a  gUS   $ U R                   S   S   $ )zz
Most probable language found in decoded sequence. If none were detected or inferred, the property will return
"Unknown".
asciiEnglishr   )encoding_languagesmb_encoding_languageszLatin BasedUnknown)r   could_be_from_charsetcharset_normalizer.cdrm   rn   r   r0   r;   )r!   rm   rn   r&   s       r)   languageCharsetMatch.language   s      $444  X *$--88 &dmm4'6  9~"my&@ Q<q!!$$r,   c                    U R                   $ rU   )r   rH   s    r)   r9   CharsetMatch.chaos   s    $$$r,   c                J    U R                   (       d  gU R                   S   S   $ )Nr   r   r
   rg   rH   s    r)   r:   CharsetMatch.coherence   s     q!!$$r,   c                0    [        U R                  S-  SS9$ Nd      )ndigits)roundr9   rH   s    r)   percent_chaosCharsetMatch.percent_chaos   s    TZZ#%q11r,   c                0    [        U R                  S-  SS9$ ry   )r}   r:   rH   s    r)   percent_coherenceCharsetMatch.percent_coherence   s    T^^c)155r,   c                    U R                   $ )z
Original untouched bytes.
)r   rH   s    r)   rB   CharsetMatch.raw   s    
 }}r,   c                    U R                   $ rU   )r   rH   s    r)   submatchCharsetMatch.submatch   s    ||r,   c                2    [        U R                  5      S:  $ Nr   )r;   r   rH   s    r)   has_submatchCharsetMatch.has_submatch   s    4<< 1$$r,   c                   U R                   b  U R                   $ [        U 5       Vs/ s H  n[        U5      PM     nn[        [	        U Vs1 s H  o3(       d  M  UiM     sn5      5      U l         U R                   $ s  snf s  snf rU   )r   r/   r   sortedlist)r!   chardetected_rangesrs       r)   	alphabetsCharsetMatch.alphabets   sp    +'''MPQUY,WYT]4-@Y,W%d+L!!A+L&MN### -X+Ls   A<
BBc                t    U R                   /U R                   Vs/ s H  oR                  PM     sn-   $ s  snf )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'.
)r   r   r0   )r!   ms     r)   rp   "CharsetMatch.could_be_from_charset   s.     t||"D|!::|"DDD"Ds   5c                :  ^  T R                   b  T R                   U:w  ar  UT l         [        T 5      nT R                  b<  T R                  R                  5       S;  a  [	        [
        U 4S jUSS SS9nX2SS -   nUR                  US5      T l        T R                  $ )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)zutf-8utf8utf_8c                   > U R                   U R                  5       S   U R                  5       S    R                  U R                  5       S   [	        TR
                  5      R                  SS5      5      $ )Nr   r
   _-)stringspanreplacegroupsr   r   )r   r!   s    r)   <lambda>%CharsetMatch.output.<locals>.<lambda>   sW    ahhqvvx{QVVXa[AII
1!$"7"78@@cJr,   i    r
   )countr   )r   r/   r    lowerr   r   encoder   )r!   r0   decoded_stringpatched_headers   `   r)   outputCharsetMatch.output   s    
   (D,A,AX,M$,D! YN,,80066812 "%3 #5D)" "02G!G#1#8#89#MD ###r,   c                *    [        [        U 5      5      $ )zM
Retrieve a hash fingerprint of the decoded payload, used for deduplication.
)hashr/   rH   s    r)   r1   CharsetMatch.fingerprint   s    
 CIr,   )r   r   r   r   r   r   r   r   r   r    r   r   )NN)r"   bytes | bytearrayr#   r/   r$   floatr%   boolr&   CoherenceMatchesr'   
str | Noner(   r   )r3   objectreturnr   )r   r   r   r/   )r3   r   r   None)r   	list[str]r   r   )r   r   )r   zlist[CharsetMatch])r   )r0   r/   r   bytesr   int)__name__
__module____qualname____firstlineno__r*   r4   r?   propertyr<   rI   rL   rR   r0   r\   r`   rd   r&   rr   r9   r:   r~   r   rB   r   r   r   rp   r   r1   __static_attributes__ r,   r)   r   r      s    '+-1J"J J 	J
 J $J $J !+J8	Y(, 0 0 J	#   
 
 $ $ $ $ / / % %6 % % % %
 2 2 6 6     % % $ $ E E$:  r,   r   c                  v    \ rS rSrSrSSS jjrSS jrSS jrSS jrSS jr	SS	 jr
SS
 jrSS jrSS jrSrg)CharsetMatchesi  z
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.
Nc                D    U(       a  [        U5      O/ U l        SU l        g NT)r   _results
_is_sorted)r!   resultss     r)   r*   CharsetMatches.__init__  s    ?FF7OB $r,   c                j    U R                   (       d"  U R                  R                  5         SU l         g g r   )r   r   sortrH   s    r)   _ensure_sortedCharsetMatches._ensure_sorted  s%    MM "DO r,   c              #  X   #    U R                  5         U R                   S h  vN   g  N7frU   )r   r   rH   s    r)   __iter__CharsetMatches.__iter__  s     ==  s    *(*c                   [        U[        5      (       a  U R                  5         U R                  U   $ [        U[        5      (       a2  [        US5      nU R                   H  nXR                  ;   d  M  Us  $    [        e)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)r.   r   r   r   r/   r   rp   KeyError)r!   itemresults      r)   __getitem__CharsetMatches.__getitem__  sk    
 dC  !==&&dC  T5)D--777!M ( r,   c                ,    [        U R                  5      $ rU   r;   r   rH   s    r)   __len__CharsetMatches.__len__'  s    4==!!r,   c                2    [        U R                  5      S:  $ r   r   rH   s    r)   __bool__CharsetMatches.__bool__*  s    4==!A%%r,   c                   [        U[        5      (       d-  [        SR                  [	        UR
                  5      5      5      e[        UR                  5      [        :  a\  U R                   HL  nUR                  UR                  :X  d  M  UR                  UR                  :X  d  M;  UR                  U5          g   U R                  R                  U5        SU l        g)zf
Insert a single match. Will be inserted accordingly to preserve sort.
Can be inserted as a submatch.
z-Cannot append instance '{}' to CharsetMatchesNF)r.   r   r7   rO   r/   rP   r;   rB   r   r   r1   r9   rR   rQ   r   )r!   r   matchs      r)   rQ   CharsetMatches.append-  s    
 $--?FF'  txx=++$$(8(88U[[DJJ=V&&t, ' 	T"r,   c                d    U R                   (       d  gU R                  5         U R                   S   $ )zA
Simply return the first match. Strict equivalent to matches[0].
Nr   )r   r   rH   s    r)   bestCharsetMatches.bestA  s)     }}}}Qr,   c                "    U R                  5       $ )z@
Redundant method, call the method best(). Kept for BC reasons.
)r   rH   s    r)   firstCharsetMatches.firstJ  s     yy{r,   )r   r   rU   )r   zlist[CharsetMatch] | None)r   r   )r   zIterator[CharsetMatch])r   z	int | strr   r   r   r   )r   r   r   r   )r   zCharsetMatch | None)r   r   r   r   __doc__r*   r   r   r   r   r   rQ   r   r   r   r   r,   r)   r   r     s4    
%#
!"& ( r,   r   c                  h    \ rS rSr                      SS jr\SS j5       rS	S jrSrg)
CliDetectionResultiU  c                    Xl         Xl        X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl	        Xl
        g rU   )pathunicode_pathr0   r\   alternative_encodingsrr   r   r%   r9   r:   is_preferred)r!   r   r0   r\   r   rr   r   r%   r9   r:   r   r   s               r)   r*   CliDetectionResult.__init__V  s@     	(4$,+;0E"%$-$2!
 )".r,   c                    U R                   U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  S.$ )Nr   r0   r\   r   rr   r   r%   r9   r:   r   r   r   rH   s    r)   __dict__CliDetectionResult.__dict__p  se     II $ 5 5%)%?%?"11ZZ -- --
 	
r,   c                2    SSK Jn  U" U R                  SSS9$ )Nr   )dumpsT   )ensure_asciiindent)jsonr   r   )r!   r   s     r)   to_jsonCliDetectionResult.to_json  s    T]]a@@r,   )r   r   r9   r:   r0   r\   r%   r   rr   r   r   N)r   r/   r0   r   r\   r   r   r   rr   r/   r   r   r%   r   r9   r   r:   r   r   r   r   r   )r   zdict[str, Any]r   )	r   r   r   r   r*   r   r   r   r   r   r,   r)   r   r   U  s    // / $	/
  )/ / / / / / !/ /4 
 
Ar,   r   N)
__future__r   encodings.aliasesr   rer   typingr   r   r   r	   constantr   r   utilsr   r   r   r   r   r/   r   CoherenceMatchr   r   r   r,   r)   <module>r     s^    " %  - - G C Cw wtI IX sEz"' .A .Ar,   