configfile: Make getlists return an empty list on empty string. (#6042)
Signed-off-by: Jordan Woyak <jordan.woyak@gmail.com>
This commit is contained in:
parent
df1137ef75
commit
1e7057e917
|
@ -80,11 +80,15 @@ class ConfigWrapper:
|
||||||
def getlists(self, option, default=sentinel, seps=(',',), count=None,
|
def getlists(self, option, default=sentinel, seps=(',',), count=None,
|
||||||
parser=str, note_valid=True):
|
parser=str, note_valid=True):
|
||||||
def lparser(value, pos):
|
def lparser(value, pos):
|
||||||
|
if len(value.strip()) == 0:
|
||||||
|
# Return an empty list instead of [''] for empty string
|
||||||
|
parts = []
|
||||||
|
else:
|
||||||
|
parts = [p.strip() for p in value.split(seps[pos])]
|
||||||
if pos:
|
if pos:
|
||||||
# Nested list
|
# Nested list
|
||||||
parts = [p.strip() for p in value.split(seps[pos])]
|
|
||||||
return tuple([lparser(p, pos - 1) for p in parts if p])
|
return tuple([lparser(p, pos - 1) for p in parts if p])
|
||||||
res = [parser(p.strip()) for p in value.split(seps[pos])]
|
res = [parser(p) for p in parts]
|
||||||
if count is not None and len(res) != count:
|
if count is not None and len(res) != count:
|
||||||
raise error("Option '%s' in section '%s' must have %d elements"
|
raise error("Option '%s' in section '%s' must have %d elements"
|
||||||
% (option, self.section, count))
|
% (option, self.section, count))
|
||||||
|
|
Loading…
Reference in New Issue