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


Python SafeConfigParser.options方法代码示例

本文整理汇总了Python中six.moves.configparser.SafeConfigParser.options方法的典型用法代码示例。如果您正苦于以下问题:Python SafeConfigParser.options方法的具体用法?Python SafeConfigParser.options怎么用?Python SafeConfigParser.options使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.configparser.SafeConfigParser的用法示例。


在下文中一共展示了SafeConfigParser.options方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read

# 需要导入模块: from six.moves.configparser import SafeConfigParser [as 别名]
# 或者: from six.moves.configparser.SafeConfigParser import options [as 别名]
def read(config_path):
    config_path = os.path.abspath(config_path)
    config_root = os.path.split(config_path)[0]
    parser = SafeConfigParser()
    success = parser.read(config_path)
    assert config_path in success, success

    subns = {"pwd": os.path.abspath(os.path.curdir)}

    rv = OrderedDict()
    for section in parser.sections():
        rv[section] = ConfigDict(config_root)
        for key in parser.options(section):
            rv[section][key] = parser.get(section, key, False, subns)

    return rv
开发者ID:Honry,项目名称:web-platform-tests,代码行数:18,代码来源:config.py

示例2: IniConfigLoader

# 需要导入模块: from six.moves.configparser import SafeConfigParser [as 别名]
# 或者: from six.moves.configparser.SafeConfigParser import options [as 别名]
class IniConfigLoader(object):
    """This config loader transforms a traditional INI file into
       a Montague Standard Format dictionary. It is compatible with
       most but not all PasteDeploy files."""

    def __init__(self, path):
        self.path = path
        self._data = self._read()
        self._config = self._process()

    def _read(self):
        # We need to keep the parser around so the logging conversion can use it.
        path_defaults = {
            'here': os.path.dirname(self.path),
            '__file__': self.path,
        }
        self._parser = SafeConfigParser()
        self._parser.read(self.path)
        self._globals = self._parser.defaults()
        data = {}
        for section in self._parser.sections():
            section_data = data.setdefault(section, {})
            for option in self._parser.options(section):
                if option in self._globals:
                    continue
                try:
                    section_data[option] = self._parser.get(section, option, vars=path_defaults)
                except InterpolationError:
                    section_data[option] = self._parser.get(section, option, raw=True)
        return data

    def _process(self):
        orig = self._data
        config = {}
        for key in six.iterkeys(orig):
            if ':' in key:
                scheme, name = key.split(':', 1)
                kind_config = config.setdefault(SCHEMEMAP[scheme], {})
                kind_config[name] = orig[key]
            else:
                config[key] = orig[key]
        config['globals'] = {
            'here': os.path.dirname(self.path),
            '__file__': self.path,
        }
        for key, value in six.iteritems(self._globals):
            config['globals'][key] = value
        apps = config.setdefault('application', {})
        filters = config.setdefault('filter', {})
        generated_filter_count = 0
        filter_apps = config.pop('filter-app', {})
        for name, filter_app in six.iteritems(filter_apps):
            use = filter_app.pop('next')
            generated_filter_count += 1
            filter_name = '_montague_filter_{0}'.format(generated_filter_count)
            apps[name] = {'use': use, 'filter-with': filter_name}
            filters[filter_name] = filter_app
        pipelines = config.pop('pipeline', {})
        for name, pipeline in six.iteritems(pipelines):
            items = pipeline['pipeline'].split()
            pipeline_app = items[-1]
            pipeline_filters = items[:-1]
            pipeline_filters.reverse()
            apps[name] = {'use': pipeline_app}
            last_item = apps[name]
            for count, use_filter in enumerate(pipeline_filters, start=1):
                filter_name = '_montague_pipeline_{0}_filter_{1}'.format(name, count)
                filters[filter_name] = {'use': use_filter}
                last_item['filter-with'] = filter_name
                last_item = filters[filter_name]
        if all([self._parser.has_section(section_name) for section_name in LOGGING_SECTIONS]):
            loggers = convert_loggers(self._parser)
            handlers = convert_handlers(self._parser)
            formatters = convert_formatters(self._parser)

            config['logging'] = {'main': combine(loggers, handlers, formatters)}

        for key in MSF_KEYS:
            config.setdefault(key, {})
        return config

    def config(self):
        return self._config

    def app_config(self, name):
        # This method isn't actually necessary, since montague can extract
        # the config information from the MSF dict returned by .config()
        # but it's a nice example of how to do it.
        if name in self._config['application']:
            constructor = LoadableConfig.app
            local_config = self._config['application'][name]
        elif name in self._config['composite']:
            constructor = LoadableConfig.composite
            local_config = self._config['composite'][name]
        else:
            raise KeyError
        return constructor(
            name=name, config=local_config, global_config=self._config['globals'])

    def server_config(self, name):
#.........这里部分代码省略.........
开发者ID:inklesspen,项目名称:montague,代码行数:103,代码来源:ini.py


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