From bcc7692e14b7b695f08dfb39aaccf3dbfa67d857 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sat, 14 Jan 2017 23:18:06 +0100 Subject: [PATCH] Add safeGetInt to BMConfigParser --- src/configparser.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/configparser.py b/src/configparser.py index 7a4258be..ac70cee4 100644 --- a/src/configparser.py +++ b/src/configparser.py @@ -27,6 +27,14 @@ class BMConfigParser(ConfigParser.SafeConfigParser): return False return False + def safeGetInt(self, section, field): + if self.has_option(section, field): + try: + return self.getint(section, field) + except ValueError: + return 0 + return 0 + def safeGet(self, section, option, default = None): if self.has_option(section, option): return self.get(section, option)