[GRASS-SVN] r54222 - in grass/branches/releasebranch_6_4/gui/wxpython: core gmodeler

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 6 05:08:09 PST 2012


Author: martinl
Date: 2012-12-06 05:08:08 -0800 (Thu, 06 Dec 2012)
New Revision: 54222

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/core/gcmd.py
   grass/branches/releasebranch_6_4/gui/wxpython/core/workspace.py
   grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/model.py
Log:
wxGUI: fix writing workspace or model file (unknown encoding)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/core/gcmd.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/core/gcmd.py	2012-12-06 13:02:31 UTC (rev 54221)
+++ grass/branches/releasebranch_6_4/gui/wxpython/core/gcmd.py	2012-12-06 13:08:08 UTC (rev 54222)
@@ -14,6 +14,7 @@
 
 Functions:
  - RunCommand
+ - GetDefaultEncoding
 
 (C) 2007-2008, 2010-2011 by the GRASS Development Team
 
@@ -700,3 +701,17 @@
     
     Debug.msg(2, "gcmd.RunCommand(): return result")
     return stdout, _formatMsg(stderr)
+
+def GetDefaultEncoding(forceUTF8 = False):
+    """!Get default system encoding
+    
+    @param forceUTF8 force 'UTF-8' if encoding is not defined
+
+    @return system encoding (can be None)
+    """
+    enc = locale.getdefaultlocale()[1]
+    if forceUTF8 and (enc is None or enc == 'UTF8'):
+        return 'UTF-8'
+    
+    Debug.msg(1, "GetSystemEncoding(): %s" % enc)
+    return enc

Modified: grass/branches/releasebranch_6_4/gui/wxpython/core/workspace.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/core/workspace.py	2012-12-06 13:02:31 UTC (rev 54221)
+++ grass/branches/releasebranch_6_4/gui/wxpython/core/workspace.py	2012-12-06 13:08:08 UTC (rev 54222)
@@ -17,13 +17,12 @@
 """
 
 import os
-import locale
 
 import wx
 
 from core.utils     import normalize_whitespace
 from core.settings  import UserSettings
-from core.gcmd      import EncodeString
+from core.gcmd      import EncodeString, GetDefaultEncoding
 from nviz.main      import NvizSettings
 
 class ProcessWorkspaceFile:
@@ -536,8 +535,8 @@
         self.indent = 0
         
         # write header
-        enc = locale.getdefaultlocale()[1]
-        self.file.write('<?xml version="1.0" encoding="%s"?>\n' % enc)
+
+        self.file.write('<?xml version="1.0" encoding="%s"?>\n' % GetDefaultEncoding(forceUTF8 = True))
         self.file.write('<!DOCTYPE gxw SYSTEM "grass-gxw.dtd">\n')
         self.file.write('%s<gxw>\n' % (' ' * self.indent))
         

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/model.py	2012-12-06 13:02:31 UTC (rev 54221)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/model.py	2012-12-06 13:08:08 UTC (rev 54222)
@@ -31,7 +31,6 @@
 import re
 import mimetypes
 import time
-import locale
 try:
     import xml.etree.ElementTree as etree
 except ImportError:
@@ -42,7 +41,7 @@
 
 from core                import globalvar
 from core                import utils
-from core.gcmd           import GMessage, GException, GError, RunCommand, EncodeString, GWarning
+from core.gcmd           import GMessage, GException, GError, RunCommand, EncodeString, GWarning, GetDefaultEncoding
 from core.settings       import UserSettings
 from gui_core.forms      import GUI, CmdPanel
 from gui_core.widgets    import GNotebook
@@ -1775,8 +1774,7 @@
         
     def _header(self):
         """!Write header"""
-        enc = locale.getdefaultlocale()[1]
-        self.fd.write('<?xml version="1.0" encoding="%s"?>\n' % enc)
+        self.fd.write('<?xml version="1.0" encoding="%s"?>\n' % GetDefaultEncoding(forceUTF8 = True))
         self.fd.write('<!DOCTYPE gxm SYSTEM "grass-gxm.dtd">\n')
         self.fd.write('%s<gxm>\n' % (' ' * self.indent))
         self.indent += 4



More information about the grass-commit mailing list