[Checkins] SVN: grokcore.view/trunk/ Add validator to templatedir directive to disallow path separator

Vincent Fretin vincent.fretin at gmail.com
Fri Jul 3 08:22:22 EDT 2009


Log message for revision 101437:
  Add validator to templatedir directive to disallow path separator

Changed:
  U   grokcore.view/trunk/CHANGES.txt
  U   grokcore.view/trunk/src/grokcore/view/directive.py
  A   grokcore.view/trunk/src/grokcore/view/tests/view/templatedirectory_with_path_sep.py
  A   grokcore.view/trunk/src/grokcore/view/tests/view/templatedirectory_with_path_sep_fixture.py

-=-
Modified: grokcore.view/trunk/CHANGES.txt
===================================================================
--- grokcore.view/trunk/CHANGES.txt	2009-07-03 12:11:47 UTC (rev 101436)
+++ grokcore.view/trunk/CHANGES.txt	2009-07-03 12:22:22 UTC (rev 101437)
@@ -4,7 +4,7 @@
 1.8 (unreleased)
 ----------------
 
-- Nothing changed yet.
+- Add validator to templatedir directive to disallow path separator.
 
 
 1.7 (2009-05-19)

Modified: grokcore.view/trunk/src/grokcore/view/directive.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/directive.py	2009-07-03 12:11:47 UTC (rev 101436)
+++ grokcore.view/trunk/src/grokcore/view/directive.py	2009-07-03 12:22:22 UTC (rev 101437)
@@ -13,11 +13,20 @@
 ##############################################################################
 """Grok directives.
 """
+import os.path
+
 import martian
 from martian.error import GrokImportError
 from martian.directive import StoreOnce
 from zope.interface.interface import TAGGED_DATA
 
+
+def validateLocalPath(directive, value):
+    martian.validateText(directive, value)
+    if os.path.sep in value:
+        raise GrokImportError("The '%s' directive can not contain path separator."
+                               % directive.name)
+
 # Define grok directives
 class template(martian.Directive):
     scope = martian.CLASS
@@ -27,7 +36,7 @@
 class templatedir(martian.Directive):
     scope = martian.MODULE
     store = martian.ONCE
-    validate = martian.validateText
+    validate = validateLocalPath
 
 class OneInterfaceOrClassOnClassOrModule(martian.Directive):
     """Convenience base class.  Not for public use."""

Added: grokcore.view/trunk/src/grokcore/view/tests/view/templatedirectory_with_path_sep.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/tests/view/templatedirectory_with_path_sep.py	                        (rev 0)
+++ grokcore.view/trunk/src/grokcore/view/tests/view/templatedirectory_with_path_sep.py	2009-07-03 12:22:22 UTC (rev 101437)
@@ -0,0 +1,10 @@
+"""
+You can not use path separator in templatedir directive:
+
+  >>> import grokcore.view.tests.view.templatedirectory_with_path_sep_fixture
+  Traceback (most recent call last):
+    ...
+  GrokImportError: The 'templatedir' directive can not contain path separator.
+
+
+"""

Added: grokcore.view/trunk/src/grokcore/view/tests/view/templatedirectory_with_path_sep_fixture.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/tests/view/templatedirectory_with_path_sep_fixture.py	                        (rev 0)
+++ grokcore.view/trunk/src/grokcore/view/tests/view/templatedirectory_with_path_sep_fixture.py	2009-07-03 12:22:22 UTC (rev 101437)
@@ -0,0 +1,7 @@
+"""
+This should fail because you can not use path separator in templatedir directive.
+"""
+import grokcore.view as grok
+import os.path
+
+grok.templatedir('templatedirectoryname' + os.path.sep + 'subdirname')



More information about the Checkins mailing list