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
This commit is contained in:
		| @@ -19,7 +19,7 @@ class MemoryFile: | |||||||
|         self.name = name |         self.name = name | ||||||
|         self.buffer = '' |         self.buffer = '' | ||||||
|     def write(self, data): |     def write(self, data): | ||||||
|         self.buffer += data.encode() |         self.buffer += data.encode(g.currentEncoding) | ||||||
|     def close(self): |     def close(self): | ||||||
|         wxMemoryFSHandler_AddFile(self.name, self.buffer) |         wxMemoryFSHandler_AddFile(self.name, self.buffer) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -872,21 +872,10 @@ Homepage: http://xrced.sourceforge.net\ | |||||||
|         try: |         try: | ||||||
|             f = open(path) |             f = open(path) | ||||||
|             self.Clear() |             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<encd>[^<>].*)"\?>', line) |  | ||||||
|             # Build wx tree |  | ||||||
|             f.seek(0) |  | ||||||
|             dom = minidom.parse(f) |             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() |             f.close() | ||||||
|  |             # Set encoding global variable | ||||||
|  |             g.currentEncoding = dom.encoding | ||||||
|             # Change dir |             # Change dir | ||||||
|             dir = os.path.dirname(path) |             dir = os.path.dirname(path) | ||||||
|             if dir: os.chdir(dir) |             if dir: os.chdir(dir) | ||||||
| @@ -920,17 +909,18 @@ Homepage: http://xrced.sourceforge.net\ | |||||||
|  |  | ||||||
|     def Save(self, path): |     def Save(self, path): | ||||||
|         try: |         try: | ||||||
|  |             import codecs | ||||||
|             # Apply changes |             # Apply changes | ||||||
|             if tree.selection and panel.IsModified(): |             if tree.selection and panel.IsModified(): | ||||||
|                 self.OnRefresh(wxCommandEvent()) |                 self.OnRefresh(wxCommandEvent()) | ||||||
|             f = open(path, 'w') |             f = codecs.open(path, 'w', g.currentEncoding) | ||||||
|             # Make temporary copy for formatting it |             # Make temporary copy for formatting it | ||||||
|             # !!! We can't clone dom node, it works only once |             # !!! We can't clone dom node, it works only once | ||||||
|             #self.domCopy = tree.dom.cloneNode(True) |             #self.domCopy = tree.dom.cloneNode(True) | ||||||
|             self.domCopy = MyDocument() |             self.domCopy = MyDocument() | ||||||
|             mainNode = self.domCopy.appendChild(tree.mainNode.cloneNode(True)) |             mainNode = self.domCopy.appendChild(tree.mainNode.cloneNode(True)) | ||||||
|             self.Indent(mainNode) |             self.Indent(mainNode) | ||||||
|             self.domCopy.writexml(f, encoding=tree.rootObj.params['encoding'].value()) |             self.domCopy.writexml(f, encoding = g.currentEncoding) | ||||||
|             f.close() |             f.close() | ||||||
|             self.domCopy.unlink() |             self.domCopy.unlink() | ||||||
|             self.domCopy = None |             self.domCopy = None | ||||||
|   | |||||||
| @@ -336,12 +336,10 @@ class xxxContainer(xxxObject): | |||||||
|  |  | ||||||
| # Simulate normal parameter for encoding | # Simulate normal parameter for encoding | ||||||
| class xxxEncoding: | class xxxEncoding: | ||||||
|     def __init__(self, val): |  | ||||||
|         self.encd = val |  | ||||||
|     def value(self): |     def value(self): | ||||||
|         return self.encd |         return g.currentEncoding | ||||||
|     def update(self, val): |     def update(self, val): | ||||||
|         self.encd = val |         g.currentEncoding = val | ||||||
|  |  | ||||||
| # Special class for root node | # Special class for root node | ||||||
| class xxxMainNode(xxxContainer): | class xxxMainNode(xxxContainer): | ||||||
| @@ -353,7 +351,7 @@ class xxxMainNode(xxxContainer): | |||||||
|         # Reset required parameters after processing XML, because encoding is |         # Reset required parameters after processing XML, because encoding is | ||||||
|         # a little special |         # a little special | ||||||
|         self.required = ['encoding'] |         self.required = ['encoding'] | ||||||
|         self.params['encoding'] = xxxEncoding(dom.encoding) |         self.params['encoding'] = xxxEncoding() | ||||||
|  |  | ||||||
| ################################################################################ | ################################################################################ | ||||||
| # Top-level windwows | # Top-level windwows | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user