Skip to content

Commit 4d0f93c

Browse files
fix: add support of utf8 encoding (#105)
1 parent dc08c15 commit 4d0f93c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pylib/gyp/easy_xml.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5+
import sys
56
import re
67
import os
78
import locale
@@ -106,7 +107,8 @@ def _ConstructContentList(xml_parts, specification, pretty, level=0):
106107
xml_parts.append("/>%s" % new_line)
107108

108109

109-
def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False):
110+
def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False,
111+
win32=(sys.platform == "win32")):
110112
""" Writes the XML content to disk, touching the file only if it has changed.
111113
112114
Args:
@@ -121,7 +123,10 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False
121123

122124
default_encoding = locale.getdefaultlocale()[1]
123125
if default_encoding and default_encoding.upper() != encoding.upper():
124-
xml_string = xml_string.encode(encoding)
126+
if win32 and sys.version_info < (3, 7):
127+
xml_string = xml_string.decode("cp1251").encode(encoding)
128+
else:
129+
xml_string = xml_string.encode(encoding)
125130

126131
# Get the old content
127132
try:

pylib/gyp/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check
225225
return data[build_file_path]
226226

227227
if os.path.exists(build_file_path):
228-
build_file_contents = open(build_file_path).read()
228+
build_file_contents = open(build_file_path, encoding='utf-8').read()
229229
else:
230230
raise GypError(f"{build_file_path} not found (cwd: {os.getcwd()})")
231231

0 commit comments

Comments
 (0)