o
    a+)h0'                     @   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Zdd	d
Zde	e
ef deddfddZdefddZdefddZde	e
ef defddZdS )CharDistributionAnalysisi   gGz?g{Gz?   returnNc                 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"   cC:\Users\User\Downloads\Proyecto_IoT\venv\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 stateFr   N)r   r   r   r    r"   r"   r#   r   O   s   
zCharDistributionAnalysis.resetcharchar_lenc                 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!   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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_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_c                 C   s   dS )Nr(   r"   )r!   r4   r"   r"   r#   r)   |   s   z"CharDistributionAnalysis.get_orderr   N)__name__
__module____qualname__r2   r.   r-   r,   r$   r   r   bytes	bytearrayintr+   floatr0   boolr3   r)   r"   r"   r"   r#   r   :   s    

	r   c                       8   e Zd Zd fddZdeeef defddZ  Z	S )	EUCTWDistributionAnalysisr   Nc                        t    t| _t| _t| _d S r1   )superr$   r   r   r   r   r   r   r    	__class__r"   r#   r$         

z"EUCTWDistributionAnalysis.__init__byte_strc                 C   ,   |d }|dkrd|d  |d  d S dS )Nr      ^   r      r(   r"   r!   rE   
first_charr"   r"   r#   r)         z#EUCTWDistributionAnalysis.get_orderr5   
r6   r7   r8   r$   r   r9   r:   r;   r)   __classcell__r"   r"   rB   r#   r?          "r?   c                       r>   )	EUCKRDistributionAnalysisr   Nc                    r@   r1   rA   r$   r   r   r	   r   r
   r   r    rB   r"   r#   r$      rD   z"EUCKRDistributionAnalysis.__init__rE   c                 C   rF   )Nr      rH   r   rI   r(   r"   rJ   r"   r"   r#   r)      rL   z#EUCKRDistributionAnalysis.get_orderr5   rM   r"   r"   rB   r#   rP      rO   rP   c                       r>   )	JOHABDistributionAnalysisr   Nc                    r@   r1   rQ   r    rB   r"   r#   r$      rD   z"JOHABDistributionAnalysis.__init__rE   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!   rE   rK   coder"   r"   r#   r)      s   z#JOHABDistributionAnalysis.get_orderr5   rM   r"   r"   rB   r#   rS      rO   rS   c                       r>   )	GB2312DistributionAnalysisr   Nc                    r@   r1   )rA   r$   r   r   r   r   r   r   r    rB   r"   r#   r$      rD   z#GB2312DistributionAnalysis.__init__rE   c                 C   s:   |d |d }}|dkr|dkrd|d  | d S dS )Nr   r   rR   rI   rH   r(   r"   r!   rE   rK   second_charr"   r"   r#   r)      s   z$GB2312DistributionAnalysis.get_orderr5   rM   r"   r"   rB   r#   rY      rO   rY   c                       r>   )	Big5DistributionAnalysisr   Nc                    r@   r1   )rA   r$   r   r   r   r   r   r   r    rB   r"   r#   r$      rD   z!Big5DistributionAnalysis.__init__rE   c                 C   sR   |d |d }}|dkr'|dkrd|d  | d d S d|d  | d S dS )	Nr   r      rI      ?   @   r(   r"   rZ   r"   r"   r#   r)      s   z"Big5DistributionAnalysis.get_orderr5   rM   r"   r"   rB   r#   r\      rO   r\   c                       r>   )	SJISDistributionAnalysisr   Nc                    r@   r1   rA   r$   r   r   r   r   r   r   r    rB   r"   r#   r$      rD   z!SJISDistributionAnalysis.__init__rE   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(   r`      r"   )r!   rE   rK   r[   r*   r"   r"   r#   r)      s   z"SJISDistributionAnalysis.get_orderr5   rM   r"   r"   rB   r#   ra      rO   ra   c                       r>   )	EUCJPDistributionAnalysisr   Nc                    r@   r1   rb   r    rB   r"   r#   r$      rD   z"EUCJPDistributionAnalysis.__init__rE   c                 C   s,   |d }|dkrd|d  |d  d S dS )Nr      rH   rI   r   r(   r"   )r!   rE   r%   r"   r"   r#   r)      rL   z#EUCJPDistributionAnalysis.get_orderr5   rM   r"   r"   rB   r#   rj      rO   rj   N)!typingr   r   big5freqr   r   r   	euckrfreqr   r	   r
   	euctwfreqr   r   r   
gb2312freqr   r   r   jisfreqr   r   r   	johabfreqr   r   r?   rP   rS   rY   r\   ra   rj   r"   r"   r"   r#   <module>   s   J