Skip to content

Commit 9f3a1b2

Browse files
committed
Update easy_xml.py
Better handling of encoding
1 parent a8b4942 commit 9f3a1b2

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

gyp/pylib/gyp/easy_xml.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ def WriteXmlIfChanged(content, path, encoding='utf-8', pretty=False,
115115
xml_string = XmlToString(content, encoding, pretty)
116116
if win32 and os.linesep != '\r\n':
117117
xml_string = xml_string.replace('\n', '\r\n')
118+
119+
try:
120+
xml_string = xml_string.encode(encoding)
121+
except Exception:
122+
xml_string = unicode(xml_string, 'latin-1').encode(encoding)
118123

119124
# Get the old content
120125
try:
@@ -127,11 +132,6 @@ def WriteXmlIfChanged(content, path, encoding='utf-8', pretty=False,
127132
# It has changed, write it
128133
if existing != xml_string:
129134
f = open(path, 'w')
130-
try:
131-
dec = unicode(xml_string, 'latin-1').encode('utf-8')
132-
xml_string = dec
133-
except Exception as inst:
134-
pass
135135
f.write(xml_string)
136136
f.close()
137137

0 commit comments

Comments
 (0)