<commit_before>import weakref
from project.extensions import db


class Registry:
    _resources = {}

    def __getitem__(self, name):
        return self._resources[name]

    def __setitem__(self, name, func):
        self._resources[name] = func


registry = Registry()


class Resource:
    resource_name = None

    def __init__(self, resource_name):
        self.resource_name = resource_name

    def __get__(self, instance, clazz):
        if instance:
            target = instance
        else:
            target = clazz

        if self.resource_name not in target.__dict__:
            func = registry[self.resource_name](target)
            setattr(target, self.resource_name, func)

        return target.__dict__[self.resource_name]


class BaseBL:
    _model = None

    def __init__(self, model):
        self._model = weakref.ref(model)

    @property
    def model(self):
        return self._model()

    def get(self, id_):
        return self.model.query.get(id_)

    def create(self, data):
        model = self.model(**data)
        self.save()
        return model

    def update(self, data):
        model = self.model
        for key, value in data.items():
            setattr(model, key, value)
        self.save()
        return model

    def save(self):
        db.session.add(self.model)
        db.session.commit()

    def delete(self):
        db.session.delete(self.model)<commit_msg>fix #154<commit_after>import weakref
from project.extensions import db


class Registry:
    _resources = {}

    def __getitem__(self, name):
        return self._resources[name]

    def __setitem__(self, name, func):
        self._resources[name] = func


registry = Registry()


class Resource:
    resource_name = None

    def __init__(self, resource_name):
        self.resource_name = resource_name

    def __get__(self, instance, clazz):
        if instance:
            target = instance
        else:
            target = clazz

        if self.resource_name not in target.__dict__:
            func = registry[self.resource_name](target)
            setattr(target, self.resource_name, func)

        return target.__dict__[self.resource_name]


class BaseBL:
    _model = None

    def __init__(self, model):
        self._model = weakref.ref(model)

    @property
    def model(self):
        return self._model()

    def get(self, id_):
        return self.model.query.get(id_)

    def create(self, data):
        model = self.model(**data)
        model.bl.save()
        return model

    def update(self, data):
        model = self.model
        for key, value in data.items():
            setattr(model, key, value)
        self.save()
        return model

    def save(self):
        db.session.add(self.model)
        db.session.commit()

    def delete(self):
        db.session.delete(self.model)
{'fraction_non_alphanumeric': 0.09898209898209898, 'fraction_numerical': 0.001053001053001053, 'mean_word_length': 2.184357541899441, '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': '875848', 'n_tokens_mistral': 853, 'n_tokens_neox': 809, 'n_words': 208}