[GRASS-dev] [GRASS GIS] #2050: After GRASS started xml.etree.ElementTree raises ParseError when clicking any GUI element on Win 7 Simplified Chinese

#2050: After GRASS started xml.etree.ElementTree raises ParseError when clicking
any GUI element on Win 7 Simplified Chinese
----------------------------------------------+-----------------------------
Reporter: lazywalking | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: chinese,windows 7, gui, encoding | Platform: MSWindows 7
      Cpu: Unspecified |
----------------------------------------------+-----------------------------
I'm using Win7 Simplified Chinese, with GRASS 6.4.3RC4 installed. After
GRASS started successfully, it raises ParseError in xml.etree.ElementTree
module when I click any tool or menu in Layer Manager window. For Example,
if I click "Add vector map layer" tool, error messages below will display
in Command Console, and d.vect setting window can't open.

----
''Traceback (most recent call last):
   File "d:\GRASS\etc\wxpython\lmgr\frame.py", line 1563, in
OnAddVector

self.curr_page.maptree.AddLayer('vector')
   File "d:\GRASS\etc\wxpython\lmgr\layertree.py", line 924,
in AddLayer

self.PropertiesDialog(layer, show = True)
   File "d:\GRASS\etc\wxpython\lmgr\layertree.py", line 1036,
in PropertiesDialog

completed = (self.GetOptData,layer,params))
   File "d:\GRASS\etc\wxpython\gui_core\forms.py", line 1871,
in ParseCommand

blackList = _blackList)
   File "d:\GRASS\etc\python\grass\script\task.py", line 470,
in parse_interface

tree = etree.fromstring(get_interface_description(name))
   File "d:\GRASS\Python27\lib\xml\etree\ElementTree.py",
line 1300, in XML

parser.feed(text)
   File "d:\GRASS\Python27\lib\xml\etree\ElementTree.py",
line 1642, in feed

self._raiseerror(v)
   File "d:\GRASS\Python27\lib\xml\etree\ElementTree.py",
line 1506, in _raiseerror

raise err
xml.etree.ElementTree
.
ParseError
:
unknown encoding: line 1, column 30''
----

Finally I find that the bug is in task.py file with lines 460-470.

{{{
     enc = locale.getdefaultlocale()[1]
     if enc and enc.lower() == 'cp932':
         p = re.compile('encoding="' + enc + '"', re.IGNORECASE)
         tree = etree.fromstring(p.sub('encoding="utf-8"',
get_interface_description(name).decode(enc).encode("utf-8")))
     else:
        tree = etree.fromstring(get_interface_description(name))
}}}

On my PC, enc is 'cp936', but the encoding of string returned by
get_interface_description(name) is 'gbk'. I replace first two sentences
with

{{{
     enc = locale.encodings.aliases.aliases[locale.getdefaultlocale()[1]]
     if enc and enc.lower() != 'utf-8':
}}}
.
It works fine on my PC. But I don't know whether it succeeds in other
conditions.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2050&gt;
GRASS GIS <http://grass.osgeo.org>

#2050: After GRASS started xml.etree.ElementTree raises ParseError when clicking
any GUI element on Win 7 Simplified Chinese
----------------------------------------------+-----------------------------
Reporter: lazywalking | Owner: grass-dev@…
     Type: defect | Status: new
Priority: major | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: chinese,windows 7, gui, encoding | Platform: MSWindows 7
      Cpu: Unspecified |
----------------------------------------------+-----------------------------

Comment(by improgrammer):

The same question as [ticket:1941]

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2050#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>