Skip to content

Commit 6169230

Browse files
fix: decode string to string
github-close-issue: 2505
1 parent 37814ec commit 6169230

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

gyp/pylib/gyp/easy_xml.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False,
123123

124124
default_encoding = locale.getdefaultlocale()[1]
125125
if default_encoding and default_encoding.upper() != encoding.upper():
126-
if sys.platform == "win32" and sys.version_info < (3, 7):
127-
xml_string = xml_string.decode("cp1251").encode(encoding)
128-
else:
129-
xml_string = xml_string.encode(encoding)
126+
if sys.platform == "win32":
127+
if isinstance(xml_string, str):
128+
xml_string = xml_string.decode("cp1251") # str --> bytes
129+
xml_string = xml_string.encode(encoding) # bytes --> str
130130

131131
# Get the old content
132132
try:

0 commit comments

Comments
 (0)