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


Python ConfigParser.read_string方法代码示例

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


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

示例1: get_configuration

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read_string [as 别名]
def get_configuration(configuration=None):
    """
    Parse a configuration file

    Parameters
    ----------
    configuration : str or list, optional
        A configuration file or list of configuration files to parse,
        defaults to the deploy_default.conf file in the package and
        deploy.conf in the current working directory.

    Returns
    -------
    configparser
        The parsed configuration
    """
    if not configuration:  # pragma: no cover
        configuration = [
            # Config file that is part of the package
            # PACKAGE_DEFAULT_CONFIG,

            # Any deploy.conf files in the current directory
            'deploy.conf'
        ]
    config = ConfigParser()

    # Set the config defaults
    try:
        config.read_string(config_defaults())
    except AttributeError:
        config.readfp(io.BytesIO(config_defaults()))

    logger.debug('Working with default dict: %r', config_defaults())
    config.read(configuration)
    return config
开发者ID:yahoo,项目名称:invirtualenv,代码行数:37,代码来源:config.py

示例2: get_configuration_dict

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read_string [as 别名]
def get_configuration_dict(configuration=None, value_types=None):
    """
    Parse the configuration files

    Parameters
    ----------
    configuration : str or list, optional
        A configuration file or list of configuration files to parse,
        defaults to the deploy_default.conf file in the package and
        deploy.conf in the current working directory.

    value_types : dict, optional
        Dictionary containing classes to apply to specific items

    Returns
    -------
    dict
        Configuration dictionary
    """
    if not value_types:  # pragma: no cover
        value_types = config_types()
    if configuration is None or configuration is '':  # pragma: no cover
        configuration = [
            # Config file that is part of the package
            # PACKAGE_DEFAULT_CONFIG,

            # Any deploy.conf files in the current directory
            'deploy.conf'
        ]
    config = ConfigParser()

    # Set the config defaults
    try:
        config.read_string(config_defaults())
    except AttributeError:
        config.readfp(io.BytesIO(config_defaults()))

    logger.debug('Working with default dict: %r', config_defaults())
    config.read(configuration)
    result_dict = {}
    for section in config.sections():
        result_dict[section] = {}
        for key, val in config.items(section):
            result_dict[section][key] = str_format_env(val)

    config_update(result_dict)

    if 'locations' not in result_dict.keys():
        result_dict['locations'] = {}
    result_dict['locations']['package_scripts'] = package_scripts_directory()
    if not result_dict['global'].get('virtualenv_dir', None):
        result_dict['global']['virtualenv_dir'] = \
            default_virtualenv_directory()

    cast_types(result_dict)

    return result_dict
开发者ID:dwighthubbard,项目名称:invirtualenv,代码行数:59,代码来源:config.py

示例3: getLayoutsFromManifest

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read_string [as 别名]
def getLayoutsFromManifest(fp, _format, directory_name):
    # support multiple sections with the same name in manifest.cfg

    if six.PY2:
        parser = ConfigParser(None, multidict)
        parser.readfp(fp)
    else:
        data = fp.read()
        if isinstance(data, six.binary_type):
            data = data.decode()
        parser = ConfigParser(dict_type=multidict, strict=False)
        parser.read_string(data)

    layouts = {}
    for section in parser.sections():
        if not section.startswith(_format.resourceType) or \
           ':variants' in section:
            continue
        # id is a combination of directory name + filename
        if parser.has_option(section, 'file'):
            filename = parser.get(section, 'file')
        else:
            filename = ''  # this should not happen...
        _id = directory_name + '/' + filename
        if _id in layouts:
            # because TTW resources are created first, we consider layouts
            # with same id in a TTW to be taken before other resources
            continue
        data = {
            'directory': directory_name
        }
        for key in _format.keys:
            if parser.has_option(section, key):
                data[key] = parser.get(section, key)
            else:
                data[key] = _format.defaults.get(key, None)
        layouts[_id] = data

    return layouts
开发者ID:plone,项目名称:plone.app.blocks,代码行数:41,代码来源:resource.py


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