def __call__(self, klass, override=False): """ Register the plugin ``klass``. :param klass: A subclass of `Plugin` to attempt to register. :param override: If true, override an already registered plugin. """ if not inspect.isclass(klass): raise TypeError('plugin must be a class; got %r' % klass) # Raise DuplicateError if this exact class was already registered: if klass in self.__registry: raise errors.PluginDuplicateError(plugin=klass) # The plugin is okay, add to __registry: self.__registry[klass] = dict(override=override)
def register(plugin): """ Register the plugin ``plugin``. :param plugin: A subclass of `Plugin` to attempt to register. """ if not callable(plugin): raise TypeError('plugin must be callable; got %r' % plugin) # Raise DuplicateError if this exact class was already registered: if plugin in self.__registry: raise errors.PluginDuplicateError(plugin=plugin) # The plugin is okay, add to __registry: self.__registry[plugin] = dict(kwargs, plugin=plugin) return plugin