Changeset 70335


Ignore:
Timestamp:
Jan 10, 2017, 7:23:11 PM (8 years ago)
Author:
wenzeslaus
Message:

pythonlib: set fallback encoding to UTF-8 as suggested by marisn in #2885

File:
1 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/lib/python/script/utils.py

    r69811 r70335  
    151151
    152152
     153def _get_encoding():
     154    encoding = locale.getdefaultlocale()[1]
     155    if not encoding:
     156        encoding = 'UTF-8'
     157    return encoding
     158
     159
    153160def decode(bytes_):
    154161    """Decode bytes with default locale and return (unicode) string
     
    159166    """
    160167    if isinstance(bytes_, bytes):
    161         enc = locale.getdefaultlocale()[1]
    162         return bytes_.decode(enc) if enc else bytes_.decode()
     168        enc = _get_encoding()
     169        return bytes_.decode(enc)
    163170    return bytes_
    164171
     
    174181    if isinstance(string, bytes):
    175182        return string
    176     enc = locale.getdefaultlocale()[1]
    177     return string.encode(enc) if enc else string.encode()
     183    enc = _get_encoding()
     184    return string.encode(enc)
    178185
    179186
Note: See TracChangeset for help on using the changeset viewer.