[GRASS-SVN] r57501 - in grass/trunk: gui/wxpython/gui_core lib/python/script
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Aug 25 15:22:45 PDT 2013
Author: annakrat
Date: 2013-08-25 15:22:45 -0700 (Sun, 25 Aug 2013)
New Revision: 57501
Modified:
grass/trunk/gui/wxpython/gui_core/forms.py
grass/trunk/lib/python/script/task.py
Log:
wxGUI: apply patch from #1941 (Japanese locale) for testing
Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py 2013-08-25 12:12:36 UTC (rev 57500)
+++ grass/trunk/gui/wxpython/gui_core/forms.py 2013-08-25 22:22:45 UTC (rev 57501)
@@ -2347,13 +2347,7 @@
"""
# parse the interface decription
if not self.grass_task:
- 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"',
- gtask.get_interface_description(cmd).decode(enc).encode('utf-8')))
- else:
- tree = etree.fromstring(gtask.get_interface_description(cmd))
+ tree = etree.fromstring(gtask.get_interface_description(cmd))
self.grass_task = gtask.processTask(tree).get_task()
for p in self.grass_task.params:
Modified: grass/trunk/lib/python/script/task.py
===================================================================
--- grass/trunk/lib/python/script/task.py 2013-08-25 12:12:36 UTC (rev 57500)
+++ grass/trunk/lib/python/script/task.py 2013-08-25 22:22:45 UTC (rev 57501)
@@ -433,8 +433,27 @@
"""!Get grassTask instance"""
return self.task
+def convert_xml_to_utf8(xml_text):
+ # enc = locale.getdefaultlocale()[1]
+
+ # modify: fetch encoding from the interface description text(xml)
+ # e.g. <?xml version="1.0" encoding="GBK"?>
+ pattern = re.compile('<\?xml[^>]*\Wencoding="([^"]*)"[^>]*\?>')
+ m = re.match(pattern, xml_text)
+ if m == None:
+ return xml_text
+ #
+ enc = m.groups()[0]
+
+ # modify: change the encoding to "utf-8", for correct parsing
+ xml_text_utf8 = xml_text.decode(enc).encode("utf-8")
+ p = re.compile('encoding="' + enc + '"', re.IGNORECASE)
+ xml_text_utf8 = p.sub('encoding="utf-8"', xml_text_utf8)
+
+ return xml_text_utf8
+
def get_interface_description(cmd):
- """!Returns the XML description for the GRASS cmd.
+ """!Returns the XML description for the GRASS cmd (force text encoding to "utf-8").
The DTD must be located in $GISBASE/etc/grass-interface.dtd,
otherwise the parser will not succeed.
@@ -471,21 +490,15 @@
# raise ScriptError, _("Unable to fetch interface description for command '%(cmd)s'."
# "\n\nDetails: %(det)s") % { 'cmd': cmd, 'det' : decode(cmderr) }
- return cmdout.replace('grass-interface.dtd', os.path.join(os.getenv('GISBASE'), 'etc', 'grass-interface.dtd'))
+ desc = cmdout.replace('grass-interface.dtd', os.path.join(os.getenv('GISBASE'), 'etc', 'grass-interface.dtd'))
+ return convert_xml_to_utf8(desc)
def parse_interface(name, parser = processTask, blackList = None):
"""!Parse interface of given GRASS module
@param name name of GRASS module to be parsed
"""
- 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))
-
+ tree = etree.fromstring(get_interface_description(name))
return parser(tree, blackList = blackList).get_task()
def command_info(cmd):
More information about the grass-commit
mailing list