本文整理汇总了Python中configparser.ConfigParser.get方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.get方法的具体用法?Python ConfigParser.get怎么用?Python ConfigParser.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configparser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_secure_option
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def is_secure_option(self, section, option):
"""Test an option to see if it is secured or not.
:param section: section id
:type section: string
:param option: option name
:type option: string
:rtype: boolean
otherwise.
"""
if not self.has_section(section):
return False
if not self.has_option(section, option):
return False
if ConfigParser.get(self, section, option) == self._secure_placeholder:
return True
return False
示例2: getstringlist
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def getstringlist(self, section, option):
"Coerce option to a list of strings or return unchanged if that fails."
value = ConfigParser.get(self, section, option)
# This seems to allow for newlines inside values
# of the config file, but be careful!!
val = value.replace('\n', '')
if self.pat.match(val):
return eval(val)
else:
return value
# This class as suggested by /F with an additional hook
# to be able to filter filenames.
示例3: get
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def get(self, section, key=None, **kwargs): # pylint:disable=arguments-differ
""" A simple hierachical config access, priority order:
1. environment var
2. user config file
3. bentoml default config file
"""
if key is None:
key = section
section = 'core'
section = str(section).lower()
key = str(key).lower()
env_var = self._env_var_name(section, key)
if env_var in os.environ:
return os.environ[env_var]
if ConfigParser.has_option(self, section, key):
return ConfigParser.get(self, section, key, **kwargs)
else:
raise BentoMLConfigException(
"section/key '{}/{}' not found in BentoML config".format(section, key)
)
示例4: save
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def save(self, default=False):
"""Save the current or default values into the configuration file.
"""
LOGGER.info("Generate the configuration file in '%s'", self.filename)
dirname = osp.dirname(self.filename)
if not osp.isdir(dirname):
os.makedirs(dirname)
with io.open(self.filename, 'w', encoding="utf-8") as fp:
for section, options in DEFAULT.items():
fp.write("[{}]\n".format(section))
for name, value in options.items():
if default:
val = value[0]
else:
val = self.get(section, name)
fp.write("# {}\n{} = {}\n\n".format(value[1], name, val))
self.handle_autostart()
示例5: items
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def items(self, section):
"""Get all items for a section. Subclassed, to ensure secure
items come back with the unencrypted data.
:param section: section id
:type section: string
"""
items = []
for k, v in ConfigParser.items(self, section):
if self.is_secure_option(section, k):
v = self.get(section, k)
if v == '!!False!!':
v = False
items.append((k, v))
return items
示例6: set_secure
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def set_secure(self, section, option, value):
"""Set an option and mark it as secure.
Any subsequent uses of 'set' or 'get' will also
now know that this option is secure as well.
"""
if self.keyring_available:
s_option = "%s%s" % (section, option)
self._unsaved[s_option] = ('set', value)
value = self._secure_placeholder
ConfigParser.set(self, section, option, value)
示例7: get
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def get(self, section, option, *args):
"""Get option value from section. If an option is secure,
populates the plain text."""
if self.is_secure_option(section, option) and self.keyring_available:
s_option = "%s%s" % (section, option)
if self._unsaved.get(s_option, [''])[0] == 'set':
res = self._unsaved[s_option][1]
else:
res = keyring.get_password(self.keyring_name, s_option)
else:
res = ConfigParser.get(self, section, option, *args)
if res == '!!False!!':
return False
return res
示例8: encrypt_account
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def encrypt_account(self, id):
"""Make sure that certain fields are encrypted."""
for key in self.secured_field_names:
value = self.parser.get(id, key)
self.parser.set_secure(id, key, value)
return self
示例9: printLocation
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def printLocation(depth=1):
if sys._getframe(depth).f_locals.get('__name__')=='__main__':
outDir = outputfile('')
if outDir!=_OUTDIR:
print('Logs and output files written to folder "%s"' % outDir)
示例10: get
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def get(self, section, option, **kwargs):
"""Override the default function of ConfigParser to add a
default value if section or option is not found.
:param section: config section name
:type section: str
:param option: option name
:type option: str
"""
if self.has_section(section) and self.has_option(section, option):
return ConfigParser.get(self, section, option, **kwargs)
return str(DEFAULT[section][option][0])
示例11: gettyped
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def gettyped(self, section, option):
"""Get a value from config and try to convert it in a native Python
type (using the :py:mod:`ast` module).
:param section: config section name
:type section: str
:param option: option name
:type option: str
"""
value = self.get(section, option)
try:
return ast.literal_eval(value)
except (ValueError, SyntaxError):
return value
示例12: getpath
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def getpath(self, section, option):
"""Get a path from config, evaluate the absolute path from configuration
file path.
:param section: config section name
:type section: str
:param option: option name
:type option: str
"""
return self._get_abs_path(self.get(section, option))
示例13: __getitem__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def __getitem__(self, name, raw=False, vars=None):
"""Fetch a value via the dict handler"""
if name not in simpleconfigparser.Section.__dict__:
return self.parser.get(self.section, name, raw, vars)
示例14: __getattr__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def __getattr__(self, name, raw=False, vars=None):
"""Fetch a value via the object handler"""
if name not in simpleconfigparser.Section.__dict__:
return self.parser.get(self.section, name, raw, vars)
示例15: get
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import get [as 别名]
def get(self, section, option, raw=False, vars=None, fallback=None):
try:
# Strip out quotes from the edges
return configparser.get(self, section, option).strip('"\'')
except NoOptionError:
return None