o
     ѹg.                     @  sr  d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d	d
lmZmZmZmZmZmZ e
eddgddZe
eddhddZe
eddiddZe
eddgddZe
eddgddZe
eddgddZe
eddgddZe
eddgdd Ze
eddgd!d"Z e
eddgd#d$Z!e
eddgd%d&Z"e
eddgd'd(Z#e
eddgd)d*Z$e
eddgd+d,Z%e
eddgd-d.Z&e
eddgd/d0Z'e
e(eddjd2d3Z)e
eddgd4d5Z*dkdld;d<Z+e
d=ddmd?d@Z,dndBdCZ-dodEdFZ.dpdqdJdKZ/drdOdPZ0dsdQdRZ1dSej2dTfdtdXdYZ3	dudvdedfZ4dS )w    )annotationsN)IncrementalDecoder)aliases)	lru_cache)findall)	Generator)MultibyteIncrementalDecoder   )ENCODING_MARKSIANA_SUPPORTED_SIMILARRE_POSSIBLE_ENCODING_INDICATIONUNICODE_RANGES_COMBINEDUNICODE_SECONDARY_RANGE_KEYWORDUTF8_MAXIMAL_ALLOCATION)maxsize	characterstrreturnboolc                 C  sd   zt | }W n
 ty   Y dS w d|v p1d|v p1d|v p1d|v p1d|v p1d|v p1d|v p1d	|v S )
NFz
WITH GRAVEz
WITH ACUTEzWITH CEDILLAzWITH DIAERESISzWITH CIRCUMFLEXz
WITH TILDEzWITH MACRONzWITH RING ABOVEunicodedataname
ValueErrorr   description r   \/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/site-packages/charset_normalizer/utils.pyis_accentuated   s(   r   c                 C  s.   t | }|s	| S |d}tt|d dS )N r      )r   decompositionsplitchrint)r   Z
decomposedcodesr   r   r   remove_accent,   s
   

r%   
str | Nonec                 C  s.   t | }t D ]\}}||v r|  S qdS )zK
    Retrieve the Unicode range official name from a single character.
    N)ordr   items)r   Zcharacter_ord
range_nameZ	ord_ranger   r   r   unicode_range7   s   r*   c                 C  *   z
t | }W d|v S  ty   Y dS w )NFZLATINr   r   r   r   r   is_latinE   s   r,   c                 C  s2   t | }d|v rdS t| }|d u rdS d|v S )NPTFZPunctuationr   categoryr*   r   character_categorycharacter_ranger   r   r   is_punctuationN   s   
r3   c                 C  sB   t | }d|v sd|v rdS t| }|d u rdS d|v o |dkS )NSNTFZFormsZLor.   r0   r   r   r   	is_symbol]   s   
r6   c                 C  s$   t | }|d u r
dS d|v pd|v S )NFZ	EmoticonsZPictographs)r*   )r   r2   r   r   r   is_emoticonl   s   r7   c                 C  s.   |   s| dv r
dS t| }d|v p|dv S )N>   >u   ｜+<TZ>   ZPoZPdZPc)isspacer   r/   )r   r1   r   r   r   is_separatorv   s   
r=   c                 C  s   |   |  kS N)islowerisupperr   r   r   r   is_case_variable   s   rB   c                 C  r+   )NFCJKr   r   Zcharacter_namer   r   r   is_cjk      rE   c                 C  r+   )NFZHIRAGANAr   rD   r   r   r   is_hiragana   rF   rG   c                 C  r+   )NFZKATAKANAr   rD   r   r   r   is_katakana   rF   rH   c                 C  r+   )NFZHANGULr   rD   r   r   r   	is_hangul   rF   rI   c                 C  r+   )NFZTHAIr   rD   r   r   r   is_thai   rF   rJ   c                 C  r+   )NFARABICr   rD   r   r   r   	is_arabic   rF   rL   c                 C  s4   zt | }W n
 ty   Y dS w d|v od|v S )NFrK   zISOLATED FORMr   rD   r   r   r   is_arabic_isolated_form   s   rM   r)   c                   s   t  fddtD S )Nc                 3  s    | ]}| v V  qd S r>   r   ).0keywordr)   r   r   	<genexpr>   s    z-is_unicode_range_secondary.<locals>.<genexpr>)anyr   rP   r   rP   r   is_unicode_range_secondary   s   rS   c                 C  s(   |   du o|  du o| dko| dkS )NFu   ﻿)r<   isprintablerA   r   r   r   is_unprintable   s   
