Thomas Funk <[email protected]> writes:

>    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 [removed] ... 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-pyth
>    on-%28or---i-didn%27t-ask-you-to-use-the-%27ascii%27-codec!-%29/
>    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

Sorry this escaped my attention.

The patch above intercepts a failure in printtext which does this:

def printtext(text):
    print text.encode("utf-8")

So if I understand the patch, it intercepts one failure to do utf-8
encoding and tries using iso-8859-15 instead.

Why is only that call to printtext subject to this failure?
Don't other calls to printtext using menu names share this problem?
Just wondering if it makes more sense to put the logic in printtext.

How about just printing the text without encoding it, if encoding fails?


-- 
Dan Espen

Reply via email to