def set_value(self, obj, value=None, check_mandatory=True): if self.deprecated: if value is not None: msg = 'Depreciated parameter supplied for "{}" in "{}". The value will be ignored.' logger.warning(msg.format(self.name, obj.name)) return if value is None: if self.default is not None: value = self.kind(self.default) elif check_mandatory and self.mandatory: msg = 'No values specified for mandatory parameter "{}" in {}' raise ConfigError(msg.format(self.name, obj.name)) else: try: value = self.kind(value) except (ValueError, TypeError): typename = get_type_name(self.kind) msg = 'Bad value "{}" for {}; must be {} {}' article = get_article(typename) raise ConfigError(msg.format(value, self.name, article, typename)) if value is not None: self.validate_value(self.name, value) if self.merge and hasattr(obj, self.name): value = merge_config_values(getattr(obj, self.name), value) setattr(obj, self.name, value)
def get_plugin_class(self, name, kind=None): """ Return the class for the specified plugin if found or raises ``ValueError``. """ name, _ = self.resolve_alias(name) if kind is None: try: return self.plugins[name] except KeyError: raise NotFoundError('plugins {} not found.'.format(name)) if kind not in self.kind_map: raise ValueError('Unknown plugin type: {}'.format(kind)) store = self.kind_map[kind] if name not in store: msg = 'plugins {} is not {} {}.' raise NotFoundError(msg.format(name, get_article(kind), kind)) return store[name]
def set_value(self, obj, value=None, check_mandatory=True): if value is None: if self.default is not None: value = self.kind(self.default) elif check_mandatory and self.mandatory: msg = 'No values specified for mandatory parameter "{}" in {}' raise ConfigError(msg.format(self.name, obj.name)) else: try: value = self.kind(value) except (ValueError, TypeError): typename = get_type_name(self.kind) msg = 'Bad value "{}" for {}; must be {} {}' article = get_article(typename) raise ConfigError(msg.format(value, self.name, article, typename)) if value is not None: self.validate_value(self.name, value) if self.merge and hasattr(obj, self.name): value = merge_config_values(getattr(obj, self.name), value) setattr(obj, self.name, value)