From d498f1c0aebe73394080cc0b254ee0eebf8bd058 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Wed, 24 May 2017 16:49:16 +0200 Subject: [PATCH] Configparser update - add default values for maxdownload/uploadrate, asyncore - rework error handler slightly --- src/bmconfigparser.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index 448a9ffc..4e66c703 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -10,8 +10,13 @@ BMConfigDefaults = { "bitmessagesettings": { "maxaddrperstreamsend": 500, "maxbootstrapconnections": 20, + "maxdownloadrate": 0, "maxoutboundconnections": 8, "maxtotalconnections": 200, + "maxuploadrate": 0, + }, + "network": { + "asyncore": False }, "zlib": { 'maxsize': 1048576 @@ -27,35 +32,35 @@ class BMConfigParser(ConfigParser.SafeConfigParser): return ConfigParser.ConfigParser.set(self, section, option, value) def get(self, section, option, raw=False, vars=None): - if section == "bitmessagesettings" and option == "timeformat": - try: - return ConfigParser.ConfigParser.get(self, section, option, raw, vars) - except ConfigParser.InterpolationError: - return ConfigParser.ConfigParser.get(self, section, option, True, vars) try: - return ConfigParser.ConfigParser.get(self, section, option, True, vars) + if section == "bitmessagesettings" and option == "timeformat": + return ConfigParser.ConfigParser.get(self, section, option, raw, vars) + else: + return ConfigParser.ConfigParser.get(self, section, option, True, vars) + except ConfigParser.InterpolationError: + return ConfigParser.ConfigParser.get(self, section, option, True, vars) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e: try: return BMConfigDefaults[section][option] - except KeyError: + except (KeyError, ValueError, AttributeError): raise e def safeGetBoolean(self, section, field): try: return self.getboolean(section, field) - except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError): + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError, AttributeError): return False def safeGetInt(self, section, field, default=0): try: return self.getint(section, field) - except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError): + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError, AttributeError): return default def safeGet(self, section, option, default = None): try: return self.get(section, option) - except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError): + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError, AttributeError): return default def items(self, section, raw=False, vars=None):