U ʗRe3 @ s d Z ddlZddlZddlZddlmZ ddlmZmZm Z ddl mZ ddlm Z ddlmZ dd lmZ dd lmZ G dd dZdS ) 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) InputStateLanguageFilterProbingState)EscCharSetProber)Latin1Prober)MBCSGroupProber)SBCSGroupProber) UTF1632Proberc @ s e Zd ZdZdZedZedZedZ dddd d ddd dZ ejfddZ edd Zedd Zedd Zdd 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 [-]zWindows-1252zWindows-1250zWindows-1251zWindows-1256zWindows-1253zWindows-1255zWindows-1254zWindows-1257)z iso-8859-1z iso-8859-2z iso-8859-5z iso-8859-6z iso-8859-7z iso-8859-8z iso-8859-9ziso-8859-13c C sT d | _ d | _g | _d | _d | _d | _d | _d | _|| _t t| _d | _ | d S N)_esc_charset_prober_utf1632_prober_charset_probersresultdone _got_data_input_state _last_charlang_filterlogging getLogger__name__logger_has_win_bytesreset)selfr r /builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/chardet/universaldetector.py__init__T s zUniversalDetector.__init__c C s | j S r )r r r r r input_stateb s zUniversalDetector.input_statec C s | j S r )r r! r r r has_win_bytesf s zUniversalDetector.has_win_bytesc C s | j S r )r r! r r r charset_probersj s z!UniversalDetector.charset_probersc C sf dddd| _ d| _d| _d| _tj| _d| _| jr>| j | j rN| j | jD ]}| qTdS )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. N encoding confidencelanguageF )r r r r r PURE_ASCIIr r r r r r )r proberr r r r n s zUniversalDetector.resetc C s | j r dS |sdS t|ts$t|}| js|tjrFdddd| _nv|tjtj frhdddd| _nT|drdddd| _n:|d rd ddd| _n |tj tjfrdddd| _d| _| jd dk rd| _ dS | jt jkr(| j|rt j| _n*| jt jkr(| j| j| r(t j| _|dd | _| jsFt | _| jjtjkr| j|tjkr| jj| j dd| _d| _ dS | jt jkr| jst| j | _| j|tjkr| jj| j | jj!d| _d| _ n| jt jkr| j"s4t#| j g| _"| j t$j%@ r&| j"&t' | j"&t( | j"D ]:}||tjkr:|j| |j!d| _d| _ qvq:| j)|rd| _*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-SIG ? r&