Python configparser.SectionProxy() Examples
The following are 30
code examples of configparser.SectionProxy().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
configparser
, or try the search function
.
Example #1
Source File: util.py From autosuspend with GNU General Public License v2.0 | 6 votes |
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
Example #2
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 6 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> "XIdleTime": with warnings.catch_warnings(): warnings.simplefilter("ignore", FutureWarning) try: return cls( name, config.getint("timeout", fallback=600), config.get("method", fallback="sockets"), re.compile(config.get("ignore_if_process", fallback=r"a^")), re.compile(config.get("ignore_users", fallback=r"a^")), ) except re.error as error: raise ConfigurationError( "Regular expression is invalid: {}".format(error), ) from error except ValueError as error: raise ConfigurationError( "Unable to parse configuration: {}".format(error), ) from error
Example #3
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> "Users": with warnings.catch_warnings(): warnings.simplefilter("ignore", FutureWarning) try: user_regex = re.compile(config.get("name", fallback=r".*")) terminal_regex = re.compile(config.get("terminal", fallback=r".*")) host_regex = re.compile(config.get("host", fallback=r".*")) return cls(name, user_regex, terminal_regex, host_regex) except re.error as error: raise ConfigurationError( "Regular expression is invalid: {}".format(error), ) from error
Example #4
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create( cls, name: str, config: configparser.SectionProxy, ) -> "ActiveConnection": try: split_ports = config["ports"].split(",") ports = {int(p.strip()) for p in split_ports} return cls(name, ports) except KeyError as error: raise ConfigurationError("Missing option ports") from error except ValueError as error: raise ConfigurationError("Ports must be integers") from error
Example #5
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def _add_default_kodi_url(config: configparser.SectionProxy) -> None: if "url" not in config: config["url"] = "http://localhost:8080/jsonrpc"
Example #6
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
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
Example #7
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> "Kodi": return cls(name, **cls.collect_init_args(config))
Example #8
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def collect_init_args(cls, config: configparser.SectionProxy) -> Dict[str, Any]: try: _add_default_kodi_url(config) args = NetworkMixin.collect_init_args(config) args["idle_time"] = config.getint("idle_time", fallback=120) return args except ValueError as error: raise ConfigurationError("Configuration error " + str(error)) from error
Example #9
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> "Load": try: return cls(name, config.getfloat("threshold", fallback=2.5)) except ValueError as error: raise ConfigurationError( "Unable to parse threshold as float: {}".format(error) ) from error
Example #10
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> "Mpd": try: host = config.get("host", fallback="localhost") port = config.getint("port", fallback=6600) timeout = config.getint("timeout", fallback=5) return cls(name, host, port, timeout) except ValueError as error: raise ConfigurationError( "Host port or timeout configuration wrong: {}".format(error) ) from error
Example #11
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
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
Example #12
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> "Ping": try: hosts = config["hosts"].split(",") hosts = [h.strip() for h in hosts] return cls(name, hosts) except KeyError as error: raise ConfigurationError( "Unable to determine hosts to ping: {}".format(error) ) from error
Example #13
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> "Processes": try: processes = config["processes"].split(",") processes = [p.strip() for p in processes] return cls(name, processes) except KeyError as error: raise ConfigurationError("No processes to check specified") from error
Example #14
Source File: util.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> Check: return cls(name, **cls.collect_init_args(config)) # type: ignore
Example #15
Source File: activity.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create( cls, name: str, config: configparser.SectionProxy, ) -> "LogindSessionsIdle": types = config.get("types", fallback="tty,x11,wayland").split(",") types = [t.strip() for t in types] states = config.get("states", fallback="active,online").split(",") states = [t.strip() for t in states] return cls(name, types, states)
Example #16
Source File: wakeup.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> "File": try: path = config["path"] return cls(name, path) except KeyError as error: raise ConfigurationError("Missing option path") from error
Example #17
Source File: wakeup.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> "Periodic": try: kwargs = {} kwargs[config["unit"]] = float(config["value"]) return cls(name, timedelta(**kwargs)) # type: ignore except (ValueError, KeyError, TypeError) as error: raise ConfigurationError(str(error))
Example #18
Source File: __init__.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def config_section_string(section: configparser.SectionProxy) -> str: data = {k: v if k != "password" else "<redacted>" for k, v in section.items()} return f"{data}"
Example #19
Source File: permissions.py From rhinobot_heroku with MIT License | 5 votes |
def __init__(self, config_file, grant_all=None): self.config_file = config_file self.config = configparser.ConfigParser(interpolation=None) if not self.config.read(config_file, encoding='utf-8'): log.info("Permissions file not found, copying example_permissions.ini") try: shutil.copy('config/example_permissions.ini', config_file) self.config.read(config_file, encoding='utf-8') except Exception as e: traceback.print_exc() raise RuntimeError("Unable to copy config/example_permissions.ini to {}: {}".format(config_file, e)) self.default_group = PermissionGroup('Default', self.config['Default']) self.groups = set() for section in self.config.sections(): if section != 'Owner (auto)': self.groups.add(PermissionGroup(section, self.config[section])) if self.config.has_section('Owner (auto)'): owner_group = PermissionGroup('Owner (auto)', self.config['Owner (auto)'], fallback=Permissive) else: log.info("[Owner (auto)] section not found, falling back to permissive default") # Create a fake section to fallback onto the default permissive values to grant to the owner # noinspection PyTypeChecker owner_group = PermissionGroup("Owner (auto)", configparser.SectionProxy(self.config, "Owner (auto)"), fallback=Permissive) if hasattr(grant_all, '__iter__'): owner_group.user_list = set(grant_all) self.groups.add(owner_group)
Example #20
Source File: config.py From gpu_mon with GNU General Public License v3.0 | 5 votes |
def config_from_section(cls, section): assert isinstance(section, configparser.SectionProxy) indices = parse_gpu_indices(section['gpus']) ignore_programs = section['ignore_programs'].split(',') return GPUConfiguration(indices, ignore_programs)
Example #21
Source File: config.py From gpu_mon with GNU General Public License v3.0 | 5 votes |
def config_from_section(cls, section): assert isinstance(section, configparser.SectionProxy) indices = parse_gpu_indices(section['gpus']) dir = section['dir'] cmd = section['cmd'] log = section.get('log') return ProcessConfiguration(indices, dir, cmd, log)
Example #22
Source File: config.py From gpu_mon with GNU General Public License v3.0 | 5 votes |
def config_from_section(cls, section): assert isinstance(section, configparser.SectionProxy) enabled = section.getboolean('enabled') whitelist = section.get('whitelist', fallback='').split(',') idle_seconds = section.getint('idle_seconds', fallback=0) return TTYConfiguration(enabled, whitelist, idle_seconds)
Example #23
Source File: permissions.py From MusicBot with MIT License | 5 votes |
def __init__(self, config_file, grant_all=None): self.config_file = config_file self.config = configparser.ConfigParser(interpolation=None) if not self.config.read(config_file, encoding='utf-8'): log.info("Permissions file not found, copying example_permissions.ini") try: shutil.copy('config/example_permissions.ini', config_file) self.config.read(config_file, encoding='utf-8') except Exception as e: traceback.print_exc() raise RuntimeError("Unable to copy config/example_permissions.ini to {}: {}".format(config_file, e)) self.default_group = PermissionGroup('Default', self.config['Default']) self.groups = set() for section in self.config.sections(): if section != 'Owner (auto)': self.groups.add(PermissionGroup(section, self.config[section])) if self.config.has_section('Owner (auto)'): owner_group = PermissionGroup('Owner (auto)', self.config['Owner (auto)'], fallback=Permissive) else: log.info("[Owner (auto)] section not found, falling back to permissive default") # Create a fake section to fallback onto the default permissive values to grant to the owner # noinspection PyTypeChecker owner_group = PermissionGroup("Owner (auto)", configparser.SectionProxy(self.config, "Owner (auto)"), fallback=Permissive) if hasattr(grant_all, '__iter__'): owner_group.user_list = set(grant_all) self.groups.add(owner_group)
Example #24
Source File: util.py From autosuspend with GNU General Public License v2.0 | 5 votes |
def create(cls, name: str, config: configparser.SectionProxy) -> Check: return cls(name, **cls.collect_init_args(config)) # type: ignore
Example #25
Source File: test_Config.py From vault with MIT License | 5 votes |
def test_get_config(self): self.assertIsInstance(self.config.get_config(), configparser.SectionProxy)
Example #26
Source File: base.py From popup-dict with MIT License | 5 votes |
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') # 各发音客户端配置基类
Example #27
Source File: base.py From popup-dict with MIT License | 5 votes |
def __init__(self, section: SectionProxy): # noinspection PyUnresolvedReferences self.request_timeout = section.getint('request_timeout') # Validate configuration, raise exception if invalid
Example #28
Source File: base.py From popup-dict with MIT License | 5 votes |
def __init__(self, section: SectionProxy): self.client_id = section.get('client') if not self.client_id: raise ConfigError('No query client specified') # 查询客户端基本配置
Example #29
Source File: base.py From popup-dict with MIT License | 5 votes |
def __init__(self, section: SectionProxy): # noinspection PyUnresolvedReferences self.request_timeout = section.getint('request_timeout') # Validate configuration, raise exception if invalid
Example #30
Source File: word2vec.py From ee-outliers with GNU General Public License v3.0 | 5 votes |
def __init__(self, model_name: str, config_section: SectionProxy): super(Word2VecAnalyzer, self).__init__("word2vec", model_name, config_section)