def get(self, section, option, subsection=None): """Get an option""" if not section in self.sections(): raise NoSectionError(section) if subsection: if not subsection in self._sections[section]: raise NoSectionError(subsection) if not option in self._sections[section][subsection]: raise NoOptionError(option, subsection) return self._sections[section][subsection][option] if not option in self._sections[section]: raise NoOptionError(option, section) return self._sections[section][option]
def includeme(config): try: datasources = config.registry.application_settings.ip_navigator.datasources except: raise NoOptionError('datasources', 'ip_navigator') if 'ops' in datasources: config.include("patzilla.access.epo.ops.client") if 'depatisconnect' in datasources: config.include("patzilla.access.dpma.depatisconnect") if 'ificlaims' in datasources: config.include("patzilla.access.ificlaims.clientpool") if 'depatech' in datasources: config.include("patzilla.access.depatech.clientpool") if 'sip' in datasources: config.include("patzilla.access.sip.concordance") config.include("patzilla.access.sip.clientpool") config.include('.office') config.scan()
def has_comment(self, section, option=None): """ Return if the given section heading or option within a section has an associated comment. @type section: str @type option: str or None @rtype: bool @raise NoSectionError: The provided section does not exist """ if not section: section = DEFAULTSECT if not self.has_section(section) and section != DEFAULTSECT: raise NoSectionError(section) if option: option = self.optionxform(option) if not self.has_option(section, option): raise NoOptionError(option, section) else: # looking for section comment option = '__name__' return bool( self._comments.get(section, False) and self._comments[section].get(option, False))
def set_comment(self, comment, section, option=None): """ Set the comment for a section or option @type comment: str or None @type section: str @type option: str or None """ if not section: section = DEFAULTSECT if not self.has_section(section) and section != DEFAULTSECT: raise NoSectionError(section) if section not in self._comments: self._comments[section] = self._dict() if option: option = self.optionxform(option) if not self.has_option(section, option): raise NoOptionError(option, section) else: # setting section comment option = '__name__' self._comments[section][option] = comment
def get(self, section, option): if self.has_option(section, option): hkey = "%s:section:%s:option:%s" % (self.namespace, section, option) value = self.redis.get(hkey) return value else: raise NoOptionError(section, option)
def remove_comment(self, section, option=None): """ Remove the comment from a section or option. @type section: str @param section: The section to remove from. @type option: str or None @param option: The option to remove from or None to remove a section's comment. @rtype: bool @return: True if a comment was removed and False if no comment was removed. """ if not section: section = DEFAULTSECT elif not self.has_section(section) and section != DEFAULTSECT: raise NoSectionError(section) if option: option = self.optionxform(option) if not self.has_option(section, option): raise NoOptionError(option, section) else: # setting section comment option = '__name__' del self._comments[section][option]
def get(self, section, option, raw=False, vars=None, fallback=_UNSET): d = self._defaults.copy() try: d.update(self._sections[section]) except KeyError: if section != DEFAULTSECT: raise NoSectionError(section) # Update the entry specific variables if vars: for key, value in vars.items(): d[self.optionxform(key)] = value option = self.optionxform(option) try: value = d[option] except KeyError: if fallback is _UNSET: raise NoOptionError(option, section) else: return fallback if raw or value is None: return value else: return self._interpolate(section, option, value, d)
def _read_value(parser, section, option): if not parser.has_section(section): raise NoSectionError("%s (available sections: %s)" % (section, sorted(parser.sections()))) if not parser.has_option(section, option): raise NoOptionError("%s (available options: %s)" % (option, sorted(parser.options(section))), section) else: return parser.get(section, option)
def get(self, section, option): if section == 'memcache': if option == 'memcache_servers': return '1.2.3.4:5' else: raise NoOptionError(option) else: raise NoSectionError(option)
def has_option(self, section, option): hkey = "%s:section:%s:option:%s" % (self.namespace, section, option) if self.has_section(section): if not self.redis.exists(hkey): raise NoOptionError(section, option) else: raise NoSectionError(section) return True
def validate_config(self): if not self.has_section('input'): raise NoSectionError('input') must_haves = ('file', 'type', 'tags', 'pattern') for key in must_haves: if not self.has_option('input', key): raise NoOptionError(key, 'input')
def _get(self, config_func, option): superclasses = [superclass.__name__ for superclass in self.__class__.__mro__] superclasses[-1] = 'DEFAULT' for i, superclass in enumerate(superclasses): superclasses[i] = superclass = re.sub('\B([A-Z][a-z])', r' \1', superclass) superclasses[i] = superclass = re.sub('([a-z])([A-Z])', r'\1 \2', superclass) if self._config.has_section(superclass) and self._config.has_option(superclass, option): return None if self._config.get(superclass, option) == 'None' else config_func(superclass, option) raise NoOptionError(option, superclasses)
def get(self, section, option): if _section == section: if option == 'memcache_servers': if _srvs == 'error': raise NoOptionError(option, section) return _srvs elif option == 'memcache_serialization_support': if _sers == 'error': raise NoOptionError(option, section) return _sers elif option in ('memcache_max_connections', 'max_connections'): if _maxc == 'error': raise NoOptionError(option, section) return _maxc else: raise NoOptionError(option, section) else: raise NoSectionError(option)
def includeme(config): datasource_settings = config.registry.datasource_settings try: api_uri = datasource_settings.datasource.sip.api_uri except: raise NoOptionError('api_uri', 'datasource:sip') config.registry.registerUtility(SipClientPool(api_uri=api_uri)) config.add_subscriber(attach_sip_client, "pyramid.events.ContextFound")
def get(self, section, option, vars=None): if not self.has_section(section): raise NoSectionError(section) if vars is not None and option in vars: value = vars[option] try: return self.data[section][option] except KeyError: raise NoOptionError(option, section)
def get(self, section, option, raw=False, vars=None): try: return SafeConfigParser.get(self, section, option, raw, vars) except NoSectionError: try: section_defaults = config_defaults[section] except KeyError: raise NoSectionError(section) try: return section_defaults[option] except KeyError: raise NoOptionError(option, section) except NoOptionError: try: section_defaults = config_defaults[section] return section_defaults[option] except KeyError: raise NoOptionError(option, section)
def get(self, section, option, default=NoDefault): """ Get an option section=None: attribute a default section name default: default value (if not specified, an exception will be raised if option doesn't exist) """ section = self.__check_section_option(section, option) if not self.has_section(section): if default is NoDefault: raise NoSectionError(section) else: self.add_section(section) if not self.has_option(section, option): if default is NoDefault: raise NoOptionError(option, section) else: self.set(section, option, default) return default value = ConfigParser.get(self, section, option, self.raw) default_value = self.get_default(section, option) try: # really ugly from datetime import datetime value = datetime.strptime(value ,"%Y-%m-%d").date() return default_value except: pass if isinstance(default_value, bool): value = eval(value) elif isinstance(default_value, float): value = float(value) elif isinstance(default_value, int): value = int(value) else: if isinstance(default_value, basestring): try: value = value.decode('utf-8') except (UnicodeEncodeError, UnicodeDecodeError): pass try: # lists, tuples, ... value = eval(value) except: pass return value
def test_get_repo_url_prefixes_from_config_no_entry(self): """ If we can't read the options, assert that we get a default """ mock_config = mock.Mock() mock_config.get.side_effect = NoOptionError(None, None) validator = oid_validation.OidValidator(mock_config) result = validator._get_repo_url_prefixes_from_config(mock_config) self.assertEquals(result, ["/pulp/repos", "/pulp/ostree/web"])
def _read_netapp_config(self, attribute, zfscredconfig): # Try reading Netapp configuration first from the credentials file, then fail over to main configuration file value = None try: return zfscredconfig.get('netapp', attribute) except (NoOptionError, NoSectionError) as e: pass try: return Configuration.get(attribute, 'netapp') except (NoOptionError, NoSectionError) as e: raise NoOptionError("Attribute %s not found" % attribute)
def get(self, section, option, vars=None): if not self.has_section(section): raise NoSectionError(section) if vars is not None and option in vars: value = vars[option] sec = self.data[section] if option in sec: return sec._compat_get(option) else: raise NoOptionError(option, section)
def includeme(config): global use_https global archive_service_baseurl datasource_settings = config.registry.datasource_settings try: archive_service_baseurl = datasource_settings.datasource.depatisconnect.api_uri except: raise NoOptionError('api_uri', 'datasource_depatisconnect') if archive_service_baseurl.startswith('https'): use_https = True
def _get_default(self, section, option): # cater for 'special' sections if section == '__noschema__': value = super(SchemaConfigParser, self).get(section, option) return value # any other section opt = self.schema.section(section).option(option) if not opt.fatal: value = opt.default return value # no default value found, raise an error raise NoOptionError(option, section)
def validate_config(self): if not self.has_section('default'): raise NoSectionError('default') for name in self.defaults(): if not self.has_option('default', name): raise NoOptionError(name, 'default') sender = self.get('default', 'sender') if not self.has_section(sender): raise NoSectionError(sender) loglevel = self.get('default', 'loglevel') if not hasattr(logging, loglevel.upper()): raise ValueError('Unknown loglevel: %r' % (loglevel))
def includeme(config): datasource_settings = config.registry.datasource_settings try: api_uri = datasource_settings.datasource.ificlaims.api_uri except: raise NoOptionError('api_uri', 'datasource:ificlaims') api_uri_json = None if 'api_uri_json' in datasource_settings.datasource.ificlaims: api_uri_json = datasource_settings.datasource.ificlaims.api_uri_json config.registry.registerUtility( IFIClaimsClientPool(api_uri=api_uri, api_uri_json=api_uri_json)) config.add_subscriber(attach_ificlaims_client, "pyramid.events.ContextFound")
def get(self, section, option): """ return default values instead of breaking this is a drop-in replacement for standard get from ConfigParser """ try: return SafeConfigParser.get(self, section, option) except NoOptionError: try: default_value = DEFAULT_CONF[section][option] except KeyError: raise NoOptionError(option, section) else: return default_value
def getValueFromComp(self, component, cvar, lang=None, required=False, default=None, override=None): if override: return override options = self.getComponentOptions(component) if lang: lcvar = cvar + '.' + lang if lcvar in options: return options[lcvar] if cvar in options: return options[cvar] else: if required: raise NoOptionError(cvar,component) return default
def get_asiaq_option(self, option, section=DEFAULT_CONFIG_SECTION, environment=None, required=True, default=None): """ Get a value from the config, checking first for an environment-specific value, then a generic value, then an env-specific default value in the default section, then a non-env-specific default value in the default section. In the case where none of these options has been set, if the "required" option is False, return the value of the "default" option; otherwise, raise NoOptionError. """ if required and (default is not None): raise ProgrammerError( "Using the 'default' option when 'required' is True makes no sense." ) if not environment: environment = self.environment env_option = "{0}@{1}".format(option, environment) default_option = "default_{0}".format(option) default_env_option = "default_{0}".format(env_option) if self.has_option(section, env_option): return self.get(section, env_option) if self.has_option(section, option): return self.get(section, option) elif self.has_option(DEFAULT_CONFIG_SECTION, default_env_option): return self.get(DEFAULT_CONFIG_SECTION, default_env_option) elif self.has_option(DEFAULT_CONFIG_SECTION, default_option): return self.get(DEFAULT_CONFIG_SECTION, default_option) if required: raise NoOptionError(option, section) return default
def get_comment(self, section, option=None): """ Get the comment for a section[.option] @type section: str @param section: Section heading to check for a comment, or the section heading that the target option is located under. @type option: str or None @param option: If checking for an option's comment, this is the option under the given section to check. If checking for a section's comment, this should be None. @rtype: str or None @return: The section or option comment if there is one, or None if there is no comment for the specified section or option. """ if not section: section = DEFAULTSECT if not self.has_section(section) and section != DEFAULTSECT: raise NoSectionError(section) if option: option = self.optionxform(option) if not self.has_option(section, option): raise NoOptionError(option, section) else: # looking for section comment option = '__name__' # Combined statement to handle both section and option requests. return (self._comments.get(section, None) and self._comments[section].get(option, None))
def wrapped(self, option, *args, **kwargs): if self.config_obj.has_option(self.name, option): return func(self, option, *args, **kwargs) else: raise NoOptionError(option, self.name)
def get(self, section, option, raw=False, vars=None): if section not in self.config_dict: raise NoSectionError(section) if option not in self.config_dict[section]: raise NoOptionError(option, section) return self.config_dict[section][option]