本文整理匯總了Python中configparser.DEFAULTSECT屬性的典型用法代碼示例。如果您正苦於以下問題:Python configparser.DEFAULTSECT屬性的具體用法?Python configparser.DEFAULTSECT怎麽用?Python configparser.DEFAULTSECT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類configparser
的用法示例。
在下文中一共展示了configparser.DEFAULTSECT屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: reload
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def reload(self):
"""load config from file"""
parser = ConfigParser()
log.debug("loading config from file: {}".format(self.abs_path))
with open(self.abs_path) as f:
parser.read_string("[{}]\n".format(DEFAULTSECT) + f.read())
default_s = parser[DEFAULTSECT]
self.base_image = get_str_clean(default_s, "baseimage", self.base_image)
self.chain = get_str_clean(default_s, "chain", self.chain)
self.message = get_str_clean(default_s, "message", self.message)
self.network = get_str_clean(default_s, "network", self.network)
self.setup_step = get_int_safe(default_s, "setupStep", self.setup_step)
self.state = get_str_clean(default_s, "state", self.state)
self.undervoltage_reports = get_int_safe(default_s, "undervoltageReports", self.undervoltage_reports)
示例2: reload
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def reload(self):
"""load config from file"""
parser = ConfigParser()
log.debug("loading RaspiBlitzInfo config from file: {}".format(self.abs_path))
with open(self.abs_path) as f:
parser.read_string("[{}]\n".format(DEFAULTSECT) + f.read())
default_s = parser[DEFAULTSECT]
self.base_image = get_str_clean(default_s, "baseimage", self.base_image)
self.chain = get_str_clean(default_s, "chain", self.chain)
self.message = get_str_clean(default_s, "message", self.message)
self.network = get_str_clean(default_s, "network", self.network)
self.setup_step = get_int_safe(default_s, "setupStep", self.setup_step)
self.state = get_str_clean(default_s, "state", self.state)
self.undervoltage_reports = get_int_safe(default_s, "undervoltageReports", self.undervoltage_reports)
示例3: _parse_data
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def _parse_data(self, path):
"""
Parses an INI file located at path
Raises schema.SchemaError if validation fails
"""
def _section_generator(data):
for section in data:
if section == configparser.DEFAULTSECT:
continue
yield section, dict(
filter(lambda x: x[0] not in self._ini_vars, data.items(section)))
new_data = configparser.ConfigParser(defaults=self._ini_vars)
with path.open(encoding=ENCODING) as ini_file:
new_data.read_file(ini_file, source=str(path))
try:
self._schema.validate(dict(_section_generator(new_data)))
except schema.SchemaError as exc:
get_logger().error('downloads.ini failed schema validation (located in %s)', path)
raise exc
return new_data
示例4: __migrate_config
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def __migrate_config(legacy_file_path):
config_parser = configparser.ConfigParser()
with open(legacy_file_path, 'r') as legacy:
regex = re.compile(r"^token\s*=\s*(\S.*)$")
token = next(iter(
[regex.match(line.strip()).group(1) for line in legacy if
regex.match(line)]),
None)
if token is not None:
config_parser[configparser.DEFAULTSECT] = {'auth_token': token}
# Will leave legacy in case R SDK may still need it
# os.remove(legacy_file_path)
return config_parser
示例5: __migrate_invalid_defaults
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def __migrate_invalid_defaults(config_parser):
# This fixes an issue related to us having referred to the default
# section in the config file as 'default' as opposed to using
# configparser.DEFAULTSECT
# That may result in 'ValueError: Invalid section name: default'
# https://github.com/datadotworld/data.world-py/issues/18
invalid_defaults = []
for section in config_parser.sections():
# Doesn't include DEFAULTSECT, but checking nonetheless
if (section != configparser.DEFAULTSECT and
section.lower() == configparser.DEFAULTSECT.lower()):
invalid_defaults.append(section)
if len(invalid_defaults) == 1:
old_default = invalid_defaults[0]
config_parser[configparser.DEFAULTSECT] = {
option: config_parser.get(old_default, option)
for option in config_parser.options(old_default)}
for section in invalid_defaults:
config_parser.remove_section(section)
return len(invalid_defaults)
示例6: __contains__
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def __contains__(self, name):
"""Determine if a binding name is defined."""
key = _normalize_key(name)
if (key in self.__overrides
or key in self.__lazy_initializers
or key in self.__defaults
or key in self.__config_parser.defaults()):
return True
all_sections = ([self.__section]
if self.__section
else self.__config_parser.sections())
if not all_sections:
all_sections = [ConfigParser.DEFAULTSECT]
for section in all_sections:
if self.__config_parser.has_option(section, key):
return True
return False
示例7: fromstring
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def fromstring(self, string, defaults=None):
cf = self.newconfig(defaults)
cf.read_string(string)
cf_copy = self.newconfig()
cf_copy.read_dict(cf)
# we have to clean up option duplicates that appeared because of
# the magic DEFAULTSECT behaviour.
for section in cf_copy.values():
if section.name == self.default_section:
continue
for default, value in cf[self.default_section].items():
if section[default] == value:
del section[default]
return cf_copy
示例8: default_config_file
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def default_config_file(config_file_path):
config_parser = configparser.ConfigParser()
config_parser.set(configparser.DEFAULTSECT, 'auth_token', 'file_token')
config_parser.write(open(config_file_path, 'w'))
# Tests
示例9: __init__
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def __init__(self, profile='default', **kwargs):
super(FileConfig, self).__init__()
# Overrides, for testing
self._config_file_path = path.expanduser(
kwargs.get('config_file_path', '~/.dw/config'))
legacy_file_path = path.expanduser(
kwargs.get('legacy_file_path', '~/.data.world'))
if not path.isdir(path.dirname(self._config_file_path)):
os.makedirs(path.dirname(self._config_file_path))
self._config_parser = (configparser.ConfigParser()
if six.PY3 else configparser.SafeConfigParser())
if path.isfile(self._config_file_path):
self._config_parser.read_file(open(self._config_file_path))
if self.__migrate_invalid_defaults(self._config_parser) > 0:
self.save()
elif path.isfile(legacy_file_path):
self._config_parser = self.__migrate_config(legacy_file_path)
self.save()
self._profile = profile
self._section = (profile
if profile.lower() != configparser.DEFAULTSECT.lower()
else configparser.DEFAULTSECT)
if not path.isdir(path.dirname(self.cache_dir)):
os.makedirs(path.dirname(self.cache_dir))
示例10: auth_token
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def auth_token(self, auth_token):
"""
:param auth_token:
"""
if (self._section != configparser.DEFAULTSECT and
not self._config_parser.has_section(self._section)):
self._config_parser.add_section(self._section)
self._config_parser.set(self._section, 'auth_token', auth_token)
示例11: _do_get
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def _do_get(self, name, default_value):
"""Helper function for looking up binding values.
Args:
name: [string] The name of the binding will be normalized internally.
default_value: [string] The value to return if not otherwise found.
Returns:
The binding value as either an override, config_value or default value.
Config values will come from the first section it is found in (or the
specific section this instance was configured for).
"""
key = _normalize_key(name)
if key in self.__overrides:
return _normalize_value(self.__overrides[key])
all_sections = ([self.__section]
if self.__section
else self.__config_parser.sections())
if not all_sections:
all_sections = [ConfigParser.DEFAULTSECT]
for section in all_sections:
if self.__config_parser.has_option(section, key):
return _normalize_value(self.__config_parser.get(section, key)
or default_value)
lazy_init = self.__lazy_initializers.get(key)
if lazy_init is not None:
lazy_value = lazy_init(self, key)
if lazy_value is not None:
self.__overrides[key] = lazy_value
return _normalize_value(lazy_value)
if key in self.__config_parser.defaults():
return _normalize_value(self.__config_parser.defaults()[key])
return _normalize_value(self.__defaults.get(key, default_value))
示例12: _write
# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import DEFAULTSECT [as 別名]
def _write(self, fp):
"""Write an .ini-format representation of the configuration state in
git compatible format"""
def write_section(name, section_dict):
fp.write(("[%s]\n" % name).encode(defenc))
for (key, value) in section_dict.items():
if key != "__name__":
fp.write(("\t%s = %s\n" % (key, self._value_to_string(value).replace('\n', '\n\t'))).encode(defenc))
# END if key is not __name__
# END section writing
if self._defaults:
write_section(cp.DEFAULTSECT, self._defaults)
for name, value in self._sections.items():
write_section(name, value)