Mercurial > genshi > mirror
comparison genshi/builder.py @ 379:e1d659c87ddf trunk
The builder API now accepts streams as children of elements and fragments.
author | cmlenz |
---|---|
date | Thu, 23 Nov 2006 17:48:17 +0000 |
parents | 2aa7ca37ae6a |
children | 228907abb726 3eb30e4ece8c |
comparison
equal
deleted
inserted
replaced
378:873ca2a7ec05 | 379:e1d659c87ddf |
---|---|
44 def __unicode__(self): | 44 def __unicode__(self): |
45 return unicode(self.generate()) | 45 return unicode(self.generate()) |
46 | 46 |
47 def append(self, node): | 47 def append(self, node): |
48 """Append an element or string as child node.""" | 48 """Append an element or string as child node.""" |
49 if isinstance(node, (Element, basestring, int, float, long)): | 49 if isinstance(node, (Stream, Element, basestring, int, float, long)): |
50 # For objects of a known/primitive type, we avoid the check for | 50 # For objects of a known/primitive type, we avoid the check for |
51 # whether it is iterable for better performance | 51 # whether it is iterable for better performance |
52 self.children.append(node) | 52 self.children.append(node) |
53 elif isinstance(node, Fragment): | 53 elif isinstance(node, Fragment): |
54 self.children.extend(node.children) | 54 self.children.extend(node.children) |
61 def _generate(self): | 61 def _generate(self): |
62 for child in self.children: | 62 for child in self.children: |
63 if isinstance(child, Fragment): | 63 if isinstance(child, Fragment): |
64 for event in child._generate(): | 64 for event in child._generate(): |
65 yield event | 65 yield event |
66 elif isinstance(child, Stream): | |
67 for event in child: | |
68 yield event | |
66 else: | 69 else: |
67 if not isinstance(child, basestring): | 70 if not isinstance(child, basestring): |
68 child = unicode(child) | 71 child = unicode(child) |
69 yield TEXT, child, (None, -1, -1) | 72 yield TEXT, child, (None, -1, -1) |
70 | 73 |