1. Matthew Turk
  2. analysis_plugins

Source

analysis_plugins / global_registry.py

import abc

class GlobalSharedRegistry(object):
    class __metaclass__(abc.ABCMeta):
        def __new__(mcls, name, b, d):
            cls = abc.ABCMeta.__new__(mcls, name, b, d)
            # Mutable, and shared between classes
            cls._global_registry = {}
            return cls

    @abc.abstractproperty
    def valid_type(self):
        pass

    def __setitem__(self, key, value):
        if not issubclass(value, self.valid_type):
            raise KeyError
        self._global_registry[key] = value

    def __getitem__(self, key):
        return self._global_registry[key]

    def __contains__(self, key):
        return key in self._global_registry

    def __iter__(self):
        return self._global_registry.__iter__()

    def keys(self):
        return self._global_registry.keys()