Add ability to check for config keys using 'in'
This commit is contained in:
@@ -87,11 +87,10 @@ class Config(object):
|
|||||||
self.__dict__[section].__dict__[name] = vdefault
|
self.__dict__[section].__dict__[name] = vdefault
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
try:
|
return self.__dict__.__getitem__(key)
|
||||||
return getattr(self, key)
|
|
||||||
except AttributeError, e:
|
def __contains__(self, key):
|
||||||
raise KeyError(e)
|
return self.__dict__.__contains__(key)
|
||||||
|
|
||||||
|
|
||||||
def x2bool(s):
|
def x2bool(s):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ value = True
|
|||||||
def testGetItem(self):
|
def testGetItem(self):
|
||||||
cfg = Config(default=self.cfg_default)
|
cfg = Config(default=self.cfg_default)
|
||||||
assert(cfg["world"]["domination"] == False)
|
assert(cfg["world"]["domination"] == False)
|
||||||
|
assert("world" in cfg)
|
||||||
|
|
||||||
def invalidaccess(c):
|
def invalidaccess(c):
|
||||||
c["nointhisconfig"]
|
c["nointhisconfig"]
|
||||||
|
|||||||
Reference in New Issue
Block a user