From 6071a857874475069b521ee51aed5b1bf0c67607 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Tue, 18 Feb 2014 16:51:04 +0100 Subject: [PATCH] add `Config.getlist` method --- isso/core.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/isso/core.py b/isso/core.py index 4b1e872..bb0c1eb 100644 --- a/isso/core.py +++ b/isso/core.py @@ -44,6 +44,9 @@ class Section: def getint(self, key): return self.conf.getint(self.section, key) + def getlist(self, key): + return self.conf.getlist(self.section, key) + def getiter(self, key): return self.conf.getiter(self.section, key) @@ -62,6 +65,7 @@ class IssoParser(ConfigParser): ... [foo] ... bar = 1h ... baz = 12 + ... spam = a, b, cdef ... bla = ... spam ... ham @@ -71,6 +75,8 @@ class IssoParser(ConfigParser): 3600 >>> parser.getint("foo", "baz") 12 + >>> parser.getlist("foo", "spam") # doctest: +IGNORE_UNICODE + ['a', 'b', 'cdef'] >>> list(parser.getiter("foo", "bla")) # doctest: +IGNORE_UNICODE ['spam', 'ham'] >>> list(parser.getiter("foo", "asd")) # doctest: +IGNORE_UNICODE @@ -92,6 +98,9 @@ class IssoParser(ConfigParser): except AttributeError: return int(IssoParser._total_seconds(delta)) + def getlist(self, section, key): + return list(map(str.strip, self.get(section, key).split(','))) + def getiter(self, section, key): for item in map(str.strip, self.get(section, key).split('\n')): if item: