# Path: charset_normalizer/constant.py
# IANA_SUPPORTED = sorted(
#     filter(
#         lambda x: x.endswith("_codec") is False
#         and x not in {"rot_13", "tactis", "mbcs"},
#         list(set(aliases.values())),
#     )
# )  # type: List[str]
# 
# TOO_BIG_SEQUENCE = int(10e6)  # type: int
# 
# TOO_SMALL_SEQUENCE = 32  # type: int
# 
# TRACE = 5  # type: int
# 
# Path: charset_normalizer/md.py
# @lru_cache(maxsize=2048)
# def mess_ratio(
#     decoded_sequence: str, maximum_threshold: float = 0.2, debug: bool = False
# ) -> float:
#     """
#     Compute a mess ratio given a decoded bytes sequence. The maximum threshold does stop the computation earlier.
#     """
# 
#     detectors = [
#         md_class() for md_class in MessDetectorPlugin.__subclasses__()
#     ]  # type: List[MessDetectorPlugin]
# 
#     length = len(decoded_sequence) + 1  # type: int
# 
#     mean_mess_ratio = 0.0  # type: float
# 
#     if length < 512:
#         intermediary_mean_mess_ratio_calc = 32  # type: int
#     elif length <= 1024:
#         intermediary_mean_mess_ratio_calc = 64
#     else:
#         intermediary_mean_mess_ratio_calc = 128
# 
#     for character, index in zip(decoded_sequence + "\n", range(length)):
#         for detector in detectors:
#             if detector.eligible(character):
#                 detector.feed(character)
# 
#         if (
#             index > 0 and index % intermediary_mean_mess_ratio_calc == 0
#         ) or index == length - 1:
#             mean_mess_ratio = sum(dt.ratio for dt in detectors)
# 
#             if mean_mess_ratio >= maximum_threshold:
#                 break
# 
#     if debug:
#         for dt in detectors:  # pragma: nocover
#             print(dt.__class__, dt.ratio)
# 
#     return round(mean_mess_ratio, 3)


import logging
from os.path import basename, splitext
from typing import BinaryIO, List, Optional, Set
    from os import PathLike
from .cd import (
    coherence_ratio,
    encoding_languages,
    mb_encoding_languages,
    merge_coherence_ratios,
)
from .constant import IANA_SUPPORTED, TOO_BIG_SEQUENCE, TOO_SMALL_SEQUENCE, TRACE
from .md import mess_ratio
from .models import CharsetMatch, CharsetMatches
from .utils import (
    any_specified_encoding,
    iana_name,
    identify_sig_or_bom,
    is_cp_similar,
    is_multi_byte_encoding,
    should_strip_sig_or_bom,
)
    explain: bool = False,
) -> CharsetMatches:
    """
    Given a raw bytes sequence, return the best possibles charset usable to render str objects.
    If there is no results, it is a strong indicator that the source is binary/not text.
    By default, the process will extract 5 blocs of 512o each to assess the mess and coherence of a given sequence.
    And will give up a particular code page after 20% of measured mess. Those criteria are customizable at will.

    The preemptive behavior DOES NOT replace the traditional detection workflow, it prioritize a particular code page
    but never take it for granted. Can improve the performance.

    You may want to focus your attention to some code page or/and not others, use cp_isolation and cp_exclusion for that
    purpose.

    This function will strip the SIG in the payload/sequence every time except on UTF-16, UTF-32.
    By default the library does not setup any handler other than the NullHandler, if you choose to set the 'explain'
    toggle to True it will alter the logger configuration to add a StreamHandler that is suitable for debugging.
    Custom logging format and handler can be set manually.
    """

    if not isinstance(sequences, (bytearray, bytes)):
        raise TypeError(
            "Expected object of type bytes or bytearray, got: {0}".format(
                type(sequences)
            )
        )

    if explain:
        previous_logger_level = logger.level  # type: int
        logger.addHandler(explain_handler)

