Configparser update

- add default values for maxdownload/uploadrate, asyncore
- rework error handler slightly
This commit is contained in:
Peter Šurda 2017-05-24 16:49:16 +02:00
parent 198470f734
commit d498f1c0ae
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -10,8 +10,13 @@ BMConfigDefaults = {
"bitmessagesettings": { "bitmessagesettings": {
"maxaddrperstreamsend": 500, "maxaddrperstreamsend": 500,
"maxbootstrapconnections": 20, "maxbootstrapconnections": 20,
"maxdownloadrate": 0,
"maxoutboundconnections": 8, "maxoutboundconnections": 8,
"maxtotalconnections": 200, "maxtotalconnections": 200,
"maxuploadrate": 0,
},
"network": {
"asyncore": False
}, },
"zlib": { "zlib": {
'maxsize': 1048576 'maxsize': 1048576
@ -27,35 +32,35 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return ConfigParser.ConfigParser.set(self, section, option, value) return ConfigParser.ConfigParser.set(self, section, option, value)
def get(self, section, option, raw=False, vars=None): def get(self, section, option, raw=False, vars=None):
try:
if section == "bitmessagesettings" and option == "timeformat": if section == "bitmessagesettings" and option == "timeformat":
try:
return ConfigParser.ConfigParser.get(self, section, option, raw, vars) return ConfigParser.ConfigParser.get(self, section, option, raw, vars)
except ConfigParser.InterpolationError: else:
return ConfigParser.ConfigParser.get(self, section, option, True, vars) return ConfigParser.ConfigParser.get(self, section, option, True, vars)
try: except ConfigParser.InterpolationError:
return ConfigParser.ConfigParser.get(self, section, option, True, vars) return ConfigParser.ConfigParser.get(self, section, option, True, vars)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e: except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e:
try: try:
return BMConfigDefaults[section][option] return BMConfigDefaults[section][option]
except KeyError: except (KeyError, ValueError, AttributeError):
raise e raise e
def safeGetBoolean(self, section, field): def safeGetBoolean(self, section, field):
try: try:
return self.getboolean(section, field) return self.getboolean(section, field)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError): except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError, AttributeError):
return False return False
def safeGetInt(self, section, field, default=0): def safeGetInt(self, section, field, default=0):
try: try:
return self.getint(section, field) return self.getint(section, field)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError): except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError, AttributeError):
return default return default
def safeGet(self, section, option, default = None): def safeGet(self, section, option, default = None):
try: try:
return self.get(section, option) return self.get(section, option)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError): except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError, AttributeError):
return default return default
def items(self, section, raw=False, vars=None): def items(self, section, raw=False, vars=None):