Skip to content

Commit b40017e

Browse files
Merge branch 'utf-8_support'
2 parents 9e1397c + 30af5dd commit b40017e

File tree

6 files changed

+936
-548
lines changed

6 files changed

+936
-548
lines changed

gyp/pylib/gyp/easy_xml.py

Lines changed: 5 additions & 1 deletion
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
@@ -121,7 +122,10 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False
121122

122123
default_encoding = locale.getdefaultlocale()[1]
123124
if default_encoding and default_encoding.upper() != encoding.upper():
124-
xml_string = xml_string.encode(encoding)
125+
if sys.platform == "win32" and sys.version_info < (3, 7):
126+
xml_string = xml_string.decode("cp1251").encode(encoding)
127+
else:
128+
xml_string = xml_string.encode(encoding)
125129

126130
# Get the old content
127131
try:

gyp/pylib/gyp/input.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check
236236
# But since node-gyp produces ebcdic files, do not use that mode.
237237
build_file_contents = open(build_file_path, "r").read()
238238
else:
239-
build_file_contents = open(build_file_path, "rU").read()
239+
if sys.version_info > (3, 7) and sys.platform == "win32":
240+
build_file_contents = open(build_file_path, 'r', newline=None , encoding="utf8").read()
241+
else:
242+
# "U" flag is used becouse of backward compatibility
243+
build_file_contents = open(build_file_path, 'rU').read()
240244
else:
241245
raise GypError("%s not found (cwd: %s)" % (build_file_path, os.getcwd()))
242246

lib/find-python-script.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys, codecs;
2+
3+
if (sys.stdout.encoding != "utf-8" and sys.platform == "win32"):
4+
if sys.version_info > (3, 7):
5+
sys.stdout.reconfigure(encoding='utf-8')
6+
print(sys.executable)
7+
else:
8+
sys.stdout = codecs.getwriter("utf8")(sys.stdout)
9+
print(sys.executable.decode("cp1251"))
10+
else:
11+
print(sys.executable)

0 commit comments

Comments
 (0)