cuddlefish: Return string from RDF.__str__.

This commit is contained in:
Vincent Povirk 2019-08-20 12:52:22 -05:00 committed by Jacek Caban
parent f4f08eb92a
commit a873933ad8

View File

@ -11,24 +11,9 @@ EM_NS = "http://www.mozilla.org/2004/em-rdf#"
class RDF(object):
def __str__(self):
# real files have an .encoding attribute and use it when you
# write() unicode into them: they read()/write() unicode and
# put encoded bytes in the backend file. StringIO objects
# read()/write() unicode and put unicode in the backing store,
# so we must encode the output of getvalue() to get a
# bytestring. (cStringIO objects are weirder: they effectively
# have .encoding hardwired to "ascii" and put only bytes in
# the backing store, so we can't use them here).
#
# The encoding= argument to dom.writexml() merely sets the XML header's
# encoding= attribute. It still writes unencoded unicode to the output file,
# so we have to encode it for real afterwards.
#
# Also see: https://bugzilla.mozilla.org/show_bug.cgi?id=567660
buf = io.StringIO()
self.dom.writexml(buf, encoding="utf-8")
return buf.getvalue().encode('utf-8')
return buf.getvalue()
class RDFUpdate(RDF):
def __init__(self):