From 58b357b55f74e59307dc01589e98e5d30dcb2eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 22 Mar 2015 03:20:53 +0100 Subject: [PATCH] Improve config to be Python3 compatible issue4662 review14131002 --- trytond/backend/__init__.py | 2 +- trytond/backend/postgresql/database.py | 4 ++-- trytond/config.py | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/trytond/backend/__init__.py b/trytond/backend/__init__.py index 9264fa533a..44264ef2cf 100644 --- a/trytond/backend/__init__.py +++ b/trytond/backend/__init__.py @@ -9,7 +9,7 @@ __all__ = ['name', 'get'] def name(): - return urlparse.urlparse(config.get('database', 'uri', '')).scheme + return urlparse.urlparse(config.get('database', 'uri', default='')).scheme def get(prop): diff --git a/trytond/backend/postgresql/database.py b/trytond/backend/postgresql/database.py index 70f8382f2b..9529d5cc29 100644 --- a/trytond/backend/postgresql/database.py +++ b/trytond/backend/postgresql/database.py @@ -70,8 +70,8 @@ class Database(DatabaseInterface): name = "dbname=%s" % self.database_name user = uri.username and "user=%s" % uri.username or '' password = uri.password and "password=%s" % uri.password or '' - minconn = config.getint('database', 'minconn', 1) - maxconn = config.getint('database', 'maxconn', 64) + minconn = config.getint('database', 'minconn', default=1) + maxconn = config.getint('database', 'maxconn', default=64) dsn = '%s %s %s %s %s' % (host, port, name, user, password) self._connpool = ThreadedConnectionPool(minconn, maxconn, dsn) return self diff --git a/trytond/config.py b/trytond/config.py index ff563062b7..46f5d1f1da 100644 --- a/trytond/config.py +++ b/trytond/config.py @@ -69,30 +69,37 @@ class TrytonConfigParser(ConfigParser.RawConfigParser): return self.read(configfile) - def get(self, section, option, default=None): + def get(self, section, option, *args, **kwargs): + default = kwargs.pop('default', None) try: - return ConfigParser.RawConfigParser.get(self, section, option) + return ConfigParser.RawConfigParser.get(self, section, option, + *args, **kwargs) except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): return default - def getint(self, section, option, default=None): + def getint(self, section, option, *args, **kwargs): + default = kwargs.pop('default', None) try: - return ConfigParser.RawConfigParser.getint(self, section, option) + return ConfigParser.RawConfigParser.getint(self, section, option, + *args, **kwargs) except (ConfigParser.NoOptionError, ConfigParser.NoSectionError, TypeError): return default - def getfloat(self, section, option, default=None): + def getfloat(self, section, option, *args, **kwargs): + default = kwargs.pop('default', None) try: - return ConfigParser.RawConfigParser.getfloat(self, section, option) + return ConfigParser.RawConfigParser.getfloat(self, section, option, + *args, **kwargs) except (ConfigParser.NoOptionError, ConfigParser.NoSectionError, TypeError): return default - def getboolean(self, section, option, default=None): + def getboolean(self, section, option, *args, **kwargs): + default = kwargs.pop('default', None) try: return ConfigParser.RawConfigParser.getboolean( - self, section, option) + self, section, option, *args, **kwargs) except (ConfigParser.NoOptionError, ConfigParser.NoSectionError, AttributeError): return default