From 45f7ab81a78e9d8d8b4b74a1f04122c6af9d061c Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Tue, 14 Sep 2010 12:54:32 +0000
Subject: [PATCH] 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
---
 .../SearchText/SearchTextParser.py            | 30 ++++++++++++-------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/product/ZSQLCatalog/SearchText/SearchTextParser.py b/product/ZSQLCatalog/SearchText/SearchTextParser.py
index b29acf7279..e75581af1e 100755
--- a/product/ZSQLCatalog/SearchText/SearchTextParser.py
+++ b/product/ZSQLCatalog/SearchText/SearchTextParser.py
@@ -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):
+@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
 
-@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='='):
-- 
2.30.9