def tostring(raw, **kwargs):
 xml_declaration = kwargs.pop(u'xml_declaration', False)
 encoding = kwargs.pop(u'encoding', u'UTF-8')
 kwargs[u'encoding'] = unicode
 kwargs[u'xml_declaration'] = False
 ans = etree.tostring(raw, **kwargs)
 if xml_declaration:
  ans = ((u'<?xml version="1.0" encoding="%s"?>\n' % encoding) + ans)
 return re.sub(u'&#x([0-9A-Fa-f]+);', (lambda m: mychr(int(m.group(1), 16))), ans).encode(encoding)

def tostring ( raw , ** kwargs ) : xml_declaration = kwargs . pop ( u'xml_declaration' , False ) encoding = kwargs . pop ( u'encoding' , u'UTF-8' ) kwargs [ u'encoding' ] = unicode kwargs [ u'xml_declaration' ] = False ans = etree . tostring ( raw , ** kwargs ) if xml_declaration : ans = ( ( u'<?xml version="1.0" encoding="%s"?>\n' % encoding ) + ans ) return re . sub ( u'&#x([0-9A-Fa-f]+);' , ( lambda m : mychr ( int ( m . group ( 1 ) , 16 ) ) ) , ans ) . encode ( encoding )
serialize processed xhtml .