From: Fredrik Tolf Date: Tue, 5 Apr 2016 21:30:08 +0000 (+0200) Subject: Enable iterables to be passed as new SP nodes. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=6d764ed2eb46a991008ba011f1bdfd63ff61f827;p=wrw.git Enable iterables to be passed as new SP nodes. --- diff --git a/wrw/sp/cons.py b/wrw/sp/cons.py index 0c36458..8ffa397 100644 --- a/wrw/sp/cons.py +++ b/wrw/sp/cons.py @@ -1,4 +1,4 @@ -import sys +import sys, collections.abc import xml.dom.minidom class node(object): @@ -56,12 +56,19 @@ class context(object): return ob.__tonode__() if type(ob) in self.nodeconv: return self.nodeconv[type(ob)](ob) - raise Exception("No node conversion known for %s objects" % str(type(ob))) + return None def addchild(self, node, child): if child is None: return - node.children.append(self.nodefrom(child)) + new = self.nodefrom(child) + if new is not None: + node.children.append(self.nodefrom(child)) + elif isinstance(child, collections.abc.Iterable): + for ch in child: + self.addchild(node, ch) + else: + raise Exception("No node conversion known for %s objects" % str(type(ob))) def addattr(self, node, k, v): if v is not None: