From 580aca65b12255d8672eae1e373396bf54460960 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 15 Oct 2018 11:27:09 +0200 Subject: [PATCH] extract_types.py: force io to use UTF-8 encoding (fixes #27332) --- lasso/extract_types.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lasso/extract_types.py b/lasso/extract_types.py index 2bacbd56..1359cafc 100644 --- a/lasso/extract_types.py +++ b/lasso/extract_types.py @@ -1,9 +1,9 @@ #! /usr/bin/env python +import io import glob import re import sys -from six.moves import cStringIO as StringIO import six enable_wsf = 0 @@ -24,12 +24,12 @@ wsf = ['lasso_disco_', 'lasso_dst_', 'lasso_is_', 'lasso_profile_service_', if enable_wsf: wsf = [] -fd = StringIO() +fd = io.StringIO() -six.print_("/* This file has been autogenerated; changes will be lost */", file=fd) -six.print_("", file=fd) -six.print_("typedef GType (*type_function) ();", file=fd) -six.print_("", file=fd) +six.print_(u"/* This file has been autogenerated; changes will be lost */", file=fd) +six.print_(u"", file=fd) +six.print_(u"typedef GType (*type_function) ();", file=fd) +six.print_(u"", file=fd) header_files = [] for header_file in glob.glob('%s/*/*.h' % srcdir) + glob.glob('%s/*/*/*.h' % srcdir): @@ -37,7 +37,7 @@ for header_file in glob.glob('%s/*/*.h' % srcdir) + glob.glob('%s/*/*/*.h' % src continue header_files.append(header_file) try: - type = re.findall('lasso_.*get_type', open(header_file).read())[0] + type = re.findall('lasso_.*get_type', io.open(header_file, encoding='utf-8').read())[0] except IndexError: continue for t in wsf: @@ -46,19 +46,19 @@ for header_file in glob.glob('%s/*/*.h' % srcdir) + glob.glob('%s/*/*/*.h' % src else: six.print_("extern GType %s();" % type, file=fd) -six.print_("", file=fd) -six.print_("type_function functions[] = {", file=fd) +six.print_(u"", file=fd) +six.print_(u"type_function functions[] = {", file=fd) for header_file in header_files: try: - type = re.findall('lasso_.*get_type', open(header_file).read())[0] + type = re.findall('lasso_.*get_type', io.open(header_file, encoding='utf-8').read())[0] except IndexError: continue for t in wsf: if type.startswith(t): break else: - six.print_("\t%s," % type, file=fd) -six.print_("\tNULL", file=fd) -six.print_("};", file=fd) + six.print_(u"\t%s," % type, file=fd) +six.print_(u"\tNULL", file=fd) +six.print_(u"};", file=fd) -open('types.c', 'w').write(fd.getvalue()) +io.open('types.c', 'w', encoding='utf-8').write(fd.getvalue()) -- 2.18.0