[GRASS-dev] [GRASS GIS] #3405: encoding issue when launching modules

GRASS GIS trac at osgeo.org
Thu Aug 24 06:01:51 PDT 2017


#3405: encoding issue when launching modules
--------------------------+---------------------------------------
  Reporter:  mlennert     |      Owner:  grass-dev@…
      Type:  defect       |     Status:  new
  Priority:  normal       |  Milestone:  7.4.0
 Component:  wxGUI        |    Version:  svn-trunk
Resolution:               |   Keywords:  g.search.modules encoding
       CPU:  Unspecified  |   Platform:  Unspecified
--------------------------+---------------------------------------

Comment (by mlennert):

 Replying to [comment:5 neteler]:
 > Replying to [comment:4 mlennert]:
 > > {{{
 > > (forms.py:26034): Gtk-WARNING **: Unable to locate theme engine in
 module_path: "adwaita",
 > >
 > > (forms.py:26034): Gtk-WARNING **: Unable to locate theme engine in
 module_path: "adwaita",
 > > }}}
 >
 > Probably you are lacking the adwaita-gtk2-theme package? Here the resp.
 Fedora RPM:

 Thanks for the hint. In Debian, it's the gnome-themes-standard package.

 Installing that gets rid of the Gtk-WARNINGs, but not of the bug trying to
 run the modules.

 But I'm getting closer. In lib/python/script/utils.py we have the function
 encode, with the following code:


 {{{
     if isinstance(string, bytes):
         return string
     if isinstance(string, unicode):
         enc = _get_encoding()
         return string.encode(enc)
     return bytes(string)
 }}}

 On the work computer the string gets recognized as unicode and therefore
 the code in the second if is run. On the home computer, the string is not
 recognized as unicode and the last line is run and causes the error.

 However, if I modify the code as such:

 {{{
     print type(string)
     if isinstance(string, bytes):
         print "isinstance bytes"
         return string
     if isinstance(string, unicode):
         print "isinstance unicode"
         enc = _get_encoding()
         return string.encode(enc)
     print "isinstance none"
     return bytes(string)
 }}}

 the output I get is


 {{{
 > v.to.rast --ui
 <type 'str'>
 isinstance bytes
 <type 'str'>
 isinstance bytes
 <type 'unicode'>       <==================
 isinstance none        <==================
 Traceback (most recent call last):
   File "/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-
 gnu/gui/wxpython/gui_core/forms.py", line 2995, in <module>
     task.get_cmd(ignoreErrors=True, ignoreRequired=True))
   File "/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-
 gnu/etc/python/grass/script/task.py", line 248, in get_cmd
     errList = self.get_cmd_error()
   File "/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-
 gnu/etc/python/grass/script/task.py", line 208, in get_cmd_error
     {'name': p['name'], 'desc': encode(desc)})
   File "/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-
 gnu/etc/python/grass/script/utils.py", line 221, in encode
     return bytes(string)
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
 position 36: ordinal not in range(128)
 }}}

 In other words, it is recognized as type unicode, but isinstance(string,
 unicode) returns false...

 Actually, when type is 'str' it is recognized as unicode:


 {{{
     print type(string)
     print isinstance(string, unicode)
 }}}

 gives

 {{{
 <type 'str'>
 True
 <type 'str'>
 True
 <type 'unicode'>
 False
 }}}



 Any hints explaining why this is happening on one machine, but not the
 other ? Python versions are identical (Python 2.7.13).

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3405#comment:6>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list