<commit_before>
"""
pymongo_basemodel.entity
~~~~~~~~~~~~~~~~~~~~~~~~
This module defines the Entity and Entities interfaces. Entities is a cache of 
Entity groups that allows for retrieval by name. Entity is a metaclass that 
creates Model and Collection classes.
"""

from .delimited import DelimitedDict
from .exceptions import EntityNotSet


class EntityMeta(object):
    pass


class Entities(object):

    cache = {}

    @classmethod
    def set(cls, name, entity):
        Entities.cache[name] = entity

    @classmethod
    def get(cls, name):
        if name not in Entities.cache:
            raise EntityNotSet(name)
        else:
            return Entities.cache[name]


class Entity(type):

    def __new__(cls, name, m_options=None, c_options=None):
        from .model import Model
        from .collection import Collection

        configs = [{
            "type": "model",
            "bases": [Model, EntityMeta],
            "options": m_options
        }, {
            "type": "collection",
            "bases": [Collection, EntityMeta],
            "options": c_options
        }]

        entity = {}
        for c in configs:

            # special attributes
            if c["options"] is not None:

                # methods
                if "methods" in c["options"]:
                    c["bases"] = [c["options"]["methods"]] + c["bases"]
                    del c["options"]["methods"]

            entity[c["type"]] = type(
                name + c["type"].title(),
                tuple(c["bases"]),
                {"__entity__": entity}
            )

            if c["options"] is None:
                continue

            for k, v in c["options"].items():<commit_msg>changed entity to allow list of classes to inherit methods from<commit_after>
"""
pymongo_basemodel.entity
~~~~~~~~~~~~~~~~~~~~~~~~
This module defines the Entity and Entities interfaces. Entities is a cache of
Entity groups that allows for retrieval by name. Entity is a metaclass that
creates Model and Collection classes.
"""

from .delimited import DelimitedDict
from .exceptions import EntityNotSet


class EntityMeta(object):
    pass


class Entities(object):

    cache = {}

    @classmethod
    def set(cls, name, entity):
        Entities.cache[name] = entity

    @classmethod
    def get(cls, name):
        if name not in Entities.cache:
            raise EntityNotSet(name)
        else:
            return Entities.cache[name]


class Entity(type):

    def __new__(cls, name, m_options=None, c_options=None):
        from .model import Model
        from .collection import Collection

        configs = [{
            "type": "model",
            "bases": [Model, EntityMeta],
            "options": m_options
        }, {
            "type": "collection",
            "bases": [Collection, EntityMeta],
            "options": c_options
        }]

        entity = {}
        for c in configs:

            # special attributes
            if c["options"] is not None:

                # methods
                if "methods" in c["options"]:
                    methods = c["options"]["methods"]
                    del c["options"]["methods"]

                    if type(methods) is not list:
                        methods = [methods]

                    c["bases"] = methods + c["bases"]

            entity[c["type"]] = type(
                name + c["type"].title(),
                tuple(c["bases"]),
                {"__entity__": entity}
            )

            if c["options"] is None:
                continue

            for k, v in c["options"].items():
{'fraction_non_alphanumeric': 0.12021099389228207, 'fraction_numerical': 0.0, 'mean_word_length': 1.7973602484472049, 'pattern_counts': {'":': 14, '<': 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': '1654633', 'n_tokens_mistral': 983, 'n_tokens_neox': 929, 'n_words': 292}