<commit_before>"""
Misc stuff. --Eldar
"""

import functools as _functools

from .collections import Mapping as _Mapping
from .collections import namedtuple as _namedtuple

from .compat import *


def identity(x):
    return x


class cached_property(object):
    """Non-data descriptor."""
    __slots__ = 'func'

    def __init__(self, func):
        super(cached_property, self).__init__()
        self.func = func

    def __get__(self, obj, objtype=None):
        if obj is None:
            return self
        func = self.func
        ret = func(obj)
        setattr(obj, func.__name__, ret)
        return ret


class intercepting_property(property):
    """Data descriptor."""
    __slots__ = 'name'

    def __init__(self, fget=None, fset=None, fdel=None, name=None, doc=None):
        func = fget or fset or fdel

        if name is None:
            if func is not None:
                name = func.__name__
            else:
                raise TypeError('no attribute name given')

        super(intercepting_property, self).__init__(fget, fset, fdel, doc)

    def __get__(self, obj, objtype=None):
        if obj is None:
            return self
        try:
            ret = obj.__dict__[self.name]
        except KeyError:
            raise AttributeError
        fget = self.fget
        if fget is not None:
            ret = fget(obj, ret)
        return ret

    def __set__(self, obj, value):
        fset = self.fset
        if fset is not None:
            value = fset(obj, value)
        obj.__dict__[self.name] = value

    def __delete__(self, obj):
        fdel = self.fdel
        if fdel is not None:
            fdel(obj)
        try:
            del obj.__dict__[self.name]
        except KeyError:
            raise AttributeError

class Pair(_namedtuple('_Pair', 'false true')):
    __slots__ = ()

    def _mapwith(self, func):
        return Pair._make(map(func, self))

bools = Pair(False, True)


def to_dict(iterable_or_mapping, check_exclusive=False):<commit_msg>few utils as replacements of attrgetter, itemgetter and methodcaller functions from operator module<commit_after>"""
Misc stuff. --Eldar
"""

from functools import partial
from operator import attrgetter
from operator import itemgetter
from operator import methodcaller

from .collections import Mapping as _Mapping
from .collections import namedtuple as _namedtuple

from .compat import *


def identity(x):
    return x


class cached_property(object):
    """Non-data descriptor."""
    __slots__ = 'func'

    def __init__(self, func):
        super(cached_property, self).__init__()
        self.func = func

    def __get__(self, obj, objtype=None):
        if obj is None:
            return self
        func = self.func
        ret = func(obj)
        setattr(obj, func.__name__, ret)
        return ret


class intercepting_property(property):
    """Data descriptor."""
    __slots__ = 'name'

    def __init__(self, fget=None, fset=None, fdel=None, name=None, doc=None):
        func = fget or fset or fdel

        if name is None:
            if func is not None:
                name = func.__name__
            else:
                raise TypeError('no attribute name given')

        super(intercepting_property, self).__init__(fget, fset, fdel, doc)

    def __get__(self, obj, objtype=None):
        if obj is None:
            return self
        try:
            ret = obj.__dict__[self.name]
        except KeyError:
            raise AttributeError
        fget = self.fget
        if fget is not None:
            ret = fget(obj, ret)
        return ret

    def __set__(self, obj, value):
        fset = self.fset
        if fset is not None:
            value = fset(obj, value)
        obj.__dict__[self.name] = value

    def __delete__(self, obj):
        fdel = self.fdel
        if fdel is not None:
            fdel(obj)
        try:
            del obj.__dict__[self.name]
        except KeyError:
            raise AttributeError


class GetterType(object):
    """
    getter.attr  -> attrgetter('attr')
    getter[item] -> itemgetter(item)
    """

    def __getattr__(self, attr):
        return attrgetter(attr)

    def __getitem__(self, item):
        return itemgetter(item)

getter = GetterType()


class InvokerType(object):
    """
    invoker.meth(*args, **kwargs) -> methodcaller('meth', *args, **kwargs)
    """

    def __getattr__(self, meth):
        return partial(methodcaller, meth)

invoker = InvokerType()


class Pair(_namedtuple('_Pair', 'false true')):
    __slots__ = ()

    def _mapwith(self, func):
        return Pair._make(map(func, self))

bools = Pair(False, True)


def to_dict(iterable_or_mapping, check_exclusive=False):
{'fraction_non_alphanumeric': 0.09772195018096658, 'fraction_numerical': 0.0, 'mean_word_length': 2.23331039229181, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '1255063', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1411, 'n_words': 416}