in __setattr__, name should never be object's variable name
remove context in type_ find's option find_first_context return AttributError if no results
This commit is contained in:
@ -96,7 +96,6 @@ class SubConfig(BaseInformation):
|
||||
try:
|
||||
yield child._name, getattr(self, child._name)
|
||||
except GeneratorExit:
|
||||
raise Exception('ca passe ici')
|
||||
raise StopIteration
|
||||
except PropertiesOptionError:
|
||||
pass # option with properties
|
||||
@ -175,7 +174,6 @@ class SubConfig(BaseInformation):
|
||||
def __setattr__(self, name, value):
|
||||
"attribute notation mechanism for the setting of the value of an option"
|
||||
if name.startswith('_impl_'):
|
||||
#self.__dict__[name] = value
|
||||
object.__setattr__(self, name, value)
|
||||
return
|
||||
self._setattr(name, value)
|
||||
@ -222,17 +220,12 @@ class SubConfig(BaseInformation):
|
||||
return homeconfig._getattr(name, force_permissive=force_permissive,
|
||||
force_properties=force_properties,
|
||||
validate=validate)
|
||||
# special attributes
|
||||
if name.startswith('_impl_') or name.startswith('cfgimpl_') \
|
||||
or name.startswith('impl_'):
|
||||
# if it were in __dict__ it would have been found already
|
||||
return object.__getattribute__(self, name)
|
||||
opt_or_descr = getattr(self.cfgimpl_get_description(), name)
|
||||
# symlink options
|
||||
if self._impl_path is None:
|
||||
subpath = name
|
||||
else:
|
||||
subpath = self._impl_path + '.' + name
|
||||
# symlink options
|
||||
if isinstance(opt_or_descr, SymLinkOption):
|
||||
context = self.cfgimpl_get_context()
|
||||
path = context.cfgimpl_get_description().impl_get_path_by_opt(
|
||||
@ -318,18 +311,7 @@ class SubConfig(BaseInformation):
|
||||
return True
|
||||
return False
|
||||
|
||||
#def _filter_by_attrs():
|
||||
# if byattrs is None:
|
||||
# return True
|
||||
# for key, val in byattrs.items():
|
||||
# print "----", path, key
|
||||
# if path == key or path.endswith('.' + key):
|
||||
# if value == val:
|
||||
# return True
|
||||
# else:
|
||||
# return False
|
||||
# return False
|
||||
if type_ not in ('option', 'path', 'context', 'value'):
|
||||
if type_ not in ('option', 'path', 'value'):
|
||||
raise ValueError(_('unknown type_ type {0}'
|
||||
'for _find').format(type_))
|
||||
find_results = []
|
||||
@ -354,26 +336,25 @@ class SubConfig(BaseInformation):
|
||||
continue
|
||||
if not _filter_by_type():
|
||||
continue
|
||||
#if not _filter_by_attrs():
|
||||
# continue
|
||||
if type_ == 'value':
|
||||
retval = value
|
||||
elif type_ == 'path':
|
||||
retval = path
|
||||
elif type_ == 'option':
|
||||
retval = option
|
||||
elif type_ == 'context':
|
||||
retval = self.cfgimpl_get_context()
|
||||
if first:
|
||||
return retval
|
||||
else:
|
||||
find_results.append(retval)
|
||||
return self._find_return_results(find_results, display_error)
|
||||
|
||||
def _find_return_results(self, find_results, display_error):
|
||||
if find_results == []:
|
||||
if display_error:
|
||||
raise AttributeError(_("no option found in config"
|
||||
" with these criteria"))
|
||||
else:
|
||||
#translation is slow
|
||||
# translation is slow
|
||||
raise AttributeError()
|
||||
else:
|
||||
return find_results
|
||||
@ -620,14 +601,15 @@ class MetaConfig(CommonConfig):
|
||||
pass
|
||||
|
||||
def find_first_contexts(self, byname=None, bypath=None, byvalue=None,
|
||||
type_='context', display_error=True):
|
||||
type_='path', display_error=True):
|
||||
ret = []
|
||||
try:
|
||||
if bypath is None and byname is not None and \
|
||||
self.cfgimpl_get_description() is not None:
|
||||
bypath = self._find(bytype=None, byvalue=None, byname=byname,
|
||||
first=True, type_='path',
|
||||
check_properties=False)
|
||||
check_properties=False,
|
||||
display_error=display_error)
|
||||
except ConfigError:
|
||||
pass
|
||||
for child in self._impl_children:
|
||||
@ -654,7 +636,7 @@ class MetaConfig(CommonConfig):
|
||||
display_error=False))
|
||||
except AttributeError:
|
||||
pass
|
||||
return ret
|
||||
return self._find_return_results(ret, display_error)
|
||||
|
||||
|
||||
def mandatory_warnings(config):
|
||||
|
Reference in New Issue
Block a user