Skip to content

Commit

Permalink
fix: add support of utf8 encoding (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
owl-from-hogvarts authored May 21, 2021
1 parent dc08c15 commit 4d0f93c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions 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 @@ -106,7 +107,8 @@ def _ConstructContentList(xml_parts, specification, pretty, level=0):
xml_parts.append("/>%s" % new_line)


def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False):
def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False,
win32=(sys.platform == "win32")):
""" Writes the XML content to disk, touching the file only if it has changed.
Args:
Expand All @@ -121,7 +123,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 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
2 changes: 1 addition & 1 deletion pylib/gyp/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check
return data[build_file_path]

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

Expand Down

0 comments on commit 4d0f93c

Please sign in to comment.