def dump(self): """ Reformat everything. """ for (d,e) in self.walk(endtag=True, depth=1): if isinstance(e, basestring): yield e elif 0 < d: # start tag if e.tag == 'comment': yield u'<!--' else: yield u'<%s%s>' % (e.tag, attr2str(e.attrs.iteritems())) else: # end tag if e.tag == 'comment': yield u'-->' else: yield u'</%s>' % e.tag return
def dump(self, out=sys.stdout, codec='ascii'): if self.tag == 'comment': out.write('<!--') else: out.write('<%s%s>' % (self.tag, attr2str(self.attrs.iteritems()))) # IMMED? if self.children == None: return # CDATA? if self.tag in ('style','script'): for x in self.children: out.write(x.encode(codec, 'replace')) else: # BLOCK for x in self.children: if element_tag(x): x.dump(out, encoder) else: out.write(quotestr(x, codec)) if self.tag == 'comment': out.write('-->') else: out.write("</%s>" % self.tag) return