[Checkins] SVN: Sandbox/malthe/chameleon.html/ Added 'append' and 'prepend' insertion modes.

Malthe Borch mborch at gmail.com
Wed Oct 1 15:40:26 EDT 2008


Log message for revision 91654:
  Added 'append' and 'prepend' insertion modes.

Changed:
  U   Sandbox/malthe/chameleon.html/CHANGES.txt
  U   Sandbox/malthe/chameleon.html/README.txt
  U   Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
  U   Sandbox/malthe/chameleon.html/src/chameleon/html/xss.py

-=-
Modified: Sandbox/malthe/chameleon.html/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.html/CHANGES.txt	2008-10-01 19:29:37 UTC (rev 91653)
+++ Sandbox/malthe/chameleon.html/CHANGES.txt	2008-10-01 19:40:26 UTC (rev 91654)
@@ -4,6 +4,8 @@
 Head
 ~~~~
 
+- Added 'append' and 'prepend' insertion modes. [malthe]
+
 - Template is invalidated when XSS-files are modified. [malthe]
 
 - Added resource rebase support. [malthe]

Modified: Sandbox/malthe/chameleon.html/README.txt
===================================================================
--- Sandbox/malthe/chameleon.html/README.txt	2008-10-01 19:29:37 UTC (rev 91653)
+++ Sandbox/malthe/chameleon.html/README.txt	2008-10-01 19:40:26 UTC (rev 91654)
@@ -22,6 +22,7 @@
     name: document-heading;
     structure: true;
     attributes: document-attributes;
+    mode: content;
   }
 
 This rule will associate the <title> tag with the dynamic content
@@ -31,7 +32,16 @@
 See the file ``template.txt`` within the package for documentation on
 how to render templates and provide dynamic content and attributes.
 
+Syntax
+------
 
+Brief explanation of the properties in the XSS format::
+
+ @name        dynamic content slot name
+ @structure   if set to true, inserts content without escaping
+ @attributes  inserts dynamic attributes into tag
+ @mode        one of ('content', 'append', 'prepend') 
+
 Resource rebase functionality
 -----------------------------
 

Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/language.py	2008-10-01 19:29:37 UTC (rev 91653)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/language.py	2008-10-01 19:40:26 UTC (rev 91654)
@@ -223,9 +223,31 @@
                     selector.path, namespaces=rule.namespaces):
                     if rule.name:
                         self.slots.append(rule.name)
-                        element.attrib[
-                            '{http://namespaces.repoze.org/xss}content'] = \
-                            rule.name
+                               
+                        if rule.mode == 'content':
+                            element.attrib[
+                                '{http://namespaces.repoze.org/xss}content'] = \
+                                rule.name
+                        elif rule.mode == 'append':
+                            new = element.makeelement(
+                                utils.xhtml_attr('div'))
+                            new.attrib.update(
+                                {'{http://namespaces.repoze.org/xss}content': rule.name,
+                                 '{http://namespaces.repoze.org/xss}omit': 'true'})
+                            element.append(new)
+                            element = new
+                        elif rule.mode == 'prepend':
+                            new = element.makeelement(
+                                utils.xhtml_attr('div'))
+                            new.attrib.update(
+                                {'{http://namespaces.repoze.org/xss}content': rule.name,
+                                 '{http://namespaces.repoze.org/xss}omit': 'true'})
+                            element.insert(0, new)
+                            element = new
+                        else:
+                            raise ValueError(
+                                "Unsupported insertion mode: %s" % rule.mode)
+                            
                     if rule.structure:
                         element.attrib[
                             '{http://namespaces.repoze.org/xss}structure'] = \

Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/xss.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/xss.py	2008-10-01 19:29:37 UTC (rev 91653)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/xss.py	2008-10-01 19:40:26 UTC (rev 91654)
@@ -10,6 +10,7 @@
         self.namespaces = namespaces
         self.selector = selector
         self.name = name
+        self.mode = mode
         self.attributes = attributes
         self.structure = structure
 



More information about the Checkins mailing list