Add untested has_option

This commit is contained in:
Florian Bruhin 2014-04-07 17:53:57 +02:00
parent 30c18579f2
commit 1258a466dd
2 changed files with 13 additions and 0 deletions

View File

@ -160,6 +160,10 @@ class Config:
lines.append(keyval)
return lines
def has_option(section, option):
"""Returns True if option is in section."""
return option in self.config[section]
@cmdutils.register(instance='config', completion=['setting'])
def get(self, section, option, fallback=_UNSET, raw=False):
"""Get the value from a section/option.

View File

@ -85,6 +85,10 @@ class KeyValue:
"""Get boolean state."""
return bool(self.values)
def __contains__(self, key):
"""Return whether the section contains a given key."""
return key in self.values
def items(self):
"""Get dict item tuples."""
return self.values.items()
@ -164,6 +168,11 @@ class ValueList:
self.update_valdict()
return bool(self.valdict)
def __contains__(self, key):
"""Return whether the section contains a given key."""
self.update_valdict()
return key in self.valdict
def items(self):
"""Get dict items."""
self.update_valdict()