add more user-friendly message on condition parsing error

This commit is contained in:
Christophe Benz 2010-06-21 17:50:50 +02:00
commit 2ed5c7f5e5

View file

@ -73,18 +73,21 @@ class ResultsCondition(object):
condition_str.replace('AND', 'and') condition_str.replace('AND', 'and')
condition_str.replace('NOT', 'not') condition_str.replace('NOT', 'not')
or_list = [] or_list = []
for _or in condition_str.split('or'): try:
and_dict = {} for _or in condition_str.split('or'):
for _and in _or.split('and'): and_dict = {}
if '!=' in _and: for _and in _or.split('and'):
k, v = _and.split('!=') if '!=' in _and:
k += '!' k, v = _and.split('!=')
elif '=' in _and: k += '!'
k, v = _and.split('=') elif '=' in _and:
else: k, v = _and.split('=')
raise ResultsConditionException(u'Could not find = or != operator in sub-expression "%s"' % _and) else:
and_dict[k] = v raise ResultsConditionException(u'Could not find = or != operator in sub-expression "%s"' % _and)
or_list.append(and_dict) and_dict[k] = v
or_list.append(and_dict)
except:
raise ResultsConditionException(u'Could not parse condition expression "%s"' % condition_str)
self.condition = or_list self.condition = or_list
def is_valid(self, d): def is_valid(self, d):