Opened 11 years ago

Last modified 9 years ago

#2050 new defect

After GRASS started xml.etree.ElementTree raises ParseError when clicking any GUI element on Win 7 Simplified Chinese

Reported by: lazywalking Owned by: grass-dev@…
Priority: major Milestone: 6.4.6
Component: wxGUI Version: unspecified
Keywords: chinese, windows 7, gui, encoding Cc:
CPU: Unspecified Platform: MSWindows 7

Description

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.

Change History (2)

comment:1 by improgrammer, 11 years ago

The same question as 1941

comment:2 by neteler, 9 years ago

Milestone: 6.4.36.4.6
Note: See TracTickets for help on using tickets.