[GRASS-dev] [GRASS GIS] #2617: wxgui Raster query redirect to console UnicodeDecodeError
GRASS GIS
trac at osgeo.org
Wed Mar 11 02:15:40 PDT 2015
#2617: wxgui Raster query redirect to console UnicodeDecodeError
-----------------------------+----------------------------------------------
Reporter: marisn | Owner: grass-dev@…
Type: defect | Status: new
Priority: normal | Milestone: 7.0.1
Component: wxGUI | Version: svn-trunk
Keywords: query, encoding | Platform: MSWindows Vista
Cpu: Unspecified |
-----------------------------+----------------------------------------------
Comment(by zarch):
Replying to [comment:5 glynn]:
> Replying to [comment:4 marisn]:
> > Note that the Unicode version of the methods (i.e. ugettext() and
ungettext()) are the recommended interface to use for internationalized
Python programs.
>
> "Recommended" by someone who isn't going to be doing the (substantial)
amount of work involved in adding all the required .encode() calls, or
dealing with the bugs which arise whenever someone forgets the .encode()
call. Because without those calls, unicode values will be converted using
implicit conversions, which fails whenever the unicode value contains non-
ASCII characters.
We have to do this work in any case for python3. We can create a function
that explicity convert every input to unicode, something like:
{{{
import sys
PY2 = sys.version[0] == '2'
def to_text_string(obj, encoding=None):
"""Convert `obj` to (unicode) text string"""
if PY2:
# Python 2
if encoding is None:
return unicode(obj)
else:
return unicode(obj, encoding)
else:
# Python 3
if encoding is None:
return str(obj)
elif isinstance(obj, str):
# In case this function is not used properly, this could
happen
return obj
else:
return str(obj, encoding)
}}}
> As a rough guide, you can (and should) ignore anything the Python
developers have to say about Unicode. Their attitude tends to be
"everything should use Unicode, and the fact that POSIX (and a lot else)
doesn't is your problem and not ours".
Many recent computer languages (i.e. Go, Rust) consider this a good
practice... and personally I agree with them.
In Python3 they fix this implicit conversion, and this is the reason why I
believe we should move to python3.
--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2617#comment:6>
GRASS GIS <http://grass.osgeo.org>
More information about the grass-dev
mailing list