[Checkins] SVN: Sandbox/malthe/chameleon.html/ Fixed namespace handling.

Malthe Borch mborch at gmail.com
Tue Dec 2 10:36:10 EST 2008


Log message for revision 93546:
  Fixed namespace handling.

Changed:
  U   Sandbox/malthe/chameleon.html/CHANGES.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-12-02 14:53:27 UTC (rev 93545)
+++ Sandbox/malthe/chameleon.html/CHANGES.txt	2008-12-02 15:36:10 UTC (rev 93546)
@@ -4,6 +4,9 @@
 HEAD
 ~~~~
 
+- Fixed namespace handling; the XML parser now makes sure that the
+  default namespace gets registered as such. [malthe]
+
 chameleon.html 0.7 (released 11/19/2008)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/language.py	2008-12-02 14:53:27 UTC (rev 93545)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/language.py	2008-12-02 15:36:10 UTC (rev 93546)
@@ -259,9 +259,9 @@
                 new.tail = "\n"
                 tag = new
                 
-    def glob_resources(self, root, attribute, xpath, ns={}):
+    def glob_resources(self, root, attribute, xpath):
         """Resource globbing"""
-        tags = root.xpath(xpath, namespaces=ns)
+        tags = root.xpath(xpath)
         for tag in tags:
             href = tag.attrib.get(attribute)
             matches = glob.glob(os.path.join(self.path, href))
@@ -281,19 +281,20 @@
         self.attributes = []
 
         # process possible resource globbing
-        self.glob_resources(root, "href", './/xmlns:link', ns={'xmlns': config.XHTML_NS})
-        self.glob_resources(root, "src", './/xmlns:script', ns={'xmlns': config.XHTML_NS})
+        self.glob_resources(
+            root, "href", './/link')
+        self.glob_resources(
+            root, "src", './/script')
 
         # process dynamic rules
-        links = root.xpath(
-            './/xmlns:link[@rel="xss"]', namespaces={'xmlns': config.XHTML_NS})
-
+        links = root.xpath('.//link[@rel="xss"]')
         for link in links:
             try:
                 href = link.attrib['href']
             except KeyError:
                 raise AttributeError(
-                    "Attribute missing from tag: 'href' (line %d)." % link.sourceline)
+                    "Attribute missing from tag: "
+                    "'href' (line %d)." % link.sourceline)
 
             filename = os.path.join(self.path, href)
             if not os.path.exists(filename):
@@ -356,8 +357,7 @@
 
         # prepare reference rebase logic
         elements = root.xpath(
-            './/xmlns:link[@href] | .//xmlns:img[@src] | .//xmlns:script[@src]',
-            namespaces={'xmlns': config.XHTML_NS})
+            './/link[@href] | .//img[@src] | .//script[@src]')
         for element in elements:
             href = element.attrib.get('href')
             if href is not None:
@@ -365,8 +365,7 @@
             src = element.attrib.get('src')
             if src is not None:
                 element.attrib['{http://namespaces.repoze.org/xss}rebase'] = 'src'
-        elements = root.xpath(
-            './/xmlns:style', namespaces={'xmlns': config.XHTML_NS})
+        elements = root.xpath('.//style')
         for element in elements:
             for comment in element:
                 text = comment.text

Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/xss.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/xss.py	2008-12-02 14:53:27 UTC (rev 93545)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/xss.py	2008-12-02 15:36:10 UTC (rev 93546)
@@ -39,7 +39,10 @@
             for item in selector.seq:
                 if item.type == 'type-selector':
                     extra, name = item.value
-                    selectors.append('%s|%s' % (namespace, name))
+                    if name.lower() == 'html':
+                        selectors.append('%s|%s' % (namespace, name))
+                    else:
+                        selectors.append(name)
                 else:
                     selectors.append(item.value)
             selector = "".join(selectors)



More information about the Checkins mailing list