[Erp5-report] r38357 vincent - /erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Sep 14 14:54:34 CEST 2010
Author: vincent
Date: Tue Sep 14 14:54:32 2010
New Revision: 38357
URL: http://svn.erp5.org?rev=38357&view=rev
Log:
Move code catching parsing errors in a decorator function.
Also, document why this code is present.
Modified:
erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py
Modified: erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py?rev=38357&r1=38356&r2=38357&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py [utf8] Tue Sep 14 14:54:32 2010
@@ -65,28 +65,36 @@ def getAdvancedSearchTextParser():
parser_pool.parser = 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
def isAdvancedSearchText(input, is_column):
return getAdvancedSearchTextDetector()(input, is_column)
@profiler_decorator
-def _parse(input, is_column, *args, **kw):
+ at safeParsingDecorator
+def parse(input, is_column, *args, **kw):
if isAdvancedSearchText(input, is_column):
result = getAdvancedSearchTextParser()(input, is_column, *args, **kw)
else:
result = None
return result
- at profiler_decorator
-def parse(*args, **kw):
- try:
- result = _parse(*args, **kw)
- except (KeyboardInterrupt, SystemExit):
- raise
- except:
- result = None
- return result
-
if __name__ == '__main__':
class Query:
def __init__(self, column, value, comparison_operator='='):
More information about the Erp5-report
mailing list