[Checkins] SVN: grok/branches/faassen-index/src/grok/ Raise the right kind of exception if we misuse indexes.

Martijn Faassen faassen at infrae.com
Fri Apr 20 11:13:07 EDT 2007


Log message for revision 74265:
  Raise the right kind of exception if we misuse indexes.
  

Changed:
  A   grok/branches/faassen-index/src/grok/ftests/catalog/indexes_module.py
  U   grok/branches/faassen-index/src/grok/index.py

-=-
Added: grok/branches/faassen-index/src/grok/ftests/catalog/indexes_module.py
===================================================================
--- grok/branches/faassen-index/src/grok/ftests/catalog/indexes_module.py	2007-04-20 15:03:40 UTC (rev 74264)
+++ grok/branches/faassen-index/src/grok/ftests/catalog/indexes_module.py	2007-04-20 15:13:07 UTC (rev 74265)
@@ -0,0 +1,16 @@
+"""
+You can create an index on module level, but that should lead to a GrokError:
+
+  >>> import grok
+  >>> from grok.ftests.catalog.indexes_module import func
+  >>> func()
+  Traceback (most recent call last):
+    ...
+  GrokImportError: <class 'grok.index.Field'> can only be instantiated on
+  class level.
+"""
+from grok import index
+
+def func():
+    foo = index.Field()
+    

Modified: grok/branches/faassen-index/src/grok/index.py
===================================================================
--- grok/branches/faassen-index/src/grok/index.py	2007-04-20 15:03:40 UTC (rev 74264)
+++ grok/branches/faassen-index/src/grok/index.py	2007-04-20 15:13:07 UTC (rev 74265)
@@ -6,7 +6,7 @@
 from zope.app.catalog.field import FieldIndex
 from zope.app.catalog.text import TextIndex
 
-from grok.error import GrokError
+from grok.error import GrokError, GrokImportError
 from grok.directive import frame_is_class
 from grok.interfaces import IIndexDefinition
 
@@ -18,7 +18,8 @@
     def __init__(self, *args, **kw):
         frame = sys._getframe(1)
         if not frame_is_class(frame):
-            raise GrokError('Index definition can only be used on a class.')
+            raise GrokImportError(
+                "%r can only be instantiated on class level." % self.__class__)
         # store any extra parameters to pass to index later
         self._args = args
         self._kw = kw



More information about the Checkins mailing list