Skip to content

Commit

Permalink
lib: improved if statments for Unicode string support for Windows
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
owl-from-hogvarts committed Nov 6, 2020
1 parent 1fad283 commit abeafbe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
10 changes: 7 additions & 3 deletions gyp/pylib/gyp/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False

default_encoding = locale.getdefaultlocale()[1]
if default_encoding and default_encoding.upper() != encoding.upper():
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
xml_string = xml_string.encode(encoding)
if sys.platform == "win32":
if (sys.version_info[0] + sys.version_info[1] * 0.1) > 3.7:
xml_string = xml_string.encode(encoding)
else:
xml_string = xml_string.decode("cp1251").encode(encoding)
# for non windows systems
else:
xml_string = xml_string.decode("cp1251").encode(encoding)
xml_string = xml_string.encode(encoding)

# Get the old content
try:
Expand Down
10 changes: 7 additions & 3 deletions gyp/pylib/gyp/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,14 @@ def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check
# But since node-gyp produces ebcdic files, do not use that mode.
build_file_contents = open(build_file_path, "r").read()
else:
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
build_file_contents = open(build_file_path, 'rU', encoding="utf8").read()
if sys.platform == "win32":
if (sys.version_info[0] + sys.version_info[1] * 0.1) > 3.7:
build_file_contents = open(build_file_path, 'r', newline=None , encoding="utf8").read()
else:
# "U" flag is used becouse of backward compatibility
build_file_contents = open(build_file_path, 'rU').read()
else:
build_file_contents = open(build_file_path, 'rU').read()
build_file_contents = open(build_file_path, 'r', newline=None).read()
else:
raise GypError("%s not found (cwd: %s)" % (build_file_path, os.getcwd()))

Expand Down
14 changes: 8 additions & 6 deletions lib/find-python-script.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import sys, codecs;

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


if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
print(sys.executable)
if sys.platform == "win32":
if (sys.version_info[0] + sys.version_info[1] * 0.1) > 3.7:
print(sys.executable)
else:
print(sys.executable.decode("cp1251"));
else:
print(sys.executable.decode("cp1251"));
print(sys.executable)

0 comments on commit abeafbe

Please sign in to comment.