<commit_before>from docliber.storage.metadata import MetaEngine
from docliber.storage.documents import DocEngine


class LibreDB(object):
    def __init__(self, root_path):
        self.root_path = root_path
        self.meta = MetaEngine(self.root_path)
        self.docs = DocEngine(self.root_path)

    def add_peers(self, peers):
        """
        Add a set of peers from our databse
        :param peers: a set of peers to add
        :type peers: frozenset
        """
        if not self.meta.has_key("peers"):
            self.meta.put_pickle("peers", frozenset(peers))
        else:
            self.meta.put_pickle(
                "peers",
                self.meta.load_pickle("peers") + frozenset(peers))

    def remove_peers(self, peers):
        """
        Remove a set of peersfrom our database
        :param peers: a set of peers to add
        :type peers: frozenset
        """
        if self.meta.has_key("peers"):
            self.meta.put_pickle(
                "peers",
                self.meta.load_pickle("peers") - frozenset(peers))

    def get_peers(self):
        """
        Return all of our peers in a set
        :return A set of peers that we hve
        :rtype frozenset
        """
        if self.meta.has_key("peers"):
            return self.meta.load_pickle("peers")
        else:
            return frozenset(())
<commit_msg>Changed how peers are added and removed in order to make it easier to hook into an api<commit_after>from docliber.storage.metadata import MetaEngine
from docliber.storage.documents import DocEngine


class LibreDB(object):
    def __init__(self, root_path):
        self.root_path = root_path
        self.meta = MetaEngine(self.root_path)
        self.docs = DocEngine(self.root_path)

    def add_peer(self, peer):
        """
        Add a set of peers from our databse
        :param peers: a set of peers to add
        :type peers: frozenset
        """
        if not self.meta.has_key("peers"):
            self.meta.put_pickle("peers", {peer['address']: peer})
        else:
            current_peers = self.meta.load_pickle("peers")
            if peer['address'] not in current_peers:
                    current_peers.append(peer)
            self.meta.put_pickle("peers", current_peers)

    def remove_peer(self, peer):
        """
        Remove a set of peers from our database
        :param peers: a set of peers to add
        :type peers: frozenset
        """
        if self.meta.has_key("peers"):
            current_peers = self.meta.load_pickle("peers")
            if peer['address'] in current_peers:
                del current_peers[peer['address']]
            self.meta.put_pickle("peers", current_peers)

    def get_peers(self):
        """
        Return all of our peers in a set
        :return A set of peers that we hve
        :rtype frozenset
        """
        if self.meta.has_key("peers"):
            return [peer for _, peer in self.meta.load_pickle("peers").iteritems()]
        else:
            return []

{'fraction_non_alphanumeric': 0.09973579920739763, 'fraction_numerical': 0.0, 'mean_word_length': 2.016932270916335, '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': '637728', 'n_tokens_mistral': 913, 'n_tokens_neox': 903, 'n_words': 244}