[Checkins] SVN: Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ Added directive validation. Added some tests. README needs more text and a nicer presentation.

Souheil CHELFOUH souheil at chelfouh.com
Sat Dec 19 20:15:42 EST 2009


Log message for revision 106791:
  Added directive validation. Added some tests. README needs more text and a nicer presentation.
  

Changed:
  U   Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/README.txt
  U   Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/directive.py

-=-
Modified: Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/README.txt
===================================================================
--- Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/README.txt	2009-12-20 01:09:23 UTC (rev 106790)
+++ Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/README.txt	2009-12-20 01:15:41 UTC (rev 106791)
@@ -110,6 +110,8 @@
   </head></html>
 
 
+No hash:
+
   >>> from megrok.resource import use_hash
   >>> use_hash.set(SomeCSS, False)
   
@@ -119,3 +121,18 @@
     <link rel="stylesheet" type="text/css" href="http://localhost/@@/somecss/a.css" />
     <link rel="stylesheet" type="text/css" href="http://localhost/@@/somecss/b.css" />
   </head></html>
+
+
+Failing validation:
+
+  >>> toto = object()
+
+  >>> class FailingView(view.View):
+  ...   grok.context(SiteManagerContainer)
+  ...   include(toto)
+  ...
+  ...   def render(self):
+  ...	  return u""
+  Traceback (most recent call last):
+  ...
+  GrokImportError: You can only include IInclusions components.

Modified: Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/directive.py
===================================================================
--- Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/directive.py	2009-12-20 01:09:23 UTC (rev 106790)
+++ Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/directive.py	2009-12-20 01:15:41 UTC (rev 106791)
@@ -1,8 +1,16 @@
 # -*- coding: utf-8 -*-
 
 import martian
+from martian.error import GrokImportError
+from hurry.resource.interfaces import IInclusion
 
 
+def validateInclusion(directive, value):
+    if not IInclusion.providedBy(value):
+        raise GrokImportError(
+            "You can only include IInclusions components.")
+
+
 class use_hash(martian.Directive):
     scope = martian.CLASS_OR_MODULE
     store = martian.ONCE
@@ -15,6 +23,4 @@
 class include(martian.Directive):
     scope = martian.CLASS
     store = martian.MULTIPLE
-    
-    def factory(self, resource):
-        return resource
+    validate = validateInclusion



More information about the checkins mailing list