瀏覽代碼

script.utils: fix bug in decode/encode function

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@68180 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 9 年之前
父節點
當前提交
e083c2525f
共有 1 個文件被更改,包括 5 次插入9 次删除
  1. 5 9
      lib/python/script/utils.py

+ 5 - 9
lib/python/script/utils.py

@@ -156,10 +156,8 @@ def decode(string):
     :param str string: the string to decode
     :param str string: the string to decode
     """
     """
     enc = locale.getdefaultlocale()[1]
     enc = locale.getdefaultlocale()[1]
-    if enc:
-        if hasattr(string, 'decode'):
-            return string.decode(enc)
-
+    if hasattr(string, 'decode'):
+        return string.decode(enc) if enc else string.decode()
     return string
     return string
 
 
 
 
@@ -169,10 +167,8 @@ def encode(string):
     :param str string: the string to encode
     :param str string: the string to encode
     """
     """
     enc = locale.getdefaultlocale()[1]
     enc = locale.getdefaultlocale()[1]
-    if enc:
-        if hasattr(string, 'encode'):
-            return string.encode(enc)
-
+    if hasattr(string, 'encode'):
+        return string.encode(enc) if enc else string.encode()
     return string
     return string
 
 
 
 
@@ -376,5 +372,5 @@ def set_path(modulename, dirname=None, path='.'):
             pathname = os.path.join(modulename, dirname) if dirname else modulename
             pathname = os.path.join(modulename, dirname) if dirname else modulename
             raise ImportError("Not able to find the path '%s' directory "
             raise ImportError("Not able to find the path '%s' directory "
                               "(current dir '%s')." % (pathname, os.getcwd()))
                               "(current dir '%s')." % (pathname, os.getcwd()))
-        
+
         sys.path.insert(0, path)
         sys.path.insert(0, path)