Skip to content

Commit

Permalink
Merge branch 'utf-8_support'
Browse files Browse the repository at this point in the history
  • Loading branch information
owl-from-hogvarts committed Dec 24, 2020
2 parents 9e1397c + 30af5dd commit b40017e
Show file tree
Hide file tree
Showing 6 changed files with 936 additions and 548 deletions.
6 changes: 5 additions & 1 deletion gyp/pylib/gyp/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import sys
import re
import os
import locale
Expand Down Expand Up @@ -121,7 +122,10 @@ 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():
xml_string = xml_string.encode(encoding)
if sys.platform == "win32" and sys.version_info < (3, 7):
xml_string = xml_string.decode("cp1251").encode(encoding)
else:
xml_string = xml_string.encode(encoding)

# Get the old content
try:
Expand Down
6 changes: 5 additions & 1 deletion gyp/pylib/gyp/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ 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:
build_file_contents = open(build_file_path, "rU").read()
if sys.version_info > (3, 7) and sys.platform == "win32":
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:
raise GypError("%s not found (cwd: %s)" % (build_file_path, os.getcwd()))

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

if (sys.stdout.encoding != "utf-8" and sys.platform == "win32"):
if sys.version_info > (3, 7):
sys.stdout.reconfigure(encoding='utf-8')
print(sys.executable)
else:
sys.stdout = codecs.getwriter("utf8")(sys.stdout)
print(sys.executable.decode("cp1251"))
else:
print(sys.executable)
Loading

0 comments on commit b40017e

Please sign in to comment.