[Checkins] SVN: Sandbox/malthe/chameleon.html/src/chameleon/html/ Make slots and attribute identifiers available on the parser instance, and store the parser on the instantiated template.

Malthe Borch mborch at gmail.com
Thu Sep 25 22:54:32 EDT 2008


Log message for revision 91497:
  Make slots and attribute identifiers available on the parser instance, and store the parser on the instantiated template.

Changed:
  U   Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
  U   Sandbox/malthe/chameleon.html/src/chameleon/html/template.py

-=-
Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/language.py	2008-09-26 02:07:28 UTC (rev 91496)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/language.py	2008-09-26 02:54:32 UTC (rev 91497)
@@ -180,12 +180,22 @@
         config.META_NS: {None: MetaElement}}
 
 class DynamicHTMLParser(XSSTemplateParser):
+    slots = attributes = ()
+    
     def __init__(self, filename):
         self.path = os.path.dirname(filename)
+
+        # parse the body at initialization to fill the slots and
+        # attributes lists
+        self.parse(file(filename).read())
         
     def parse(self, body):
         root, doctype = super(DynamicHTMLParser, self).parse(body)
 
+        # reset dynamic identifier lists
+        self.slots = []
+        self.attributes = []
+        
         # process dynamic rules
         links = root.xpath(
             './/xmlns:link[@rel="xss"]', namespaces={'xmlns': config.XHTML_NS})
@@ -208,6 +218,7 @@
                 for element in root.xpath(
                     selector.path, namespaces=rule.namespaces):
                     if rule.name:
+                        self.slots.append(rule.name)
                         element.attrib[
                             '{http://namespaces.repoze.org/xss}content'] = \
                             rule.name
@@ -216,6 +227,7 @@
                             '{http://namespaces.repoze.org/xss}structure'] = \
                             rule.structure
                     if rule.attributes:
+                        self.attributes.append(rule.attributes)
                         element.attrib[
                             '{http://namespaces.repoze.org/xss}attributes'] = \
                             rule.attributes

Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/template.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/template.py	2008-09-26 02:07:28 UTC (rev 91496)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/template.py	2008-09-26 02:54:32 UTC (rev 91497)
@@ -4,10 +4,10 @@
 
 class DynamicHTMLFile(template.TemplateFile):
     def __init__(self, filename, **kwargs):
-        parser = language.DynamicHTMLParser(filename)
+        parser = self.parser = language.DynamicHTMLParser(filename)
         super(DynamicHTMLFile, self).__init__(
             filename, parser, **kwargs)
 
     def render(self, content={}, attributes={}, **kwargs):
         return template.TemplateFile.render(
-            self, content=content, attributes=attributes, **kwargs) 
+            self, content=content, attributes=attributes, **kwargs)



More information about the Checkins mailing list