From a8b49423f7b477f7b9b363c69886150d9b83acc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Henriques?= Date: Thu, 12 Dec 2013 04:09:38 +0000 Subject: [PATCH 1/2] Quick and dirty fix to allow WriteXmlIfChanged to write xml in utf-8, converting latin-1 directory paths. --- gyp/pylib/gyp/easy_xml.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gyp/pylib/gyp/easy_xml.py b/gyp/pylib/gyp/easy_xml.py index bf949b6ac9..67246d9051 100644 --- a/gyp/pylib/gyp/easy_xml.py +++ b/gyp/pylib/gyp/easy_xml.py @@ -127,6 +127,11 @@ def WriteXmlIfChanged(content, path, encoding='utf-8', pretty=False, # It has changed, write it if existing != xml_string: f = open(path, 'w') + try: + dec = unicode(xml_string, 'latin-1').encode('utf-8') + xml_string = dec + except Exception as inst: + pass f.write(xml_string) f.close() From 9f3a1b2ce62d2a703675b5474797583209602f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Henriques?= Date: Tue, 17 Dec 2013 21:14:18 +0000 Subject: [PATCH 2/2] Update easy_xml.py Better handling of encoding --- gyp/pylib/gyp/easy_xml.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gyp/pylib/gyp/easy_xml.py b/gyp/pylib/gyp/easy_xml.py index 67246d9051..2b0bb60cb4 100644 --- a/gyp/pylib/gyp/easy_xml.py +++ b/gyp/pylib/gyp/easy_xml.py @@ -115,6 +115,11 @@ def WriteXmlIfChanged(content, path, encoding='utf-8', pretty=False, xml_string = XmlToString(content, encoding, pretty) if win32 and os.linesep != '\r\n': xml_string = xml_string.replace('\n', '\r\n') + + try: + xml_string = xml_string.encode(encoding) + except Exception: + xml_string = unicode(xml_string, 'latin-1').encode(encoding) # Get the old content try: @@ -127,11 +132,6 @@ def WriteXmlIfChanged(content, path, encoding='utf-8', pretty=False, # It has changed, write it if existing != xml_string: f = open(path, 'w') - try: - dec = unicode(xml_string, 'latin-1').encode('utf-8') - xml_string = dec - except Exception as inst: - pass f.write(xml_string) f.close()