[GRASS-dev] [GRASS GIS] #2885: wxGUI Location Creation Wizard: UnicodeEncoreError when GISDBASE has accents in path
GRASS GIS
trac at osgeo.org
Sat Feb 6 03:40:11 PST 2016
#2885: wxGUI Location Creation Wizard: UnicodeEncoreError when GISDBASE has
accents in path
--------------------------+--------------------------------------
Reporter: mlennert | Owner: grass-dev@…
Type: defect | Status: new
Priority: normal | Milestone: 7.1.0
Component: wxGUI | Version: svn-trunk
Resolution: | Keywords: location wizard encoding
CPU: Unspecified | Platform: Unspecified
--------------------------+--------------------------------------
Comment (by marisn):
I think I see where is the problem. As usual - GRASS developers are not
following Unicode best practice (decode early, encode late) and ignoring
Pythonic approach in Python code (f* byte strings, use Unicode internally
everywhere. Yes, everywhere. No exceptions).
A correct approach would be to decode any incoming strings as soon as they
enter Python code i.e. in core.read_command (see patch), still that will
cause a huge breakage of whole wxgui till all str() occurrences (also
implicit ones!) will be transformed to unicode() ones (as in the example
patch for dbmgr).
Here is a hack around the issue (without breaking #2205) but I consider it
to be a wrong way to go:
{{{
Index: gui/wxpython/location_wizard/wizard.py
===================================================================
--- gui/wxpython/location_wizard/wizard.py (revision 67730)
+++ gui/wxpython/location_wizard/wizard.py (working copy)
@@ -2064,7 +2064,12 @@
return None
# current GISDbase or a new one?
- current_gdb =
grass.gisenv()['GISDBASE'].decode(sys.stdin.encoding)
+ current_gdb = grass.gisenv()['GISDBASE']
+ if isinstance(current_gdb, bytes):
+ ENCODING = locale.getdefaultlocale()[1]
+ if ENCODING is None:
+ ENCODING = 'UTF-8'
+ current_gdb = current_gdb.decode(ENCODING)
if current_gdb != database:
# change to new GISDbase or create new one
if os.path.isdir(database) != True:
}}}
I assume that it makes clear why this is a bad idea.
--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2885#comment:3>
GRASS GIS <https://grass.osgeo.org>
More information about the grass-dev
mailing list