Hacked By AnonymousFox

Current Path : /usr/lib/python3.6/site-packages/chardet/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/chardet/__pycache__/universaldetector.cpython-36.pyc

3

`9Y�0�@s�dZddlZddlZddlZddlmZddlmZmZm	Z	ddl
mZddlm
Z
ddlmZdd	lmZGd
d�de�ZdS)a
Module containing the UniversalDetector detector class, which is the primary
class a user of ``chardet`` should use.

:author: Mark Pilgrim (initial port to Python)
:author: Shy Shalom (original C code)
:author: Dan Blanchard (major refactoring for 3.0)
:author: Ian Cordasco
�N�)�CharSetGroupProber)�
InputState�LanguageFilter�ProbingState)�EscCharSetProber)�Latin1Prober)�MBCSGroupProber)�SBCSGroupProberc	@sneZdZdZdZejd�Zejd�Zejd�Z	dddd	d
ddd
d�Z
ejfdd�Z
dd�Zdd�Zdd�ZdS)�UniversalDetectoraq
    The ``UniversalDetector`` class underlies the ``chardet.detect`` function
    and coordinates all of the different charset probers.

    To get a ``dict`` containing an encoding and its confidence, you can simply
    run:

    .. code::

            u = UniversalDetector()
            u.feed(some_bytes)
            u.close()
            detected = u.result

    g�������?s[�-�]s(|~{)s[�-�]zWindows-1252zWindows-1250zWindows-1251zWindows-1256zWindows-1253zWindows-1255zWindows-1254zWindows-1257)z
iso-8859-1z
iso-8859-2z
iso-8859-5z
iso-8859-6z
iso-8859-7z
iso-8859-8z
iso-8859-9ziso-8859-13cCsNd|_g|_d|_d|_d|_d|_d|_||_tj	t
�|_d|_|j
�dS)N)�_esc_charset_prober�_charset_probers�result�done�	_got_data�_input_state�
_last_char�lang_filter�loggingZ	getLogger�__name__�logger�_has_win_bytes�reset)�selfr�r�'/usr/lib/python3.6/universaldetector.py�__init__QszUniversalDetector.__init__cCsZdddd�|_d|_d|_d|_tj|_d|_|jr>|jj	�x|j
D]}|j	�qFWdS)z�
        Reset the UniversalDetector and all of its probers back to their
        initial states.  This is called by ``__init__``, so you only need to
        call this directly in between analyses of different documents.
        Ng)�encoding�
confidence�languageF�)rrrrr�
PURE_ASCIIrrrrr
)r�proberrrrr^s
zUniversalDetector.resetcCs>|jr
dSt|�sdSt|t�s(t|�}|js�|jtj�rJdddd�|_nv|jtj	tj
f�rldddd�|_nT|jd�r�dddd�|_n:|jd	�r�d
ddd�|_n |jtjtjf�r�dddd�|_d|_|jd
dk	r�d|_dS|j
tjk�r.|jj|��rtj|_
n*|j
tjk�r.|jj|j|��r.tj|_
|dd�|_|j
tjk�r�|j�s^t|j�|_|jj|�tjk�r:|jj|jj�|jjd�|_d|_n�|j
tjk�r:|j�s�t |j�g|_|jt!j"@�r�|jj#t$��|jj#t%��x@|jD]6}|j|�tjk�r�|j|j�|jd�|_d|_P�q�W|j&j|��r:d|_'dS)a�
        Takes a chunk of a document and feeds it through all of the relevant
        charset probers.

        After calling ``feed``, you can check the value of the ``done``
        attribute to see if you need to continue feeding the
        ``UniversalDetector`` more data, or if it has made a prediction
        (in the ``result`` attribute).

        .. note::
           You should always call ``close`` when you're done feeding in your
           document if ``done`` is not already ``True``.
        Nz	UTF-8-SIGg�?�)rrrzUTF-32s��zX-ISO-10646-UCS-4-3412s��zX-ISO-10646-UCS-4-2143zUTF-16Trr���)(r�len�
isinstance�	bytearrayr�
startswith�codecs�BOM_UTF8r�BOM_UTF32_LE�BOM_UTF32_BE�BOM_LE�BOM_BErrr!�HIGH_BYTE_DETECTOR�search�	HIGH_BYTE�ESC_DETECTORrZ	ESC_ASCIIrrr�feedrZFOUND_IT�charset_name�get_confidencerr
r	rZNON_CJK�appendr
r�WIN_BYTE_DETECTORr)rZbyte_strr"rrrr3os|





zUniversalDetector.feedc	Cs�|jr|jSd|_|js&|jjd�n�|jtjkrBdddd�|_n�|jtjkr�d}d}d}x,|j	D]"}|slqb|j
�}||krb|}|}qbW|r�||jkr�|j}|jj
�}|j
�}|jd	�r�|jr�|jj||�}|||jd�|_|jj�tjk�rz|jd
dk�rz|jjd�xn|j	D]d}|�s �qt|t��rZxF|jD] }|jjd|j|j|j
���q4Wn|jjd|j|j|j
���qW|jS)
z�
        Stop analyzing the current document and come up with a final
        prediction.

        :returns:  The ``result`` attribute, a ``dict`` with the keys
                   `encoding`, `confidence`, and `language`.
        Tzno data received!�asciig�?r#)rrrNgziso-8859rz no probers hit minimum thresholdz%s %s confidence = %s)rrrr�debugrrr!r1r
r5�MINIMUM_THRESHOLDr4�lowerr(r�ISO_WIN_MAP�getrZgetEffectiveLevelr�DEBUGr&rZprobers)	rZprober_confidenceZmax_prober_confidenceZ
max_proberr"r4Zlower_charset_namerZgroup_proberrrr�close�s`	

zUniversalDetector.closeN)r�
__module__�__qualname__�__doc__r:�re�compiler/r2r7r<rZALLrrr3r?rrrrr3s"



mr)rBr)rrCZcharsetgroupproberrZenumsrrrZ	escproberrZlatin1proberrZmbcsgroupproberr	Zsbcsgroupproberr
�objectrrrrr�<module>$s

Hacked By AnonymousFox1.0, Coded By AnonymousFox