Hi Dan,

sorry, but I have another patch for fvwm-menu-desktop again ...

On a system with wine the following error occur:
Traceback (most recent call last):
  File "./fvwm-menu-desktop.in.py", line 536, in <module>
    main()
  File "./fvwm-menu-desktop.in.py", line 213, in main
    parsemenus(menulist, desktop)
  File "./fvwm-menu-desktop.in.py", line 429, in parsemenus
    parsemenu(xdg.Menu.parse(menu), name, title)
  File "./fvwm-menu-desktop.in.py", line 502, in parsemenu
    parsemenu(entry)
  File "./fvwm-menu-desktop.in.py", line 486, in parsemenu
printmenu(desktop.getName(), desktop.getIcon(), "Exec exec " + " " + execProgram)
  File "./fvwm-menu-desktop.in.py", line 407, in printmenu
    printtext('+ "%s%s" %s' % (name, iconfile, command))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 154: ordinal not in range(128)

This happens because the text will be decoded to utf-8 but there's a sign
over ascii 127 like ä,ö,ü ... so it fails.

The fix is to encode it to unicode and then decode it with iso-8859-15
to the correct string.

About this problem see
http://blog.codekills.net/2008/05/01/encoding-and-decoding-text-in-python-%28or---i-didn%27t-ask-you-to-use-the-%27ascii%27-codec!-%29/ <https://3c.web.de/mail/client/dereferrer?redirectUrl=http%3A%2F%2Fblog.codekills.net%2F2008%2F05%2F01%2Fencoding-and-decoding-text-in-python-%2528or---i-didn%2527t-ask-you-to-use-the-%2527ascii%2527-codec%2521-%2529%2F&selection=tfol119b5fa8ee852800>

Regards,
Thomas



--- ../cvs/fvwm/bin/fvwm-menu-desktop.in	2012-09-07 23:58:20.407275653 +0200
+++ fvwm-menu-desktop.in.py	2012-09-08 00:10:36.551201906 +0200
@@ -409,7 +409,18 @@
         iconfile = geticonfile(icon) or getdefaulticonfile(command) or icon
         if not iconfile == '':
             iconfile = '%'+iconfile+'%'
-    printtext('+ "%s%s" %s' % (name, iconfile, command))
+    # fix unicode decode problem like
+    # UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position xyz: ordinal not in range(128) 
+    try:
+        printtext('+ "%s%s" %s' % (name, iconfile, command))
+    except UnicodeDecodeError:
+        try:
+            unicode_name = name.decode("iso-8859-15")
+            unicode_command = command.decode("iso-8859-15")
+            text = '+ "%s%s" %s' % (unicode_name, iconfile, unicode_command)
+            print text.encode("iso-8859-15")
+        except:
+            sys.stderr.write("A menu entry cannot decode! Skipping it ...\n")
 
 def parsemenus(menulist, desktop):
     global menu_entry_count

Reply via email to