py3: write unicode bom without using bytes() type

Since the file is opened in utf-8 mode, it needs to be written to using
unicode text, not a b'' string. In python3, '\xef\xbb\xbf' becomes ''
which is definitely not a BOM. Writing the unicode escaped codepoint
allows the codecs.open() encoding to correctly choose the right bytes
for the BOM and insert it as needed.
This commit is contained in:
Eli Schwartz 2019-09-09 20:38:25 -04:00
parent 670c5ebe6a
commit d78e4807c3
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6

View File

@ -107,7 +107,7 @@ class CSV_XML(CatalogPlugin):
outfile = codecs.open(path_to_output, 'w', 'utf8')
# Write a UTF-8 BOM
outfile.write('\xef\xbb\xbf')
outfile.write(u'\ufeff')
# Output the field headers
outfile.write(u'%s\n' % u','.join(fields))