当前位置: 首页>>代码示例>>Python>>正文


Python configparser.DEFAULTSECT属性代码示例

本文整理汇总了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) 
开发者ID:rootzoll,项目名称:raspiblitz,代码行数:19,代码来源:blitz.configcheck.py

示例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) 
开发者ID:rootzoll,项目名称:raspiblitz,代码行数:19,代码来源:config.py

示例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 
开发者ID:Eloston,项目名称:ungoogled-chromium,代码行数:25,代码来源:downloads.py

示例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 
开发者ID:datadotworld,项目名称:data.world-py,代码行数:18,代码来源:config.py

示例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) 
开发者ID:datadotworld,项目名称:data.world-py,代码行数:25,代码来源:config.py

示例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 
开发者ID:google,项目名称:citest,代码行数:22,代码来源:bindings.py

示例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 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:test_configparser.py

示例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 
开发者ID:datadotworld,项目名称:data.world-py,代码行数:9,代码来源:test_config.py

示例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)) 
开发者ID:datadotworld,项目名称:data.world-py,代码行数:32,代码来源:config.py

示例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) 
开发者ID:datadotworld,项目名称:data.world-py,代码行数:12,代码来源:config.py

示例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)) 
开发者ID:google,项目名称:citest,代码行数:40,代码来源:bindings.py

示例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) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:17,代码来源:config.py


注:本文中的configparser.DEFAULTSECT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。