Fix bytes/unicode detection

https://github.com/behdad/fonttools/pull/233
This commit is contained in:
Behdad Esfahbod 2015-04-15 10:44:39 -07:00
parent 73031d5a63
commit 034ed355de

View File

@ -25,11 +25,14 @@ class XMLWriter(object):
# Figure out if writer expects bytes or unicodes # Figure out if writer expects bytes or unicodes
try: try:
self.file.write(tounicode('')) # The bytes check should be first. See:
self.totype = tounicode # https://github.com/behdad/fonttools/pull/233
except TypeError:
self.file.write(b'') self.file.write(b'')
self.totype = tobytes self.totype = tobytes
except TypeError:
# This better not fail.
self.file.write(tounicode(''))
self.totype = tounicode
self.indentwhite = self.totype(indentwhite) self.indentwhite = self.totype(indentwhite)
self.newlinestr = self.totype('\n') self.newlinestr = self.totype('\n')
self.indentlevel = 0 self.indentlevel = 0