/usr/share/pyshared/circuits/app/config.py is in python-circuits 2.1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | # Module: config
# Date: 13th August 2008
# Author: James Mills, prologic at shortcircuit dot net dot au
"""Config
Configuration Component. This component uses the standard
ConfigParser.ConfigParser class and adds support for saving
the configuration to a file.
"""
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser # NOQA
from circuits import handler, BaseComponent, Event
class ConfigEvent(Event):
"""Config Event"""
channels = ("config",)
success = True
failure = True
class Load(ConfigEvent):
"""Load Config Event"""
class Save(ConfigEvent):
"""Save Config Event"""
class Config(BaseComponent):
channel = "config"
def __init__(self, filename, defaults=None, channel=channel):
super(Config, self).__init__(channel=channel)
self._config = ConfigParser(defaults=defaults)
self._filename = filename
@handler("load")
def load(self, filename=None):
self._filename = filename or self._filename
self._config.read([self._filename])
@handler("save")
def save(self, filename=None):
self._filename = filename or self._filename
with open(self._filename, "w") as f:
self._config.write(f)
def add_section(self, section):
return self._config.add_section(section)
def items(self, section, raw=False, vars=None):
return self._config.items(section, raw=False, vars=None)
def get(self, section, option, default=None, raw=False, vars=None):
if self._config.has_option(section, option):
return self._config.get(section, option, raw=raw, vars=vars)
else:
return default
def getint(self, section, option, default=0):
if self._config.has_option(section, option):
return self._config.getint(section, option)
else:
return default
def getfloat(self, section, option, default=0.0):
if self._config.has_option(section, option):
return self._config.getfloat(section, option)
else:
return default
def getboolean(self, section, option, default=False):
if self._config.has_option(section, option):
return self._config.getboolean(section, option)
else:
return default
def has_section(self, section):
return self._config.has_section(section)
def has_option(self, section, option):
return self._config.has_option(section, option)
def set(self, section, option, value):
return self._config.set(section, option, value)
|