From 4c4dcf7a020ed52ea9d8d9048dbd62ffa3a7d54d Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Mon, 16 Sep 2013 00:40:02 +0200 Subject: [PATCH] Allow setting attributes to None as a noop, for convenience. --- wrw/sp/cons.py | 3 ++- wrw/sp/xhtml.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/wrw/sp/cons.py b/wrw/sp/cons.py index ce258c6..4052dce 100644 --- a/wrw/sp/cons.py +++ b/wrw/sp/cons.py @@ -60,7 +60,8 @@ class context(object): node.children.append(self.nodefrom(child)) def addattr(self, node, k, v): - node.attrs[unicode(k)] = unicode(v) + if v is not None: + node.attrs[unicode(k)] = unicode(v) class constructor(object): def __init__(self, ns, elcls=element, ctx=None): diff --git a/wrw/sp/xhtml.py b/wrw/sp/xhtml.py index e78d197..f10d315 100644 --- a/wrw/sp/xhtml.py +++ b/wrw/sp/xhtml.py @@ -19,7 +19,7 @@ class xhtmlcontext(_cons.context): def addattr(self, node, k, v): k = unicode(k) - node.attrs[self.attrmap.get(k, k)] = unicode(v) + super(xhtmlcontext, self).addattr(node, self.attrmap.get(k, k), v) def cons(ctx=None): if ctx is None: ctx = xhtmlcontext() -- 2.11.0