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
try:
self.file.write(tounicode(''))
self.totype = tounicode
except TypeError:
# The bytes check should be first. See:
# https://github.com/behdad/fonttools/pull/233
self.file.write(b'')
self.totype = tobytes
except TypeError:
# This better not fail.
self.file.write(tounicode(''))
self.totype = tounicode
self.indentwhite = self.totype(indentwhite)
self.newlinestr = self.totype('\n')
self.indentlevel = 0