本文整理汇总了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
示例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
示例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