o
    n~b\$                  	   @   sj  zd dl ZW n ey   d dlZY nw 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mZmZmZ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
dedefddZe
ed
dedefddZe
ed
dedee fddZ e
ed
dedefddZ!dedefddZ"e
ed
dedefddZ#e
ed
dedefddZ$e
ed
dedefddZ%e
ed
dedefddZ&e
ed
dedefdd Z'dedefd!d"Z(e
ed
dedefd#d$Z)e
ed
dedefd%d&Z*e
ed
dedefd'd(Z+e
ed
dedefd)d*Z,e
ed
dedefd+d,Z-e
e.ed
d-edefd.d/Z/dRd1e0d2e1dee fd3d4Z2e
d5d
d6edefd7d8Z3d1e0deee e0f fd9d:Z4d;edefd<d=Z5dSd?ed@edefdAdBZ6dCedee fdDdEZ7dFedGede8fdHdIZ9dFedGedefdJdKZ:dLej;dMfd6edNe1dOeddfdPdQZ<dS )T    N)IncrementalDecoder)aliases)	lru_cache)findall)ListOptionalSetTupleUnion)MultibyteIncrementalDecoder   )ENCODING_MARKSIANA_SUPPORTED_SIMILARRE_POSSIBLE_ENCODING_INDICATIONUNICODE_RANGES_COMBINEDUNICODE_SECONDARY_RANGE_KEYWORDUTF8_MAXIMAL_ALLOCATION)maxsize	characterreturnc                 C   sT   zt | }W n
 ty   Y dS w d|v p)d|v p)d|v p)d|v p)d|v p)d|v S )NFz
WITH GRAVEz
WITH ACUTEzWITH CEDILLAzWITH DIAERESISzWITH CIRCUMFLEXz
WITH TILDEunicodedataname
ValueErrorr   description r   C/usr/local/lib/python3.10/dist-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&   c                 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_range5   s   r*   c                 C   *   z
t | }W d|v S  ty   Y dS w )NFZLATINr   r   r   r   r   is_latinC   s   r,   c                 C   s&   z|  d W dS  ty   Y dS w )NasciiFT)encodeUnicodeEncodeErrorr   r   r   r   is_asciiL   s   r1   c                 C   s2   t | }d|v rdS t| }|d u rdS d|v S )NPTFPunctuationr   categoryr*   r   character_categorycharacter_ranger   r   r   is_punctuationT   s   
r9   c                 C   s:   t | }d|v sd|v rdS t| }|d u rdS d|v S )NSNTFZFormsr4   r6   r   r   r   	is_symbolc   s   
r<   c                 C   s   t | }|d u r
dS d|v S )NFZ	Emoticons)r*   )r   r8   r   r   r   is_emoticonr   s   r=   c                 C   s&   |   s| dv r
dS t| }d|v S )N>      ｜+,;<>TZ)isspacer   r5   r   r7   r   r   r   is_separator|   s   
rG   c                 C   s   |   |  kS N)islowerisupperr0   r   r   r   is_case_variable   s   rK   c                 C   s   t | }|dkS )NCo)r   r5   rF   r   r   r   is_private_use_only   s   
rM   c                 C   r+   )NFCJKr   r   Zcharacter_namer   r   r   is_cjk      rP   c                 C   r+   )NFZHIRAGANAr   rO   r   r   r   is_hiragana   rQ   rR   c                 C   r+   )NFZKATAKANAr   rO   r   r   r   is_katakana   rQ   rS   c                 C   r+   )NFZHANGULr   rO   r   r   r   	is_hangul   rQ   rT   c                 C   r+   )NFZTHAIr   rO   r   r   r   is_thai   rQ   rU   r)   c                    s   t  fddtD S )Nc                 3   s    | ]}| v V  qd S rH   r   ).0keywordr)   r   r   	<genexpr>   s    z-is_unicode_range_secondary.<locals>.<genexpr>)anyr   rX   r   rX   r   is_unicode_range_secondary   s   r[      sequencesearch_zonec                 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.
    Nr-   ignoreerrorsr   -_)
isinstancebytes	TypeErrorlenr   r   mindecodelowerreplacer   r(   )r]   r^   Zseq_lenresultsZspecified_encodingencoding_aliasencoding_ianar   r   r   any_specified_encoding   s&   
ro      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_8_sigutf_7utf_8utf_16utf_32	utf_16_be	utf_16_le	utf_32_be	utf_32_leencodings.{})
issubclass	importlibimport_moduleformatr   r   )r   r   r   r   is_multi_byte_encoding   s   
r   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    )r   rd   re   
startswith)r]   iana_encodingZmarksmarkr   r   r   identify_sig_or_bom   s   

r   r   c                 C   s   | dvS )N>   rt   ru   r   )r   r   r   r   should_strip_sig_or_bom  s   r   Tcp_namestrictc                 C   sL   |   dd} t D ]\}}| ||fv r|  S q|r$td| | S )Nrb   rc   z Unable to retrieve IANA for '{}')rj   rk   r   r(   r   r~   )r   r   rm   rn   r   r   r   	iana_name  s   r   decoded_sequencec                 C   s4   t  }| D ]}t|}|d u rq|| qt|S rH   )setr*   addlist)r   rangesr   r8   r   r   r   
range_scan  s   r   iana_name_aiana_name_bc           	      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        rz   r_   r`   r      r      )r   r|   r}   r~   r   rangere   ri   )	r   r   Z	decoder_aZ	decoder_bZid_aZid_bZcharacter_match_countiZto_be_decodedr   r   r   cp_similarity+  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.
    )r   )r   r   r   r   r   is_cp_similar@  s   
r   Zcharset_normalizerz)%(asctime)s | %(levelname)s | %(message)slevelformat_stringc                 C   s:   t | }|| t  }|t | || d S rH   )logging	getLoggersetLevelStreamHandlersetFormatter	Formatter
addHandler)r   r   r   loggerhandlerr   r   r   set_logging_handlerK  s
   

r   )r\   )T)=Zunicodedata2r   ImportErrorr|   r   codecsr   Zencodings.aliasesr   	functoolsr   rer   typingr   r   r   r	   r
   Z_multibytecodecr   Zconstantr   r   r   r   r   r   strboolr   r&   r*   r,   r1   r9   r<   r=   rG   rK   rM   rP   rR   rS   rT   rU   rg   r[   re   r$   ro   r   r   r   r   r   floatr   r   INFOr   r   r   r   r   <module>   s     

							