<commit_before>"""Probe DstBytes for objects based on .bytes sections."""


import os
import numbers
import importlib
from collections import OrderedDict

from .bytes import DstBytes, BytesModel, Section, Magic, CATCH_EXCEPTIONS
from .lazy import LazySequence


do_autoload = os.environ.get("DISTANCEUTILS_AUTOLOAD", "") != "0"


class ProbeError(Exception):
    pass


class RegisterError(ValueError):
    pass


class AutoloadError(Exception):
    pass


class TagError(LookupError):
    "Given tag not found"

    def __init__(self, tag):
        LookupError.__init__(self, repr(tag))


def fragment_property(tag, name, default=None, doc=None):
    def fget(self):
        try:
            frag = self[tag]
        except KeyError as e:
            raise AttributeError(name)
        return getattr(frag, name, default)
    def fset(self, value):
        try:
            frag = self[tag]
        except KeyError as e:
            raise AttributeError(name)
        setattr(frag, name, value)
    if doc is None:
        doc = f"property forwarded to {tag!r}"
    return property(fget, fset, doc=doc)


class ClassCollector(object):

    def __init__(self, **kw):
        super().__init__(**kw)
        self._sections = {}
        self._interesting_sections = set()
        self._autoload_sections = {}
        self._classes = {}
        self._tags_by_base_key = {}

    def add_fragment(self, cls, *args,
                     any_version=False, versions=None, **kw):

        """Register a fragment.

        If additional arguments are specified, `cls` is registered for the
        `Section` specified by these arguments and the `any_version` argument.

        If there are no additional arguments and `versions` is specified,
        `cls` is registered for the given versions of the section specified<commit_msg>remove unused locals<commit_after>"""Probe DstBytes for objects based on .bytes sections."""


import os
import numbers
import importlib
from collections import OrderedDict

from .bytes import DstBytes, BytesModel, Section, Magic, CATCH_EXCEPTIONS
from .lazy import LazySequence


do_autoload = os.environ.get("DISTANCEUTILS_AUTOLOAD", "") != "0"


class ProbeError(Exception):
    pass


class RegisterError(ValueError):
    pass


class AutoloadError(Exception):
    pass


class TagError(LookupError):
    "Given tag not found"

    def __init__(self, tag):
        LookupError.__init__(self, repr(tag))


def fragment_property(tag, name, default=None, doc=None):
    def fget(self):
        try:
            frag = self[tag]
        except KeyError:
            raise AttributeError(name)
        return getattr(frag, name, default)
    def fset(self, value):
        try:
            frag = self[tag]
        except KeyError:
            raise AttributeError(name)
        setattr(frag, name, value)
    if doc is None:
        doc = f"property forwarded to {tag!r}"
    return property(fget, fset, doc=doc)


class ClassCollector(object):

    def __init__(self, **kw):
        super().__init__(**kw)
        self._sections = {}
        self._interesting_sections = set()
        self._autoload_sections = {}
        self._classes = {}
        self._tags_by_base_key = {}

    def add_fragment(self, cls, *args,
                     any_version=False, versions=None, **kw):

        """Register a fragment.

        If additional arguments are specified, `cls` is registered for the
        `Section` specified by these arguments and the `any_version` argument.

        If there are no additional arguments and `versions` is specified,
        `cls` is registered for the given versions of the section specified
{'fraction_non_alphanumeric': 0.09343226161033251, 'fraction_numerical': 0.0005496015388843089, 'mean_word_length': 2.795620437956204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2534013', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1018, 'n_words': 323}