[GRASS-SVN] r47368 - grass/branches/releasebranch_6_4/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 3 08:11:02 EDT 2011


Author: martinl
Date: 2011-08-03 05:11:02 -0700 (Wed, 03 Aug 2011)
New Revision: 47368

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gcmd.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/goutput.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: fix encoding strings

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gcmd.py	2011-08-03 11:48:59 UTC (rev 47367)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gcmd.py	2011-08-03 12:11:02 UTC (rev 47368)
@@ -606,7 +606,7 @@
         ps.stdin = None
     
     Debug.msg(3, "gcmd.RunCommand(): decoding string")
-    stdout, stderr = map(lambda x: utils.DecodeString(x) if type(x) is types.StringType else x, ps.communicate())
+    stdout, stderr = map(utils.DecodeString, ps.communicate())
     
     ret = ps.returncode
     Debug.msg(1, "gcmd.RunCommand(): get return code %d" % ret)

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/goutput.py	2011-08-03 11:48:59 UTC (rev 47367)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/goutput.py	2011-08-03 12:11:02 UTC (rev 47368)
@@ -26,6 +26,7 @@
 import threading
 import Queue
 import codecs
+import locale
 
 import wx
 import wx.stc
@@ -357,20 +358,20 @@
     
     def Redirect(self):
         """!Redirect stdout/stderr
-        
-        @return True redirected
-        @return False failed
         """
         if Debug.GetLevel() == 0 and int(grass.gisenv().get('DEBUG', 0)) == 0:
             # don't redirect when debugging is enabled
             sys.stdout = self.cmd_stdout
             sys.stderr = self.cmd_stderr
-            return True
         else:
-            sys.stdout = sys.__stdout__
-            sys.stderr = sys.__stderr__
-        return False
-
+            enc = locale.getdefaultlocale()[1]
+            if enc:
+                sys.stdout = codecs.getwriter(enc)(sys.__stdout__)
+                sys.stderr = codecs.getwriter(enc)(sys.__stderr__)
+            else:
+                sys.stdout = sys.__stdout__
+                sys.stderr = sys.__stderr__
+        
     def WriteLog(self, text, style = None, wrap = None,
                  switchPage = False):
         """!Generic method for writing log message in 

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py	2011-08-03 11:48:59 UTC (rev 47367)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py	2011-08-03 12:11:02 UTC (rev 47368)
@@ -300,7 +300,7 @@
                                     map = fullname,
                                     fs = ';')
     if ret != 0:
-        sys.stderr.write(_("Vector map <%s>") % fullname + ": " + msg + "\n")
+        sys.stderr.write(_("Vector map <%s>: %s\n") % (fullname, msg))
         return layers
     
     Debug.msg(1, "GetVectorNumberOfLayers(): ret %s" % ret)
@@ -655,22 +655,20 @@
     return ret.splitlines()
 
 def DecodeString(string):
-    """!Return decoded string
+    """!Decode string using system encoding
     
-    String is decoded as unicode, on failure
-    are used system locales.
-
     @param string string to be decoded
     
     @return decoded string
     """
-    try:
-        return string.decode('utf-8')
-    except LookupError:
-        enc = locale.getdefaultlocale()[1]
-        if enc:
-            return string.decode(enc)
+    if not string:
+        return string
     
+    enc = locale.getdefaultlocale()[1]
+    if enc:
+        Debug.msg(5, "DecodeString(): enc=%s" % enc)
+        return string.decode(enc)
+    
     return string
 
 def EncodeString(string):
@@ -680,8 +678,11 @@
     
     @return encoded string
     """
+    if not string:
+        return string
     enc = locale.getdefaultlocale()[1]
     if enc:
+        Debug.msg(5, "EncodeString(): enc=%s" % enc)
         return string.encode(enc)
     
     return string



More information about the grass-commit mailing list