From: Robin Dunn Date: Tue, 14 Dec 2004 19:39:09 +0000 (+0000) Subject: Applied patch #1084332: xrced does not respect encoding X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7353d818016e293e14980b53bcd9698bdbb8226f Applied patch #1084332: xrced does not respect encoding git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31004 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/wxPython/wx/tools/XRCed/tree.py b/wxPython/wx/tools/XRCed/tree.py index 84d6cd95d2..6bc609caf3 100644 --- a/wxPython/wx/tools/XRCed/tree.py +++ b/wxPython/wx/tools/XRCed/tree.py @@ -19,7 +19,7 @@ class MemoryFile: self.name = name self.buffer = '' def write(self, data): - self.buffer += data.encode() + self.buffer += data.encode(g.currentEncoding) def close(self): wxMemoryFSHandler_AddFile(self.name, self.buffer) diff --git a/wxPython/wx/tools/XRCed/xrced.py b/wxPython/wx/tools/XRCed/xrced.py index 6bab858c5a..4a7ef0bc37 100644 --- a/wxPython/wx/tools/XRCed/xrced.py +++ b/wxPython/wx/tools/XRCed/xrced.py @@ -872,21 +872,10 @@ Homepage: http://xrced.sourceforge.net\ try: f = open(path) self.Clear() - # Parse first line to get encoding (!! hack, I don't know a better way) - line = f.readline() - mo = re.match(r'^<\?xml ([^<>]* )?encoding="(?P[^<>].*)"\?>', line) - # Build wx tree - f.seek(0) dom = minidom.parse(f) - # Set encoding global variable and document encoding property - if mo: - dom.encoding = g.currentEncoding = mo.group('encd') - if dom.encoding not in ['ascii', sys.getdefaultencoding()]: - wxLogWarning('Encoding is different from system default') - else: - g.currentEncoding = 'ascii' - dom.encoding = '' f.close() + # Set encoding global variable + g.currentEncoding = dom.encoding # Change dir dir = os.path.dirname(path) if dir: os.chdir(dir) @@ -920,17 +909,18 @@ Homepage: http://xrced.sourceforge.net\ def Save(self, path): try: + import codecs # Apply changes if tree.selection and panel.IsModified(): self.OnRefresh(wxCommandEvent()) - f = open(path, 'w') + f = codecs.open(path, 'w', g.currentEncoding) # Make temporary copy for formatting it # !!! We can't clone dom node, it works only once #self.domCopy = tree.dom.cloneNode(True) self.domCopy = MyDocument() mainNode = self.domCopy.appendChild(tree.mainNode.cloneNode(True)) self.Indent(mainNode) - self.domCopy.writexml(f, encoding=tree.rootObj.params['encoding'].value()) + self.domCopy.writexml(f, encoding = g.currentEncoding) f.close() self.domCopy.unlink() self.domCopy = None diff --git a/wxPython/wx/tools/XRCed/xxx.py b/wxPython/wx/tools/XRCed/xxx.py index 90542e52ce..535c6e2395 100644 --- a/wxPython/wx/tools/XRCed/xxx.py +++ b/wxPython/wx/tools/XRCed/xxx.py @@ -336,12 +336,10 @@ class xxxContainer(xxxObject): # Simulate normal parameter for encoding class xxxEncoding: - def __init__(self, val): - self.encd = val def value(self): - return self.encd + return g.currentEncoding def update(self, val): - self.encd = val + g.currentEncoding = val # Special class for root node class xxxMainNode(xxxContainer): @@ -353,7 +351,7 @@ class xxxMainNode(xxxContainer): # Reset required parameters after processing XML, because encoding is # a little special self.required = ['encoding'] - self.params['encoding'] = xxxEncoding(dom.encoding) + self.params['encoding'] = xxxEncoding() ################################################################################ # Top-level windwows