MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / BMConfigParser

Class BMConfigParser

src/bmconfigparser.py:38–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37@Singleton
38class BMConfigParser(ConfigParser.SafeConfigParser):
39 def set(self, section, option, value=None):
40 if self._optcre is self.OPTCRE or value:
41 if not isinstance(value, basestring):
42 raise TypeError("option values must be strings")
43 if not self.validate(section, option, value):
44 raise ValueError("Invalid value %s" % str(value))
45 return ConfigParser.ConfigParser.set(self, section, option, value)
46
47 def get(self, section, option, raw=False, variables=None):
48 try:
49 if section == "bitmessagesettings" and option == "timeformat":
50 return ConfigParser.ConfigParser.get(self, section, option, raw, variables)
51 return ConfigParser.ConfigParser.get(self, section, option, True, variables)
52 except ConfigParser.InterpolationError:
53 return ConfigParser.ConfigParser.get(self, section, option, True, variables)
54 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e:
55 try:
56 return BMConfigDefaults[section][option]
57 except (KeyError, ValueError, AttributeError):
58 raise e
59
60 def safeGetBoolean(self, section, field):
61 try:
62 return self.getboolean(section, field)
63 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError, AttributeError):
64 return False
65
66 def safeGetInt(self, section, field, default=0):
67 try:
68 return self.getint(section, field)
69 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError, AttributeError):
70 return default
71
72 def safeGet(self, section, option, default = None):
73 try:
74 return self.get(section, option)
75 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError, AttributeError):
76 return default
77
78 def items(self, section, raw=False, variables=None):
79 return ConfigParser.ConfigParser.items(self, section, True, variables)
80
81 def addresses(self):
82 return filter(lambda x: x.startswith('BM-'), BMConfigParser().sections())
83
84 def read(self, filenames):
85 ConfigParser.ConfigParser.read(self, filenames)
86 for section in self.sections():
87 for option in self.options(section):
88 try:
89 if not self.validate(section, option, ConfigParser.ConfigParser.get(self, section, option)):
90 try:
91 newVal = BMConfigDefaults[section][option]
92 except KeyError:
93 continue
94 ConfigParser.ConfigParser.set(self, section, option, newVal)
95 except ConfigParser.InterpolationError:

Callers 15

decodeExtendedMethod · 0.90
__init__Method · 0.90
l10n.pyFile · 0.90
getTranslationLanguageFunction · 0.90
configInitFunction · 0.90
apiInitFunction · 0.90
apiDataFunction · 0.90
bmSettingsFunction · 0.90
runMethod · 0.90
processgetpubkeyMethod · 0.90
processmsgMethod · 0.90
processbroadcastMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected