Add ability to check for config keys using 'in'

This commit is contained in:
Stefan Hacker
2013-02-25 10:08:19 +01:00
parent 1aac7ac6df
commit 4a42e01f36
2 changed files with 5 additions and 5 deletions

View File

@@ -87,11 +87,10 @@ class Config(object):
self.__dict__[section].__dict__[name] = vdefault
def __getitem__(self, key):
try:
return getattr(self, key)
except AttributeError, e:
raise KeyError(e)
return self.__dict__.__getitem__(key)
def __contains__(self, key):
return self.__dict__.__contains__(key)
def x2bool(s):
"""

View File

@@ -134,6 +134,7 @@ value = True
def testGetItem(self):
cfg = Config(default=self.cfg_default)
assert(cfg["world"]["domination"] == False)
assert("world" in cfg)
def invalidaccess(c):
c["nointhisconfig"]