online
     ˆÈÇÌ438ÆÀÉ ¶    ‹      •“O�Ó0Åïû)¸%Ó´AB»ŽÑ’T¢Rÿ©„âàÄib­kWŽKX>=NS´Z±œâ$¿7~o<¦¯²Uš^OáC¾˜Ãúãûù, ~š¤ˆYž?âp!N—HãÜþ±ëº°›„ÆÖ˜o°q;cë¬,](œ ì†ößØÐ¦âÂ?�:éTÅfZTßÁlÍÁµRT1Z‹JX%%(¤×âIL#žúšÑ‹ô;nÈ‹c™~iu|ãJÖ:!Îì	£rWCkË„ ,�n±P\?†µÜàÊ%äË,]}õº¦W3Ê¡±Õ6!ïÒdy·J2Â–|WQä—™…gî	›óÖÁÎ¹••¸
?ðƒüq½`60YÕ–Vî�4úEñ<jiT»ç>ëŸ ±çÔ€ˆuƒ—¿5c}¿™.ól¶Z"úÏîþ>ÂÖÜVÚA&mU:cŸNfåk]´û»_¯p²beÝ8Â ¸Hþ‡ÿƒ~Ô¦Óç|{.šW~`•8·÷‡Ÿñh<	FQÅ½½Ç WÀI8Z\7þÂãÁÓàR<Ž=Åá*ý¿ÕžÒ­    C   ˆl–Ðz¾”Š_)%ÕÆ…p©‹Fÿ�þY ³r‚2	—Úqö�üÿÎ„O4÷Í_ŠI|¥�+Wé3ž¯ÂË :     ######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Universal charset detector code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#   Mark Pilgrim - port to Python
#   Shy Shalom - original C code
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301  USA
######################### END LICENSE BLOCK #########################
"""
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
"""


import codecs
import logging
import re
from typing import List, Optional, Union

from .charsetgroupprober import CharSetGroupProber
from .charsetprober import CharSetProber
from .enums import InputState, LanguageFilter, ProbingState
from .escprober import EscCharSetProber
from .latin1prober import Latin1Prober
from .macromanprober import MacRomanProber
from .mbcsgroupprober import MBCSGroupProber
from .resultdict import ResultDict
from .sbcsgroupprober import SBCSGroupProber
from .utf1632prober import UTF1632Prober


class UniversalDetector:
    """
    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

    """

    MINIMUM_THRESHOLD = 0.20
    HIGH_BYTE_DETECTOR = re.compile(b"[\x80-\xFF]")
    ESC_DETECTOR = re.compile(b"(\033|~{)")
    WIN_BYTE_DETECTOR = re.compile(b"[\x80-\x9F]")
    ISO_WIN_MAP = {
        "iso-8859-1": "Windows-1252",
        "iso-8859-2": "Windows-1250",
        "iso-8859-5": "Windows-1251",
        "iso-8859-6": "Windows-1256",
        "iso-8859-7": "Windows-1253",
        "iso-8859-8": "Windows-1255",
        "iso-8859-9": "Windows-1254",
        "iso-8859-13": "Windows-1257",
    }
    # Based on https://encoding.spec.whatwg.org/#names-and-labels
    # but altered to match Python names for encodings and remove mappings
    # that break tests.
    LEGACY_MAP = {
        "ascii": "Windows-1252",
        "iso-8859-1": "Windows-1252",
        "tis-620": "ISO-8859-11",
        "iso-8859-9": "Windows-1254",
        "gb2312": "GB18030",
        "euc-kr": "CP949",
        "utf-16le": "UTF-16",
    }

    def __init__(
        self,
        lang_filter: LanguageFilter = LanguageFilter.ALL,
        should_rename_legacy: bool = False,
    ) -> None:
        self._esc_charset