o
    Oc%                     @   s   d dl mZmZmZ d dlmZmZmZ d dlm	Z	m
Z
mZ d dlmZmZmZ d dlmZmZmZ d dlmZ G dd dZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )   )BIG5_CHAR_TO_FREQ_ORDERBIG5_TABLE_SIZEBIG5_TYPICAL_DISTRIBUTION_RATIO)EUCKR_CHAR_TO_FREQ_ORDEREUCKR_TABLE_SIZE EUCKR_TYPICAL_DISTRIBUTION_RATIO)EUCTW_CHAR_TO_FREQ_ORDEREUCTW_TABLE_SIZE EUCTW_TYPICAL_DISTRIBUTION_RATIO)GB2312_CHAR_TO_FREQ_ORDERGB2312_TABLE_SIZE!GB2312_TYPICAL_DISTRIBUTION_RATIO)JIS_CHAR_TO_FREQ_ORDERJIS_TABLE_SIZEJIS_TYPICAL_DISTRIBUTION_RATIO)JOHAB_TO_EUCKR_ORDER_TABLEc                   @   sL   e Zd ZdZdZdZdZdd Zdd Zd	d
 Z	dd Z
dd Zdd ZdS )CharDistributionAnalysisi   gGz?g{Gz?   c                 C   s2   t  | _d | _d | _d | _d | _d | _|   d S N)tuple_char_to_freq_order_table_sizetypical_distribution_ratio_done_total_chars_freq_charsresetself r   FD:\Flask\env\lib\site-packages\pip\_vendor\chardet\chardistribution.py__init__>   s   z!CharDistributionAnalysis.__init__c                 C   s   d| _ d| _d| _dS )zreset analyser, clear any stateF    N)r   r   r   r   r   r   r    r   M   s   
zCharDistributionAnalysis.resetc                 C   sd   |dkr
|  |}nd}|dkr,|  jd7  _|| jk r.d| j| kr0|  jd7  _dS dS dS dS )z"feed a character with known length   r"   r   i   N)	get_orderr   r   r   r   )r   charZchar_lenorderr   r   r    feedV   s   
zCharDistributionAnalysis.feedc                 C   sT   | j dks| j| jkr| jS | j | jkr'| j| j | j | j  }|| jk r'|S | jS )z(return confidence based on existing datar"   )r   r   MINIMUM_DATA_THRESHOLDSURE_NOr   SURE_YES)r   rr   r   r    get_confidenced   s   
z'CharDistributionAnalysis.get_confidencec                 C   s   | j | jkS r   )r   ENOUGH_DATA_THRESHOLDr   r   r   r    got_enough_datau   s   z(CharDistributionAnalysis.got_enough_datac                 C   s   dS )Nr$   r   )r   _r   r   r    r%   z   s   z"CharDistributionAnalysis.get_orderN)__name__
__module____qualname__r.   r+   r*   r)   r!   r   r(   r-   r/   r%   r   r   r   r    r   8   s    	r   c                       $   e Zd Z fddZdd Z  ZS )EUCTWDistributionAnalysisc                        t    t| _t| _t| _d S r   )superr!   r   r   r	   r   r
   r   r   	__class__r   r    r!         

z"EUCTWDistributionAnalysis.__init__c                 C   ,   |d }|dkrd|d  |d  d S dS )Nr"      ^   r      r$   r   r   byte_str
first_charr   r   r    r%         z#EUCTWDistributionAnalysis.get_orderr1   r2   r3   r!   r%   __classcell__r   r   r8   r    r5          r5   c                       r4   )EUCKRDistributionAnalysisc                    r6   r   r7   r!   r   r   r   r   r   r   r   r8   r   r    r!      r:   z"EUCKRDistributionAnalysis.__init__c                 C   r;   )Nr"      r=   r   r>   r$   r   r?   r   r   r    r%      rB   z#EUCKRDistributionAnalysis.get_orderrC   r   r   r8   r    rF      rE   rF   c                       r4   )JOHABDistributionAnalysisc                    r6   r   rG   r   r8   r   r    r!      r:   z"JOHABDistributionAnalysis.__init__c                 C   sB   |d }d|  krdk rn dS |d |d  }t |dS dS )Nr"            r   r$   )r   get)r   r@   rA   coder   r   r    r%      s   z#JOHABDistributionAnalysis.get_orderrC   r   r   r8   r    rI      rE   rI   c                       r4   )GB2312DistributionAnalysisc                    r6   r   )r7   r!   r   r   r   r   r   r   r   r8   r   r    r!      r:   z#GB2312DistributionAnalysis.__init__c                 C   s:   |d |d }}|dkr|dkrd|d  | d S dS )Nr"   r   rH   r>   r=   r$   r   r   r@   rA   second_charr   r   r    r%      s   z$GB2312DistributionAnalysis.get_orderrC   r   r   r8   r    rO      rE   rO   c                       r4   )Big5DistributionAnalysisc                    r6   r   )r7   r!   r   r   r   r   r   r   r   r8   r   r    r!      r:   z!Big5DistributionAnalysis.__init__c                 C   sR   |d |d }}|dkr'|dkrd|d  | d d S d|d  | d S dS )	Nr"   r      r>      ?   @   r$   r   rP   r   r   r    r%      s   z"Big5DistributionAnalysis.get_orderrC   r   r   r8   r    rR      rE   rR   c                       r4   )SJISDistributionAnalysisc                    r6   r   r7   r!   r   r   r   r   r   r   r   r8   r   r    r!      r:   z!SJISDistributionAnalysis.__init__c                 C   s   |d |d }}d|  krdkrn nd|d  }nd|  kr&dkr2n d	S d|d d  }nd	S || d
 }|dkr@d	}|S )Nr"   r                     r$   rV      r   )r   r@   rA   rQ   r'   r   r   r    r%      s   z"SJISDistributionAnalysis.get_orderrC   r   r   r8   r    rW      rE   rW   c                       r4   )EUCJPDistributionAnalysisc                    r6   r   rX   r   r8   r   r    r!      r:   z"EUCJPDistributionAnalysis.__init__c                 C   s,   |d }|dkrd|d  |d  d S dS )Nr"      r=   r>   r   r$   r   )r   r@   r&   r   r   r    r%      rB   z#EUCJPDistributionAnalysis.get_orderrC   r   r   r8   r    r`      rE   r`   N)Zbig5freqr   r   r   Z	euckrfreqr   r   r   Z	euctwfreqr   r	   r
   Z
gb2312freqr   r   r   Zjisfreqr   r   r   Z	johabfreqr   r   r5   rF   rI   rO   rR   rW   r`   r   r   r   r    <module>   s   J