U ��.e�$�@s�ddlmZmZmZddlmZmZmZddlm Z m Z m Z ddl m Z mZmZddlmZmZmZGdd�de�ZGdd �d e�ZGd d �d e�ZGd d �d e�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)�)�EUCTW_CHAR_TO_FREQ_ORDER�EUCTW_TABLE_SIZE� EUCTW_TYPICAL_DISTRIBUTION_RATIO)�EUCKR_CHAR_TO_FREQ_ORDER�EUCKR_TABLE_SIZE� EUCKR_TYPICAL_DISTRIBUTION_RATIO)�GB2312_CHAR_TO_FREQ_ORDER�GB2312_TABLE_SIZE�!GB2312_TYPICAL_DISTRIBUTION_RATIO)�BIG5_CHAR_TO_FREQ_ORDER�BIG5_TABLE_SIZE�BIG5_TYPICAL_DISTRIBUTION_RATIO)�JIS_CHAR_TO_FREQ_ORDER�JIS_TABLE_SIZE�JIS_TYPICAL_DISTRIBUTION_RATIOc@sLeZdZdZdZdZdZdd�Zdd�Zd d �Z d d �Z d d�Z dd�Z dS)�CharDistributionAnalysisig�G�z��?g{�G�z�?�cCs0d|_d|_d|_d|_d|_d|_|��dS�N)�_char_to_freq_order� _table_size�typical_distribution_ratio�_done� _total_chars� _freq_chars�reset��self�r�H/usr/lib/python3.8/site-packages/pip/_vendor/chardet/chardistribution.py�__init__.sz!CharDistributionAnalysis.__init__cCsd|_d|_d|_dS)zreset analyser, clear any stateF�N)rrrrrrrr=szCharDistributionAnalysis.resetcCsX|dkr|�|�}nd}|dkrT|jd7_||jkrTd|j|krT|jd7_dS)z"feed a character with known length������r riN)� get_orderrrrr)r�charZchar_len�orderrrr�feedFs  zCharDistributionAnalysis.feedcCsT|jdks|j|jkr|jS|j|jkrN|j|j|j|j}||jkrN|S|jS)z(return confidence based on existing datar )rr�MINIMUM_DATA_THRESHOLD�SURE_NOr�SURE_YES)r�rrrr�get_confidenceTs � z'CharDistributionAnalysis.get_confidencecCs |j|jkSr)r�ENOUGH_DATA_THRESHOLDrrrr�got_enough_datadsz(CharDistributionAnalysis.got_enough_datacCsdS)Nr"r)r�byte_strrrrr#isz"CharDistributionAnalysis.get_orderN) �__name__� __module__� __qualname__r,r)r(r'rrr&r+r-r#rrrrr(s rcs$eZdZ�fdd�Zdd�Z�ZS)�EUCTWDistributionAnalysiscs$tt|���t|_t|_t|_dSr) �superr2rrrrrrrr�� __class__rrrrsz"EUCTWDistributionAnalysis.__init__cCs0|d}|dkr(d|d|ddSdSdS)Nr ���^r�r"r�rr.� first_charrrrr#xsz#EUCTWDistributionAnalysis.get_order�r/r0r1rr#� __classcell__rrr4rr2qs r2cs$eZdZ�fdd�Zdd�Z�ZS)�EUCKRDistributionAnalysiscs$tt|���t|_t|_t|_dSr) r3r=rrrrrrrrr4rrr�sz"EUCKRDistributionAnalysis.__init__cCs0|d}|dkr(d|d|ddSdSdS)Nr �r7rr8r"rr9rrrr#�sz#EUCKRDistributionAnalysis.get_orderr;rrr4rr=�s r=cs$eZdZ�fdd�Zdd�Z�ZS)�GB2312DistributionAnalysiscs$tt|���t|_t|_t|_dSr) r3r?rrrr rr rrr4rrr�sz#GB2312DistributionAnalysis.__init__cCs>|d|d}}|dkr6|dkr6d|d|dSdSdS)Nr rr>r8r7r"r�rr.r:� second_charrrrr#�sz$GB2312DistributionAnalysis.get_orderr;rrr4rr?�s r?cs$eZdZ�fdd�Zdd�Z�ZS)�Big5DistributionAnalysiscs$tt|���t|_t|_t|_dSr) r3rBrr rr rr rrr4rrr�sz!Big5DistributionAnalysis.__init__cCsX|d|d}}|dkrP|dkr:d|d|ddSd|d|dSndSdS) Nr r�r8��?�@r"rr@rrrr#�s z"Big5DistributionAnalysis.get_orderr;rrr4rrB�s rBcs$eZdZ�fdd�Zdd�Z�ZS)�SJISDistributionAnalysiscs$tt|���t|_t|_t|_dSr) r3rGrrrrrrrrr4rrr�sz!SJISDistributionAnalysis.__init__cCsr|d|d}}|dkr0|dkr0d|d}n&|dkrR|dkrRd|dd}nd S||d }|d krnd }|S) Nr r��������r"rF�r)rr.r:rAr%rrrr#�s z"SJISDistributionAnalysis.get_orderr;rrr4rrG�s rGcs$eZdZ�fdd�Zdd�Z�ZS)�EUCJPDistributionAnalysiscs$tt|���t|_t|_t|_dSr) r3rOrrrrrrrrr4rrr�sz"EUCJPDistributionAnalysis.__init__cCs0|d}|dkr(d|d|ddSdSdS)Nr �r7r8rr"r)rr.r$rrrr#�sz#EUCJPDistributionAnalysis.get_orderr;rrr4rrO�s rON)Z euctwfreqrrrZ euckrfreqrrrZ gb2312freqrr r Zbig5freqr r r Zjisfreqrrr�objectrr2r=r?rBrGrOrrrr�sI