U
    yc0'                     @   s  d dl 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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 )    )TupleUnion   )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                   @   s   e Zd ZdZdZdZdZddddZddd	d
Ze	e
ef eddddZedddZedddZe	e
ef edddZdS )CharDistributionAnalysisi   gGz?g{Gz?   Nreturnc                 C   s2   t  | _d| _d| _d| _d| _d| _|   d S )Nr   g        F)tuple_char_to_freq_order_table_sizetypical_distribution_ratio_done_total_chars_freq_charsresetself r#   C/tmp/pip-build-0we0fmvo/pip/pip/_vendor/chardet/chardistribution.py__init__@   s    z!CharDistributionAnalysis.__init__c                 C   s   d| _ d| _d| _dS )zreset analyser, clear any stateFr   N)r   r   r   r!   r#   r#   r$   r    O   s    zCharDistributionAnalysis.reset)charchar_lenr   c                 C   sX   |dkr|  |}nd}|dkrT|  jd7  _|| jk rTd| j| krT|  jd7  _dS )z"feed a character with known length   r   r   i   N)	get_orderr   r   r   r   )r"   r&   r'   orderr#   r#   r$   feedX   s    
zCharDistributionAnalysis.feedc                 C   sT   | j dks| j| jkr| jS | j | jkrN| j| j | j | j  }|| jk rN|S | jS )z(return confidence based on existing datar   )r   r   MINIMUM_DATA_THRESHOLDSURE_NOr   SURE_YES)r"   rr#   r#   r$   get_confidencef   s    
z'CharDistributionAnalysis.get_confidencec                 C   s   | j | jkS N)r   ENOUGH_DATA_THRESHOLDr!   r#   r#   r$   got_enough_dataw   s    z(CharDistributionAnalysis.got_enough_data)_r   c                 C   s   dS )Nr)   r#   )r"   r5   r#   r#   r$   r*   |   s    z"CharDistributionAnalysis.get_order)__name__
__module____qualname__r3   r/   r.   r-   r%   r    r   bytes	bytearrayintr,   floatr1   boolr4   r*   r#   r#   r#   r$   r   :   s   	r   c                       s:   e Zd Zdd fddZeeef edddZ  Z	S )EUCTWDistributionAnalysisNr   c                    s    t    t| _t| _t| _d S r2   )superr%   r   r   r   r   r   r   r!   	__class__r#   r$   r%      s    
z"EUCTWDistributionAnalysis.__init__byte_strr   c                 C   s,   |d }|dkr(d|d  |d  d S dS )Nr      ^   r      r)   r#   r"   rC   
first_charr#   r#   r$   r*      s    z#EUCTWDistributionAnalysis.get_order
r6   r7   r8   r%   r   r9   r:   r;   r*   __classcell__r#   r#   r@   r$   r>      s   r>   c                       s:   e Zd Zdd fddZeeef edddZ  Z	S )EUCKRDistributionAnalysisNr   c                    s    t    t| _t| _t| _d S r2   r?   r%   r   r   r	   r   r
   r   r!   r@   r#   r$   r%      s    
z"EUCKRDistributionAnalysis.__init__rB   c                 C   s,   |d }|dkr(d|d  |d  d S dS )Nr      rE   r   rF   r)   r#   rG   r#   r#   r$   r*      s    z#EUCKRDistributionAnalysis.get_orderrI   r#   r#   r@   r$   rK      s   rK   c                       s:   e Zd Zdd fddZeeef edddZ  Z	S )JOHABDistributionAnalysisNr   c                    s    t    t| _t| _t| _d S r2   rL   r!   r@   r#   r$   r%      s    
z"JOHABDistributionAnalysis.__init__rB   c                 C   s@   |d }d|  krdk r<n n|d |d  }t |dS dS )Nr            r   r)   )r   get)r"   rC   rH   coder#   r#   r$   r*      s
    z#JOHABDistributionAnalysis.get_orderrI   r#   r#   r@   r$   rN      s   rN   c                       s:   e Zd Zdd fddZeeef edddZ  Z	S )GB2312DistributionAnalysisNr   c                    s    t    t| _t| _t| _d S r2   )r?   r%   r   r   r   r   r   r   r!   r@   r#   r$   r%      s    
z#GB2312DistributionAnalysis.__init__rB   c                 C   s:   |d |d  }}|dkr6|dkr6d|d  | d S dS )Nr   r   rM   rF   rE   r)   r#   r"   rC   rH   second_charr#   r#   r$   r*      s    z$GB2312DistributionAnalysis.get_orderrI   r#   r#   r@   r$   rT      s   rT   c                       s:   e Zd Zdd fddZeeef edddZ  Z	S )Big5DistributionAnalysisNr   c                    s    t    t| _t| _t| _d S r2   )r?   r%   r   r   r   r   r   r   r!   r@   r#   r$   r%      s    
z!Big5DistributionAnalysis.__init__rB   c                 C   sR   |d |d  }}|dkrN|dkr:d|d  | d d S d|d  | d S dS )	Nr   r      rF      ?   @   r)   r#   rU   r#   r#   r$   r*      s    z"Big5DistributionAnalysis.get_orderrI   r#   r#   r@   r$   rW      s   rW   c                       s:   e Zd Zdd fddZeeef edddZ  Z	S )SJISDistributionAnalysisNr   c                    s    t    t| _t| _t| _d S r2   r?   r%   r   r   r   r   r   r   r!   r@   r#   r$   r%      s    
z!SJISDistributionAnalysis.__init__rB   c                 C   s   |d |d  }}d|  kr&dkr8n nd|d  }n.d|  krLdkrbn nd|d d  }nd	S || d
 }|dkr~d	}|S )Nr   r                     r)   r[      r#   )r"   rC   rH   rV   r+   r#   r#   r$   r*      s    z"SJISDistributionAnalysis.get_orderrI   r#   r#   r@   r$   r\      s   r\   c                       s:   e Zd Zdd fddZeeef edddZ  Z	S )EUCJPDistributionAnalysisNr   c                    s    t    t| _t| _t| _d S r2   r]   r!   r@   r#   r$   r%      s    
z"EUCJPDistributionAnalysis.__init__rB   c                 C   s,   |d }|dkr(d|d  |d  d S dS )Nr      rE   rF   r   r)   r#   )r"   rC   r&   r#   r#   r$   r*      s    z#EUCJPDistributionAnalysis.get_orderrI   r#   r#   r@   r$   re      s   re   N)!typingr   r   big5freqr   r   r   	euckrfreqr   r	   r
   	euctwfreqr   r   r   
gb2312freqr   r   r   jisfreqr   r   r   Z	johabfreqr   r   r>   rK   rN   rT   rW   r\   re   r#   r#   r#   r$   <module>   s   J