Viewing File: /opt/alt/python35/lib/python3.5/site-packages/chardet/__pycache__/universaldetector.cpython-35.pyc



<_9Y0@sdZddlZddlZddlZddlmZddlmZmZm	Z	ddl
mZddlm
Z
ddlmZdd	lmZGd
ddeZdS)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)
InputStateLanguageFilterProbingState)EscCharSetProber)Latin1Prober)MBCSGroupProber)SBCSGroupProberc@seZdZdZdZejdZejdZejdZ	dddd	d
ddd
ddddddddiZ
ejddZ
ddZddZddZdS)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
iso-8859-1zWindows-1252z
iso-8859-2zWindows-1250z
iso-8859-5zWindows-1251z
iso-8859-6zWindows-1256z
iso-8859-7zWindows-1253z
iso-8859-8zWindows-1255z
iso-8859-9zWindows-1254ziso-8859-13zWindows-1257cCsqd|_g|_d|_d|_d|_d|_d|_||_tj	t
|_d|_|j
dS)N)_esc_charset_prober_charset_probersresultdone	_got_data_input_state
_last_charlang_filterlogging	getLogger__name__logger_has_win_bytesreset)selfrr/universaldetector.py__init__Qs									zUniversalDetector.__init__cCsddddddi|_d|_d|_d|_tj|_d|_|jra|jj	x|j
D]}|j	qkWdS)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.
        encodingN
confidenceglanguageF)rrrrr
PURE_ASCIIrrrrr
)rproberrrrr^s					
zUniversalDetector.resetcCsF|jr
dSt|sdSt|ts8t|}|jsc|jtjrqddddddi|_n|jtj	tj
frddddddi|_n|jd	rdd
ddddi|_nc|jdrddddddi|_n6|jtjtjfr:dd
ddddi|_d|_|jddk	rcd|_dS|j
tjkr|jj|rtj|_
n7|j
tjkr|jj|j|rtj|_
|dd|_|j
tjkrd|js
t|j|_|jj|tjkrBd|jjd|jjd|jji|_d|_n|j
tjkrB|jst |jg|_|jt!j"@r|jj#t$|jj#t%xZ|jD]O}|j|tjkrd|jd|jd|ji|_d|_PqW|j&j|rBd|_'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``.
        Nrz	UTF-8-SIGrg?r zUTF-32szX-ISO-10646-UCS-4-3412szX-ISO-10646-UCS-4-2143zUTF-16Tr)(rlen
isinstance	bytearrayr
startswithcodecsBOM_UTF8rBOM_UTF32_LEBOM_UTF32_BEBOM_LEBOM_BErrr"HIGH_BYTE_DETECTORsearch	HIGH_BYTEESC_DETECTORrZ	ESC_ASCIIrrrfeedrZFOUND_ITcharset_nameget_confidencer r
r	rZNON_CJKappendr
rWIN_BYTE_DETECTORr)rZbyte_strr#rrrr4os									zUniversalDetector.feedc	Cs|jr|jSd|_|js5|jjdn|jtjkreddddddi|_n|jtjkrNd	}d
}d	}x>|j	D]3}|sq|j
}||kr|}|}qW|rN||jkrN|j}|jj
}|j
}|jdr0|jr0|jj||}d|d|d|ji|_|jjtjkr|jdd	kr|jjdx|j	D]}|sqt|trx^|jD]+}|jjd
|j|j|j
qWq|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!rasciirg?r r$Ngziso-8859z no probers hit minimum thresholdz%s %s confidence = %s)rrrrdebugrrr"r2r
r6MINIMUM_THRESHOLDr5lowerr)rISO_WIN_MAPgetr getEffectiveLevelrDEBUGr'rZprobers)	rZprober_confidenceZmax_prober_confidenceZ
max_proberr#r5Zlower_charset_namerZgroup_proberrrrcloses`				
			zUniversalDetector.closeN)r
__module____qualname____doc__r;recompiler0r3r8r=rZALLrrr4rArrrrr3s"
mr)rDr*rrEZcharsetgroupproberrZenumsrrrZ	escproberrZlatin1proberrZmbcsgroupproberr	Zsbcsgroupproberr
objectrrrrr<module>$s
Back to Directory File Manager