glib-mkenums: fix encoding error when writing files

Instead of using NamedTemporaryFile, which doesn't take an encoding in Python 2
use mkstemp() to create a file and open it with io.open(), with a proper
encoding set.

https://bugzilla.gnome.org/show_bug.cgi?id=785113
This commit is contained in:
Christoph Reiter 2017-07-22 20:47:43 +02:00
parent 039c40e6ec
commit b92e15c75d

View File

@ -366,7 +366,9 @@ if output is not None:
out_suffix = '_' + os.path.splitext(out_fn)[1]
if out_dir == '':
out_dir = '.'
tmpfile = tempfile.NamedTemporaryFile(dir=out_dir, delete=False)
fd, filename = tempfile.mkstemp(dir=out_dir)
os.close(fd)
tmpfile = io.open(filename, "w", encoding="utf-8")
output_stream = tmpfile
else:
tmpfile = None