Skip to content

Commit abeafbe

Browse files
lib: improved if statments for Unicode string support for Windows
Better checking for python version (fix bug with python 4.0.0 which could break unicode strings support) Added checking for OS (unicode support doesn't necessary for other systems)
1 parent 1fad283 commit abeafbe

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

gyp/pylib/gyp/easy_xml.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False
122122

123123
default_encoding = locale.getdefaultlocale()[1]
124124
if default_encoding and default_encoding.upper() != encoding.upper():
125-
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
126-
xml_string = xml_string.encode(encoding)
125+
if sys.platform == "win32":
126+
if (sys.version_info[0] + sys.version_info[1] * 0.1) > 3.7:
127+
xml_string = xml_string.encode(encoding)
128+
else:
129+
xml_string = xml_string.decode("cp1251").encode(encoding)
130+
# for non windows systems
127131
else:
128-
xml_string = xml_string.decode("cp1251").encode(encoding)
132+
xml_string = xml_string.encode(encoding)
129133

130134
# Get the old content
131135
try:

gyp/pylib/gyp/input.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,14 @@ 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-
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
240-
build_file_contents = open(build_file_path, 'rU', encoding="utf8").read()
239+
if sys.platform == "win32":
240+
if (sys.version_info[0] + sys.version_info[1] * 0.1) > 3.7:
241+
build_file_contents = open(build_file_path, 'r', newline=None , encoding="utf8").read()
242+
else:
243+
# "U" flag is used becouse of backward compatibility
244+
build_file_contents = open(build_file_path, 'rU').read()
241245
else:
242-
build_file_contents = open(build_file_path, 'rU').read()
246+
build_file_contents = open(build_file_path, 'r', newline=None).read()
243247
else:
244248
raise GypError("%s not found (cwd: %s)" % (build_file_path, os.getcwd()))
245249

lib/find-python-script.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import sys, codecs;
22

3-
if (sys.stdout.encoding != "utf-8"):
4-
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
3+
if (sys.stdout.encoding != "utf-8" and sys.platform == "win32"):
4+
if (sys.version_info[0] + sys.version_info[1] * 0.1) > 3.7:
55
sys.stdout.reconfigure(encoding='utf-8')
66
else:
77
sys.stdout = codecs.getwriter("utf8")(sys.stdout)
88

9-
10-
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
11-
print(sys.executable)
9+
if sys.platform == "win32":
10+
if (sys.version_info[0] + sys.version_info[1] * 0.1) > 3.7:
11+
print(sys.executable)
12+
else:
13+
print(sys.executable.decode("cp1251"));
1214
else:
13-
print(sys.executable.decode("cp1251"));
15+
print(sys.executable)

0 commit comments

Comments
 (0)