本文整理汇总了Python中six.moves.configparser.SafeConfigParser.getboolean方法的典型用法代码示例。如果您正苦于以下问题:Python SafeConfigParser.getboolean方法的具体用法?Python SafeConfigParser.getboolean怎么用?Python SafeConfigParser.getboolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.configparser.SafeConfigParser
的用法示例。
在下文中一共展示了SafeConfigParser.getboolean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getboolean
# 需要导入模块: from six.moves.configparser import SafeConfigParser [as 别名]
# 或者: from six.moves.configparser.SafeConfigParser import getboolean [as 别名]
def getboolean(self, section, option, default=None):
"""Wrapper around SafeConfigParser.getboolean() with a custom default.
This method simply wraps the base class method, but adds a `default`
keyword argument. The value of `default` is returned whenever the
config parser does not have the requested option and/or section.
"""
if not self.has_option(section, option):
if isinstance(default, bool):
return default
else:
# compatibility layer for py3 version of ConfigParser
if hasattr(self, '_boolean_states'):
boolean_states = self._boolean_states
else:
boolean_states = self.BOOLEAN_STATES
if default.lower() not in boolean_states:
raise ValueError('Not a boolean: %s' % default)
return boolean_states[default.lower()]
return SafeConfigParser.getboolean(self, section, option)
示例2: SafeConfigParser
# 需要导入模块: from six.moves.configparser import SafeConfigParser [as 别名]
# 或者: from six.moves.configparser.SafeConfigParser import getboolean [as 别名]
config = SafeConfigParser()
try:
with open(config_file, 'r') as f:
config.readfp(f, config_file)
except IOError:
pass
for option in ("jid", "jabber_password", "conference_domain", "mode", "zulip_email_suffix",
"jabber_server_address", "jabber_server_port"):
if (getattr(options, option) is None
and config.has_option("jabber_mirror", option)):
setattr(options, option, config.get("jabber_mirror", option))
for option in ("no_use_tls",):
if getattr(options, option) is None:
if config.has_option("jabber_mirror", option):
setattr(options, option, config.getboolean("jabber_mirror", option))
else:
setattr(options, option, False)
if options.mode is None:
options.mode = "personal"
if options.zulip_email_suffix is None:
options.zulip_email_suffix = ''
if options.mode not in ('public', 'personal'):
config_error("Bad value for --mode: must be one of 'public' or 'personal'")
if None in (options.jid, options.jabber_password):
config_error("You must specify your Jabber JID and Jabber password either "
+ "in the Zulip configuration file or on the commandline")