本文整理匯總了Python中configparser.SectionProxy方法的典型用法代碼示例。如果您正苦於以下問題:Python configparser.SectionProxy方法的具體用法?Python configparser.SectionProxy怎麽用?Python configparser.SectionProxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類configparser
的用法示例。
在下文中一共展示了configparser.SectionProxy方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: 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
示例2: 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
示例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