[Checkins] SVN: Sandbox/malthe/chameleon.core/ Changed handling of static attributes to allow foreign namespaces.
Malthe Borch
mborch at gmail.com
Mon Nov 24 11:40:29 EST 2008
Log message for revision 93318:
Changed handling of static attributes to allow foreign namespaces.
Changed:
U Sandbox/malthe/chameleon.core/CHANGES.txt
U Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py
U Sandbox/malthe/chameleon.core/src/chameleon/core/testing.py
U Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py
U Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py
-=-
Modified: Sandbox/malthe/chameleon.core/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.core/CHANGES.txt 2008-11-24 16:38:27 UTC (rev 93317)
+++ Sandbox/malthe/chameleon.core/CHANGES.txt 2008-11-24 16:40:29 UTC (rev 93318)
@@ -4,6 +4,10 @@
HEAD
~~~~
+- Static attributes are now computed such that attributes are omitted
+ according to a `ns_omit` flag, and they are always prefixed
+ according to the element's `nsmap`. [malthe]
+
- Do not fix-up self-closing tags if an XML declaration is present
without a DOCTYPE. [malthe]
Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py 2008-11-24 16:38:27 UTC (rev 93317)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/clauses.py 2008-11-24 16:40:29 UTC (rev 93318)
@@ -545,7 +545,7 @@
def __init__(self, tag, attributes=None, selfclosing=False,
expression=None, cdata=False, defaults={}):
- self.tag = tag.split('}')[-1]
+ self.tag = tag
self.defaults = defaults
self.selfclosing = selfclosing
self.attributes = attributes or {}
Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/testing.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/testing.py 2008-11-24 16:38:27 UTC (rev 93317)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/testing.py 2008-11-24 16:40:29 UTC (rev 93318)
@@ -59,11 +59,6 @@
return None
@property
- def static_attributes(self):
- return utils.get_attributes_from_namespace(
- self.element, config.XHTML_NS)
-
- @property
def omit(self):
if self.element.meta_omit is not None:
return self.element.meta_omit or True
Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py 2008-11-24 16:38:27 UTC (rev 93317)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py 2008-11-24 16:40:29 UTC (rev 93318)
@@ -42,9 +42,11 @@
include = None
format = None
dict_attributes = None
- static_attributes = utils.emptydict()
dynamic_attributes = utils.emptydict()
+ ns_omit = (
+ "http://xml.zope.org/namespaces/meta")
+
def __init__(self, element):
self.element = element
@@ -71,6 +73,23 @@
return (self.element.tail,)
@property
+ def static_attributes(self):
+ result = {}
+
+ for prefix, ns in self.element.nsmap.items():
+ if ns not in self.ns_omit:
+ attrs = utils.get_attributes_from_namespace(self.element, ns)
+ for tag, value in attrs.items():
+ name = tag.split('}')[-1]
+
+ if prefix:
+ result["%s:%s" % (prefix, name)] = value
+ else:
+ result[name] = value
+
+ return result
+
+ @property
def stream(self):
return self.element.stream
Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py 2008-11-24 16:38:27 UTC (rev 93317)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py 2008-11-24 16:40:29 UTC (rev 93318)
@@ -276,14 +276,20 @@
return map(self.get, self._keys)
def get_attributes_from_namespace(element, namespace):
- if element.nsmap.get(element.prefix, marker) in (namespace, marker):
- return dict([
+ if namespace is None:
+ attrs = dict([
(name, value) for (name, value) in element.attrib.items() \
if '{' not in name])
+ else:
+ attrs = dict([
+ (name, value) for (name, value) in element.attrib.items() \
+ if name.startswith('{%s}' % namespace)])
+
+ if namespace == config.XHTML_NS and element.prefix is None:
+ attrs.update(get_attributes_from_namespace(
+ element, None))
- return dict([
- (name, value) for (name, value) in element.attrib.items() \
- if name.startswith('{%s}' % namespace)])
+ return attrs
def get_namespace(element):
if '}' in element.tag:
More information about the Checkins
mailing list