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


Python SafeConfigParser.defaults方法代码示例

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


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

示例1: read_ini

# 需要导入模块: from six.moves.configparser import SafeConfigParser [as 别名]
# 或者: from six.moves.configparser.SafeConfigParser import defaults [as 别名]
    def read_ini(cls, path, section=None):
        """read preferences from an .ini file"""

        parser = ConfigParser()
        parser.optionxform = str
        parser.readfp(mozfile.load(path))

        if section:
            if section not in parser.sections():
                raise PreferencesReadError("No section '%s' in %s" % (section, path))
            retval = parser.items(section, raw=True)
        else:
            retval = parser.defaults().items()

        # cast the preferences since .ini is just strings
        return [(i, cls.cast(j)) for i, j in retval]
开发者ID:luke-chang,项目名称:gecko-1,代码行数:18,代码来源:prefs.py

示例2: IniConfigLoader

# 需要导入模块: from six.moves.configparser import SafeConfigParser [as 别名]
# 或者: from six.moves.configparser.SafeConfigParser import defaults [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.defaults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。