From 05a9366f7b6e22f07fd275f59cec591ab7c72c68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rg=20Lehmann?= Date: Fri, 13 May 2011 19:11:22 +0000 Subject: [PATCH] allow options without default git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@3061 069f4177-920e-0410-937b-c2a4a81bcd90 --- pyx/config.py | 57 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/pyx/config.py b/pyx/config.py index 284dd0de..6af7f4e5 100644 --- a/pyx/config.py +++ b/pyx/config.py @@ -23,40 +23,57 @@ import ConfigParser, os.path, warnings import siteconfig +class _marker: pass + cflist = [os.path.join(siteconfig.pyxrcdir, "pyxrc"), os.path.expanduser("~/.pyxrc")] config = ConfigParser.ConfigParser() config.read(cflist) -def get(section, option, default): - try: +def get(section, option, default=_marker): + if default is _marker: return config.get(section, option) - except: - return default + else: + try: + return config.get(section, option) + except ConfigParser.Error: + return default -def getint(section, option, default): - try: +def getint(section, option, default=_marker): + if default is _marker: return config.getint(section, option) - except: - return default + else: + try: + return config.getint(section, option) + except ConfigParser.Error: + return default -def getfloat(section, option, default): - try: +def getfloat(section, option, default=_marker): + if default is _marker: return config.getfloat(section, option) - except: - return default + else: + try: + return config.getfloat(section, option) + except ConfigParser.Error: + return default -def getboolean(section, option, default): - try: +def getboolean(section, option, default=_marker): + if default is _marker: return config.getboolean(section, option) - except: - return default + else: + try: + return config.getboolean(section, option) + except ConfigParser.Error: + return default -def getlist(section, option, default): - try: +def getlist(section, option, default=_marker): + if default is _marker: l = config.get(section, option).split() - except: - return default + else: + try: + l = config.get(section, option).split() + except ConfigParser.Error: + return default if space: l = [item.replace(space, ' ') for item in l] return l -- 2.11.4.GIT