changeset 907:bb813ef5fe25 experimental-inline

inline branch: merged r1129 from trunk.
author cmlenz
date Wed, 28 Apr 2010 21:36:59 +0000
parents be8d2d828be6
children
files genshi/core.py genshi/template/directives.py
diffstat 2 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/genshi/core.py
+++ b/genshi/core.py
@@ -379,14 +379,19 @@
 
     def __or__(self, attrs):
         """Return a new instance that contains the attributes in `attrs` in
-        addition to any already existing attributes.
+        addition to any already existing attributes. Any attributes in the new
+        set that have a value of `None` are removed.
         
         :return: a new instance with the merged attributes
         :rtype: `Attrs`
         """
-        repl = dict([(an, av) for an, av in attrs if an in self])
-        return Attrs([(sn, repl.get(sn, sv)) for sn, sv in self] +
-                     [(an, av) for an, av in attrs if an not in self])
+        remove = set([an for an, av in attrs if av is None])
+        replace = dict([(an, av) for an, av in attrs
+                        if an in self and av is not None])
+        return Attrs([(sn, replace.get(sn, sv)) for sn, sv in self
+                      if sn not in remove] +
+                     [(an, av) for an, av in attrs
+                      if an not in self and an not in remove])
 
     def __repr__(self):
         if not self:
@@ -507,7 +512,7 @@
         if type(text) is cls:
             return text
         if hasattr(text, '__html__'):
-            return Markup(text.__html__())
+            return cls(text.__html__())
 
         text = text.replace('&', '&') \
                    .replace('<', '&lt;') \
--- a/genshi/template/directives.py
+++ b/genshi/template/directives.py
@@ -175,9 +175,10 @@
                         attrs = []
                 elif not isinstance(attrs, list): # assume it's a dict
                     attrs = attrs.items()
-                attrib -= [name for name, val in attrs if val is None]
-                attrib |= [(QName(name), unicode(val).strip()) for name, val
-                           in attrs if val is not None]
+                attrib |= [
+                    (QName(n), v is not None and unicode(v).strip() or None)
+                    for n, v in attrs
+                ]
             yield kind, (tag, attrib), pos
             for event in stream:
                 yield event
Copyright (C) 2012-2017 Edgewall Software