Re: Patch for fvwm-menu-desktop to fix UnicodeDecodeError

2012-10-03 Thread Thomas Funk

Dan Espen wrote:
 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?

Because wine applications create desktop files with another codepage
than linux apps do. The best solution was to decode the strings with
iso-8859-15 because this codepage has the most special characters as
all other codepages.


 Don't other calls to printtext using menu names share this problem?

No.


 Just wondering if it makes more sense to put the logic in printtext.

That was my first thought but the error occurs while calling printtext.
printtext expects unicode compliant strings (chars below ascii 127).
Perhaps we could made a decode function which brings the strings in the
correct format before sending to printtext. but only the wrong formated
strings need this function others not. The solution above was the smallest.


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

Doesn't work because print wants strings without signs above ascii 127 also.
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/

again.


Thomas



Re: Patch for fvwm-menu-desktop to fix UnicodeDecodeError

2012-10-01 Thread Thomas Funk

Hi Dan!

have you got this email below? If so, what do you think?

To state the problem more precisely:

This issue happens if wine is installed on the system and also some
apps. The command entries have often signs over ascii 127 if the
user lives outside England or United States. Therefore I think it
is important to implement this fix ...

Thanks,
Thomas

Thomas Funk wrote:
 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/





Re: Patch for fvwm-menu-desktop to fix UnicodeDecodeError

2012-10-01 Thread Dan Espen
Thomas Funk t.f...@web.de 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