本文整理汇总了Python中configparser.SectionProxy方法的典型用法代码示例。如果您正苦于以下问题:Python configparser.SectionProxy方法的具体用法?Python configparser.SectionProxy怎么用?Python configparser.SectionProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configparser
的用法示例。
在下文中一共展示了configparser.SectionProxy方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize_plugin
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def initialize_plugin(self) -> None:
"""
Initialize the plugin reading patterns from the config.
"""
try:
config: SectionProxy = self.configuration[self.name]
except KeyError:
return
else:
logger.info(f"Initializing {self.name} plugin")
if not self.initilized:
for k in config:
pattern_strings = [
pattern for pattern in config[k].split("\n") if pattern
]
self.patterns[k] = [
re.compile(pattern_string) for pattern_string in pattern_strings
]
logger.info(f"Initialized {self.name} plugin with {self.patterns}")
self.initilized = True
示例2: collect_init_args
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def collect_init_args(cls, config: configparser.SectionProxy) -> Dict[str, Any]:
from lxml.etree import XPath, XPathSyntaxError # noqa: S410 our input
try:
args = NetworkMixin.collect_init_args(config)
args["xpath"] = config["xpath"].strip()
# validate the expression
try:
XPath(args["xpath"])
except XPathSyntaxError as error:
raise ConfigurationError(
"Invalid xpath expression: " + args["xpath"]
) from error
return args
except KeyError as error:
raise ConfigurationError("Lacks " + str(error) + " config entry") from error
示例3: create
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def create(
cls, name: str, config: configparser.SectionProxy,
) -> "NetworkBandwidth":
try:
interfaces = config["interfaces"].split(",")
interfaces = [i.strip() for i in interfaces if i.strip()]
if not interfaces:
raise ConfigurationError("No interfaces configured")
host_interfaces = psutil.net_if_addrs().keys()
for interface in interfaces:
if interface not in host_interfaces:
raise ConfigurationError(
"Network interface {} does not exist".format(interface)
)
threshold_send = config.getfloat("threshold_send", fallback=100)
threshold_receive = config.getfloat("threshold_receive", fallback=100)
return cls(name, interfaces, threshold_send, threshold_receive)
except KeyError as error:
raise ConfigurationError(
"Missing configuration key: {}".format(error)
) from error
except ValueError as error:
raise ConfigurationError(
"Threshold in wrong format: {}".format(error)
) from error
示例4: read_ini_config
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def read_ini_config(
config_path: Path, sections: Optional[List[str]] = None
) -> configparser.SectionProxy:
"""Read a config_path using ConfigParser
Args:
config_path: path to the INI config file
sections: sections of config file to return, default to ['mutatest'] if None
Returns:
config section proxy
Raises:
KeyError if ``section`` not in ``config_path``.
"""
sections = sections or ["mutatest"]
config = configparser.ConfigParser()
# ensures [ mutatest ] is valid like [mutatest] in a section key
config.SECTCRE = re.compile(r"\[ *(?P<header>[^]]+?) *\]") # type: ignore
config.read(config_path)
# Attempt sections in the list, if none are matched raise a KeyError
for section in sections:
try:
return config[section]
except KeyError:
continue
raise KeyError
示例5: test_get_config
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def test_get_config(self):
self.assertIsInstance(self.config.get_config(),
configparser.SectionProxy)
示例6: __init__
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def __init__(self, section: SectionProxy):
# 是否启用发音
self.enabled = section.getboolean('enabled')
# 是否自动播放发音
self.auto_play = section.getboolean('auto_play')
# 发音客户端 id
self.client_id = section.get('client')
if self.enabled and not self.client_id:
raise ConfigError('No speech client specified')
# 各发音客户端配置基类
示例7: __init__
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def __init__(self, section: SectionProxy):
self.client_id = section.get('client')
if not self.client_id:
raise ConfigError('No query client specified')
# 查询客户端基本配置
示例8: __init__
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def __init__(self, model_name: str, config_section: SectionProxy):
super(Word2VecAnalyzer, self).__init__("word2vec", model_name, config_section)
示例9: configure
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def configure(self, config: configparser.SectionProxy) -> None:
"""
Configure the extractor from the mapping section.
Args:
config:
configuration section for the entry
"""
pass
示例10: __init__
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def __init__(self, section: configparser.SectionProxy, key: str) -> None:
self.section = section
self.key = key
self.value = self.section.get(key)
示例11: create
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def create(cls, name: str, config: configparser.SectionProxy) -> Check:
try:
return cls(name, config["command"].strip()) # type: ignore
except KeyError as error:
raise ConfigurationError("Missing command specification") from error
示例12: _add_default_kodi_url
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def _add_default_kodi_url(config: configparser.SectionProxy) -> None:
if "url" not in config:
config["url"] = "http://localhost:8080/jsonrpc"
示例13: collect_init_args
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import SectionProxy [as 别名]
def collect_init_args(cls, config: configparser.SectionProxy) -> Dict[str, Any]:
try:
_add_default_kodi_url(config)
args = NetworkMixin.collect_init_args(config)
args["suspend_while_paused"] = config.getboolean(
"suspend_while_paused", fallback=False
)
return args
except ValueError as error:
raise ConfigurationError("Configuration error {}".format(error)) from error