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:
parent
b987387052
commit
7353d81801
@ -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)
|
||||
|
||||
|
@ -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<encd>[^<>].*)"\?>', 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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user