[GRASS-SVN] r70789 - grass/trunk/gui/wxpython/gui_core
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Mar 22 09:19:54 PDT 2017
Author: martinl
Date: 2017-03-22 09:19:54 -0700 (Wed, 22 Mar 2017)
New Revision: 70789
Modified:
grass/trunk/gui/wxpython/gui_core/forms.py
Log:
wxGUI/forms: fix UnicodeDecodeError on loading file when default and file encoding differs
Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py 2017-03-22 03:14:19 UTC (rev 70788)
+++ grass/trunk/gui/wxpython/gui_core/forms.py 2017-03-22 16:19:54 UTC (rev 70789)
@@ -1840,9 +1840,17 @@
style=wx.TE_MULTILINE,
size=(-1, 75))
if p.get('value', '') and os.path.isfile(p['value']):
- f = open(p['value'])
- ifbb.SetValue(''.join(f.readlines()))
- f.close()
+ ifbb.Clear()
+ enc = locale.getdefaultlocale()[1]
+ with codecs.open(p['value'], encoding=enc, errors='ignore') as f:
+ nonascii = bytearray(range(0x80, 0x100))
+ for line in f.readlines():
+ try:
+ ifbb.AppendText(line)
+ except UnicodeDecodeError:
+ # remove non-ascii characters on encoding mismatch (file vs OS)
+ ifbb.AppendText(line.translate(None, nonascii))
+ ifbb.SetInsertionPoint(0)
ifbb.Bind(wx.EVT_TEXT, self.OnFileText)
More information about the grass-commit
mailing list