# Path: charset_normalizer/constant.py
# IANA_SUPPORTED = sorted(
#     filter(
#         lambda x: x.endswith("_codec") is False
#         and x not in {"rot_13", "tactis", "mbcs"},
#         list(set(aliases.values())),
#     )
# )  # type: List[str]
# 
# TOO_BIG_SEQUENCE = int(10e6)  # type: int
# 
# TOO_SMALL_SEQUENCE = 32  # type: int
# 
# TRACE = 5  # type: int
# 
# Path: charset_normalizer/md.py
# @lru_cache(maxsize=2048)
# def mess_ratio(
#     decoded_sequence: str, maximum_threshold: float = 0.2, debug: bool = False
# ) -> float:
#     """
#     Compute a mess ratio given a decoded bytes sequence. The maximum threshold does stop the computation earlier.
#     """
# 
#     detectors = [
#         md_class() for md_class in MessDetectorPlugin.__subclasses__()
#     ]  # type: List[MessDetectorPlugin]
# 
#     length = len(decoded_sequence) + 1  # type: int
# 
#     mean_mess_ratio = 0.0  # type: float
# 
#     if length < 512:
#         intermediary_mean_mess_ratio_calc = 32  # type: int
#     elif length <= 1024:
#         intermediary_mean_mess_ratio_calc = 64
#     else:
#         intermediary_mean_mess_ratio_calc = 128
# 
#     for character, index in zip(decoded_sequence + "\n", range(length)):
#         for detector in detectors:
#             if detector.eligible(character):
#                 detector.feed(character)
# 
#         if (
#             index > 0 and index % intermediary_mean_mess_ratio_calc == 0
#         ) or index == length - 1:
#             mean_mess_ratio = sum(dt.ratio for dt in detectors)
# 
#             if mean_mess_ratio >= maximum_threshold:
#                 break
# 
#     if debug:
#         for dt in detectors:  # pragma: nocover
#             print(dt.__class__, dt.ratio)
# 
#     return round(mean_mess_ratio, 3)


# Path: charset_normalizer/api.py
import logging
from os.path import basename, splitext
from typing import BinaryIO, List, Optional, Set
    from os import PathLike
from .cd import (
    coherence_ratio,
    encoding_languages,
    mb_encoding_languages,
    merge_coherence_ratios,
)
from .constant import IANA_SUPPORTED, TOO_BIG_SEQUENCE, TOO_SMALL_SEQUENCE, TRACE
from .md import mess_ratio
from .models import CharsetMatch, CharsetMatches
from .utils import (
    any_specified_encoding,
    iana_name,
    identify_sig_or_bom,
    is_cp_similar,
    is_multi_byte_encoding,
    should_strip_sig_or_bom,
)

    explain: bool = False,
) -> CharsetMatches:
    """
    Given a raw bytes sequence, return the best possibles charset usable to render str objects.
    If there is no results, it is a strong indicator that the source is binary/not text.
    By default, the process will extract 5 blocs of 512o each to assess the mess and coherence of a given sequence.
    And will give up a particular code page after 20% of measured mess. Those criteria are customizable at will.

    The preemptive behavior DOES NOT replace the traditional detection workflow, it prioritize a particular code page
    but never take it for granted. Can improve the performance.

    You may want to focus your attention to some code page or/and not others, use cp_isolation and cp_exclusion for that
    purpose.

    This function will strip the SIG in the payload/sequence every time except on UTF-16, UTF-32.
    By default the library does not setup any handler other than the NullHandler, if you choose to set the 'explain'
    toggle to True it will alter the logger configuration to add a StreamHandler that is suitable for debugging.
    Custom logging format and handler can be set manually.
    """

    if not isinstance(sequences, (bytearray, bytes)):
        raise TypeError(
            "Expected object of type bytes or bytearray, got: {0}".format(
                type(sequences)
            )
        )

    if explain:
        previous_logger_level = logger.level  # type: int
        logger.addHandler(explain_handler)

        logger.setLevel(TRACE)