1from __future__ import absolute_import, division, unicode_literals 2 3from .. import treewalkers 4 5from .htmlserializer import HTMLSerializer 6 7 8def serialize(input, tree="etree", format="html", encoding=None, 9 **serializer_opts): 10 # XXX: Should we cache this? 11 walker = treewalkers.getTreeWalker(tree) 12 if format == "html": 13 s = HTMLSerializer(**serializer_opts) 14 else: 15 raise ValueError("type must be html") 16 return s.render(walker(input), encoding) 17