1
0
mirror of https://github.com/edgewall/genshi.git synced 2026-02-05 15:46:37 +01:00

inline branch: merged r1129 from trunk.

This commit is contained in:
Christopher Lenz
2010-04-28 21:36:59 +00:00
2 changed files with 14 additions and 8 deletions

View File

@@ -379,14 +379,19 @@ class Attrs(tuple):
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 @@ class Markup(unicode):
if type(text) is cls:
return text
if hasattr(text, '__html__'):
return Markup(text.__html__())
return cls(text.__html__())
text = text.replace('&', '&') \
.replace('<', '&lt;') \

View File

@@ -175,9 +175,10 @@ class AttrsDirective(Directive):
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