<commit_before>from django.conf import settings
from hashlib import md5
import os
import pickle
from .signals import source_created, source_changed, source_deleted
from ..exceptions import UnknownExtensionError, AlreadyRegistered, NotRegistered
from ..imagecache.backends import get_default_image_cache_backend
from ..imagecache.strategies import StrategyWrapper
from ..lib import StringIO
from ..processors import ProcessorPipeline
from ..utils import (open_image, extension_to_format, IKContentFile,
    img_to_fobj, suggest_extension)


class SpecRegistry(object):
    signals = {
        source_created: 'source_created',
        source_changed: 'source_changed',
        source_deleted: 'source_deleted',
    }

    def __init__(self):
        self._specs = {}
        self._sources = {}
        for signal in self.signals.keys():
            signal.connect(self.source_receiver)

    def register(self, id, spec):
        if id in self._specs:
            raise AlreadyRegistered('The spec with id %s is already registered' % id)
        self._specs[id] = spec<commit_msg>Add description of registry<commit_after>from django.conf import settings
from hashlib import md5
import os
import pickle
from .signals import source_created, source_changed, source_deleted
from ..exceptions import UnknownExtensionError, AlreadyRegistered, NotRegistered
from ..imagecache.backends import get_default_image_cache_backend
from ..imagecache.strategies import StrategyWrapper
from ..lib import StringIO
from ..processors import ProcessorPipeline
from ..utils import (open_image, extension_to_format, IKContentFile,
    img_to_fobj, suggest_extension)


class SpecRegistry(object):
    """
    An object for registering specs and sources. The two are associated with
    eachother via a string id. We do this (as opposed to associating them
    directly by, for example, putting a ``sources`` attribute on specs) so that
    specs can be overridden without losing the associated sources. That way,
    a distributable app can define its own specs without locking the users of
    the app into it.

    """

    signals = {
        source_created: 'source_created',
        source_changed: 'source_changed',
        source_deleted: 'source_deleted',
    }

    def __init__(self):
        self._specs = {}
        self._sources = {}
        for signal in self.signals.keys():
            signal.connect(self.source_receiver)

    def register(self, id, spec):
        if id in self._specs:
            raise AlreadyRegistered('The spec with id %s is already registered' % id)
        self._specs[id] = spec
{'fraction_non_alphanumeric': 0.0720616570327553, 'fraction_numerical': 0.0007707129094412332, 'mean_word_length': 3.562390158172232, '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': '1329991', 'n_tokens_mistral': 707, 'n_tokens_neox': 693, 'n_words': 239}