[GRASS-SVN] r70335 - grass/trunk/lib/python/script
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jan 10 19:23:12 PST 2017
Author: wenzeslaus
Date: 2017-01-10 19:23:11 -0800 (Tue, 10 Jan 2017)
New Revision: 70335
Modified:
grass/trunk/lib/python/script/utils.py
Log:
pythonlib: set fallback encoding to UTF-8 as suggested by marisn in #2885
Modified: grass/trunk/lib/python/script/utils.py
===================================================================
--- grass/trunk/lib/python/script/utils.py 2017-01-10 20:07:13 UTC (rev 70334)
+++ grass/trunk/lib/python/script/utils.py 2017-01-11 03:23:11 UTC (rev 70335)
@@ -150,6 +150,13 @@
self[key] = value
+def _get_encoding():
+ encoding = locale.getdefaultlocale()[1]
+ if not encoding:
+ encoding = 'UTF-8'
+ return encoding
+
+
def decode(bytes_):
"""Decode bytes with default locale and return (unicode) string
@@ -158,8 +165,8 @@
:param bytes bytes_: the bytes to decode
"""
if isinstance(bytes_, bytes):
- enc = locale.getdefaultlocale()[1]
- return bytes_.decode(enc) if enc else bytes_.decode()
+ enc = _get_encoding()
+ return bytes_.decode(enc)
return bytes_
@@ -173,8 +180,8 @@
"""
if isinstance(string, bytes):
return string
- enc = locale.getdefaultlocale()[1]
- return string.encode(enc) if enc else string.encode()
+ enc = _get_encoding()
+ return string.encode(enc)
def parse_key_val(s, sep='=', dflt=None, val_type=None, vsep=None):
More information about the grass-commit
mailing list