From c76a8c5499d22b9c0b4c56f03b671033eb9f9bdd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 8 Dec 2009 19:52:48 +0100 Subject: config.get_value: Added default argument including test --- lib/git/config.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/git/config.py') diff --git a/lib/git/config.py b/lib/git/config.py index 2f567559..1739e786 100644 --- a/lib/git/config.py +++ b/lib/git/config.py @@ -347,13 +347,21 @@ class GitConfigParser(cp.RawConfigParser, LockFile): """ return self._read_only - def get_value(self, section, option): + def get_value(self, section, option, default = None): """ + ``default`` + If not None, the given default value will be returned in case + the option did not exist Returns a properly typed value, either int, float or string Raises TypeError in case the value could not be understood + Otherwise the exceptions known to the ConfigParser will be raised. """ - valuestr = self.get(section, option) + try: + valuestr = self.get(section, option) + except Exception: + return default + types = ( long, float ) for numtype in types: try: -- cgit v1.2.1