# HG changeset patch # User cmlenz # Date 1272490619 0 # Node ID bb813ef5fe252159b968a68b6328d660603ed67a # Parent be8d2d828be66adfb983d026909253e2ec3852a4 inline branch: merged r1129 from trunk. diff --git a/genshi/core.py b/genshi/core.py --- 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('<', '<') \ diff --git a/genshi/template/directives.py b/genshi/template/directives.py --- 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