Config: Prevent variable creation when trying to get the value of a channel-specific variable for a non-channel.

This commit is contained in:
Valentin Lorentz 2014-05-31 20:44:56 +02:00
parent fd2ecf0dec
commit b14ed2c5d9
2 changed files with 9 additions and 6 deletions

View File

@ -54,12 +54,12 @@ def getWrapper(name):
raise registry.InvalidRegistryName(name) raise registry.InvalidRegistryName(name)
group = getattr(conf, parts.pop(0)) group = getattr(conf, parts.pop(0))
while parts: while parts:
try: part = parts.pop(0)
group = group.get(parts.pop(0)) if group.__hasattr__(part):
# We'll catch registry.InvalidRegistryName and re-raise it here so group = group.get(part)
# that we have a useful error message for the user. else:
except (registry.NonExistentRegistryEntry, # We'll raise registry.InvalidRegistryName here so
registry.InvalidRegistryName): # that we have a useful error message for the user.
raise registry.InvalidRegistryName(name) raise registry.InvalidRegistryName(name)
return group return group

View File

@ -214,6 +214,9 @@ class Group(object):
self.register(attr, v) self.register(attr, v)
return v return v
def __hasattr__(self, attr):
return attr in self._children
def __getattr__(self, attr): def __getattr__(self, attr):
if attr in self._children: if attr in self._children:
return self._children[attr] return self._children[attr]