# -*- coding: utf-8 -*-

# (c) Jérôme Laheurte 2015-2026
# See LICENSE.txt

"""
Miscellaneous utilities.
"""

import functools


class Singleton(type):
    """
    Singleton metaclass
    """
    def __new__(mcs, name, bases, attrs):
        cls = type.__new__(mcs, name, bases, attrs)
        cls.__eq__ = lambda self, other: other is self
        cls.__lt__ = lambda self, other: not other is self
        cls.__copy__ = lambda self: self
        cls.__deepcopy__ = lambda self, memo: self
        cls.__repr__ = lambda self: self.__reprval__
        cls.__len__ = lambda self: len(self.__reprval__)
        cls.__hash__ = lambda self: hash(id(self))
        return functools.total_ordering(cls)()


def callback_by_name(func_name): # pylint: disable=missing-function-docstring
    def _wrapper(instance, *args, **kwargs):
        return getattr(instance, func_name)(*args, **kwargs)
    return _wrapper


def chars(s): # pylint: disable=missing-function-docstring
    return (s, s.encode('ascii')[0])
