find raises an exception if no option found Fixes #4721
This commit is contained in:
@ -540,7 +540,10 @@ class Config(object):
|
||||
|
||||
def _find(self, bytype, byname, byvalue, byattrs, first):
|
||||
"""
|
||||
:param first: return only one option if True, a list otherwise
|
||||
convenience method for finding an option that lives only in the subtree
|
||||
|
||||
:param first: return only one option if True, a list otherwise
|
||||
:return: find list or an exception if nothing has been found
|
||||
"""
|
||||
def _filter_by_attrs():
|
||||
if byattrs is None:
|
||||
@ -549,8 +552,11 @@ class Config(object):
|
||||
if not hasattr(option, key):
|
||||
return False
|
||||
else:
|
||||
if getattr(option, key) != value:
|
||||
return False
|
||||
try:
|
||||
if getattr(option, key) != value:
|
||||
return False
|
||||
except:
|
||||
pass # a property restricts the access of the value
|
||||
else:
|
||||
continue
|
||||
return True
|
||||
@ -569,7 +575,7 @@ class Config(object):
|
||||
value = getattr(self, path)
|
||||
if value == byvalue:
|
||||
return True
|
||||
except Exception, e: # a property restricts the acces to value
|
||||
except: # a property restricts the access of the value
|
||||
pass
|
||||
return False
|
||||
def _filter_by_type():
|
||||
@ -595,8 +601,9 @@ class Config(object):
|
||||
return option
|
||||
else:
|
||||
find_results.append(option)
|
||||
if first:
|
||||
return None
|
||||
|
||||
if find_results == []:
|
||||
raise NotFoundError("no option found in config with these criteria")
|
||||
else:
|
||||
return find_results
|
||||
|
||||
|
Reference in New Issue
Block a user