Commit 45f7ab81 authored by Vincent Pelletier's avatar Vincent Pelletier

Move code catching parsing errors in a decorator function.

Also, document why this code is present.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38357 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b5312013
...@@ -65,28 +65,36 @@ def getAdvancedSearchTextParser(): ...@@ -65,28 +65,36 @@ def getAdvancedSearchTextParser():
parser_pool.parser = parser parser_pool.parser = parser
return parser return parser
def safeParsingDecorator(func):
"""
Wrapper hiding parsing errors and returning None when they occur.
This is used to fallback to plain value when value was erroneously detected
as being valid SearchableText (detector is not perfect for speed sake).
"""
def wrapper(*args, **kw):
try:
result = func(*args, **kw)
except (KeyboardInterrupt, SystemExit):
raise
except:
result = None
return result
wrapper.__name__ = func.__name__
return wrapper
@profiler_decorator @profiler_decorator
def isAdvancedSearchText(input, is_column): def isAdvancedSearchText(input, is_column):
return getAdvancedSearchTextDetector()(input, is_column) return getAdvancedSearchTextDetector()(input, is_column)
@profiler_decorator @profiler_decorator
def _parse(input, is_column, *args, **kw): @safeParsingDecorator
def parse(input, is_column, *args, **kw):
if isAdvancedSearchText(input, is_column): if isAdvancedSearchText(input, is_column):
result = getAdvancedSearchTextParser()(input, is_column, *args, **kw) result = getAdvancedSearchTextParser()(input, is_column, *args, **kw)
else: else:
result = None result = None
return result return result
@profiler_decorator
def parse(*args, **kw):
try:
result = _parse(*args, **kw)
except (KeyboardInterrupt, SystemExit):
raise
except:
result = None
return result
if __name__ == '__main__': if __name__ == '__main__':
class Query: class Query:
def __init__(self, column, value, comparison_operator='='): def __init__(self, column, value, comparison_operator='='):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment