<commit_before>import etcd
from flask import json
from marshmallow import Schema


class BaseSchema(Schema):
    pass


class BaseManager:
    KEY = ''

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

    def all(self):
        try:
            dir = self.client.read(self.KEY, sorted=True)
            entries = [entry for entry in dir.leaves if not entry.dir]
        except etcd.EtcdKeyNotFound:
            dir = None
            entries = []

        return dir, self._load_from_etcd(entries)

    def all_keys(self):
        return [entry.key for entry in self.all()[1]]

    def by_id(self, entry_id):
        try:
            entry = self.client.read('/{}/{}'.format(self.KEY, entry_id))
        except etcd.EtcdKeyNotFound:
            return None

        return self._load_from_etcd(entry)

    def create(self, data, suffix=''):
        append = True if suffix == '' else False
        key = '/{}/{}'.format(self.KEY, suffix)

        entry = self.client.write(key, json.dumps(data), append=append)

        return self._load_from_etcd(entry)

    def update(self, entity):
        entity.value = json.dumps(entity.value)

        try:
            entity = self.client.update(entity)
        except (etcd.EtcdCompareFailed, etcd.EtcdKeyNotFound):
            return False

        return self._load_from_etcd(entity)
<commit_msg>Add delete method to base manager<commit_after>import etcd
from flask import json
from marshmallow import Schema


class BaseSchema(Schema):
    pass


class BaseManager:
    KEY = ''

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

    def all(self):
        try:
            dir = self.client.read(self.KEY, sorted=True)
            entries = [entry for entry in dir.leaves if not entry.dir]
        except etcd.EtcdKeyNotFound:
            dir = None
            entries = []

        return dir, self._load_from_etcd(entries)

    def all_keys(self):
        return [entry.key for entry in self.all()[1]]

    def by_id(self, entry_id):
        try:
            entry = self.client.read('/{}/{}'.format(self.KEY, entry_id))
        except etcd.EtcdKeyNotFound:
            return None

        return self._load_from_etcd(entry)

    def create(self, data, suffix=''):
        append = True if suffix == '' else False
        key = '/{}/{}'.format(self.KEY, suffix)

        entry = self.client.write(key, json.dumps(data), append=append)

        return self._load_from_etcd(entry)

    def update(self, entity):
        entity.value = json.dumps(entity.value)

        try:
            entity = self.client.update(entity)
        except (etcd.EtcdCompareFailed, etcd.EtcdKeyNotFound):
            return False

        return self._load_from_etcd(entity)

    def delete(self, entity):
        try:
            entity = self.client.delete(entity.key)
        except etcd.EtcdKeyNotFound:
            return False

        return self._load_from_etcd(entity)

{'fraction_non_alphanumeric': 0.10637572451414934, 'fraction_numerical': 0.0006818956699624957, 'mean_word_length': 2.1891304347826086, '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': '6922569', 'n_tokens_mistral': 901, 'n_tokens_neox': 857, 'n_words': 215}