rV       sequencebytessearch_zoner#   c                 C  s   t | tstt| }tt| dt|| jddd}t|dkr$dS |D ]'}| 	dd}t
 D ]\}}||krB|    S ||krL|    S q4q&dS )zW
    Extract using ASCII-only decoder any specified encoding in the first n-bytes.
    Nasciiignoreerrorsr   -_)
isinstancerY   	TypeErrorlenr   r   mindecodelowerreplacer   r(   )rX   rZ   Zseq_lenresultsZspecified_encodingencoding_aliasencoding_ianar   r   r   any_specified_encoding   s&   
rk      r   c                 C  s    | dv pt td|  jtS )zQ
    Verify is a specific encoding is a multi byte one based on it IANA name
    >	   utf_16	utf_32_beutf_7utf_32utf_8	utf_32_le	utf_16_be	utf_16_leZ	utf_8_sig
encodings.N)
issubclass	importlibimport_moduler   r   )r   r   r   r   is_multi_byte_encoding   s   
ry   tuple[str | None, bytes]c                 C  sJ   t D ] }t | }t|tr|g}|D ]}| |r!||f    S qqdS )z9
    Identify and extract SIG/BOM in given sequence.
    )N    N)r
   ra   rY   
startswith)rX   iana_encodingZmarksmarkr   r   r   identify_sig_or_bom  s   

r   r}   c                 C  s   | dvS )N>   rm   rp   r   )r}   r   r   r   should_strip_sig_or_bom"  s   r   Tcp_namestrictc                 C  sN   |   dd} t D ]\}}| ||fv r|  S q|r%td|  d| S )zIReturns the Python normalized encoding name (Not the IANA official name).r_   r`   zUnable to retrieve IANA for ''N)rf   rg   r   r(   r   )r   r   ri   rj   r   r   r   	iana_name&  s   r   iana_name_aiana_name_bfloatc           	      C  s   t | st |r
dS td|  j}td| j}|dd}|dd}d}tdD ]}t|g}||||krA|d7 }q,|d S )	Ng        ru   r\   r]   r      r	      )ry   rw   rx   r   rangerY   re   )	r   r   Z	decoder_aZ	decoder_bZid_aZid_bZcharacter_match_countiZto_be_decodedr   r   r   cp_similarity7  s   


r   c                 C  s   | t v o	|t |  v S )z
    Determine if two code page are at least 80% similar. IANA_SUPPORTED_SIMILAR dict was generated using
    the function cp_similarity.
    N)r   )r   r   r   r   r   is_cp_similarK  s   
r   Zcharset_normalizerz)%(asctime)s | %(levelname)s | %(message)slevelformat_stringNonec                 C  s:   t | }|| t  }|t | || d S r>   )logging	getLoggersetLevelStreamHandlersetFormatter	Formatter
addHandler)r   r   r   loggerhandlerr   r   r   set_logging_handlerV  s
   

r   	sequencesrj   offsetsr   
chunk_sizebom_or_sig_availablestrip_sig_or_bomsig_payloadis_multi_byte_decoderdecoded_payloadGenerator[str, None, None]c	                 c  s&   |r|du r|D ]}	||	|	|  }
|
s d S |
V  q	d S |D ]p}	|	| }|t | d kr/q | |	|	|  }|rA|du rA|| }|j||rHdndd}
|r|	dkrt|d}|r|
d | |vrt|	|	d d	D ]#}| || }|r{|du r{|| }|j|dd}
|
d | |v r qqi|
V  q d S )
NF   r\   r   r]   r   r      )rc   re   rd   r   )r   rj   r   r   r   r   r   r   r   r   chunkZ	chunk_endZcut_sequenceZchunk_partial_size_chkjr   r   r   cut_sequence_chunksc  sF   

r   )r   r   r   r   )r   r   r   r   )r   r   r   r&   )r)   r   r   r   )rW   )rX   rY   rZ   r#   r   r&   )r   r   r   r   )rX   rY   r   rz   )r}   r   r   r   )T)r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r#   r   r   r   r   r>   )r   rY   rj   r   r   r   r   r#   r   r   r   r   r   rY   r   r   r   r&   r   r   )5
__future__r   rw   r   r   codecsr   Zencodings.aliasesr   	functoolsr   rer   typingr   Z_multibytecodecr   Zconstantr
   r   r   r   r   r   r   r%   r*   r,   r3   r6   r7   r=   rB   rE   rG   rH   rI   rJ   rL   rM   rc   rS   rV   rk   ry   r   r   r   r   r   INFOr   r   r   r   r   r   <module>   sz     

									
 



