ponty / psidialogs

Python Simple Dialogs
BSD 2-Clause "Simplified" License
34 stars 2 forks source link

Console backend breaks on non ASCII unicode strings #2

Closed icemac closed 12 years ago

icemac commented 12 years ago

If I call the message method on the console backend with unicode string containing a non-ASCII character it breaks with a UnicodeDecodeError but for other backends (I forgot which one(s)) it is required to use unicode to prevent a UnicodeEncodeError.

Please make sure that at least unicode works for all backends (other methods have the same problem).

ponty commented 12 years ago

I added unicode support, check it out.

icemac commented 12 years ago

Am 09.02.2012 um 15:44 schrieb ponty:

I added unicode support, check it out.

Nice, but I found one problem: The default argument of a choice gets converted to a string, this breaks with a UnicodeError if it contains something outside ASCII:

.../psidialogs-0.0.5-py2.7.egg/psidialogs/mixins.py(25)_choice() -> args.default=str(args.default) (Pdb) l 20 args = args.copy() 21 lines = [ '[%s] %s' % x for x in zip(count(), args.choices) ] 22 args.message += '\n' + '\n'.join(lines) 23 args.message += '\nSelect:' 24 ## self.text(args) 25 -> args.default=str(args.default)

ponty commented 12 years ago

I replaced "str" with "unicode". If this works then I upload it to PYPI

icemac commented 12 years ago

Am 16.02.2012 um 14:05 schrieb ponty:

I replaced "str" with "unicode". If this works then I upload it to PYPI

Works like a charm for console backend, easygui backend breaks: If the choice options are unicode strings containing non-ASCII characters the following traceback occurrs:

File ".../psidialogs/plugins/easygui_wrapper.py", line 24, in choice return easygui.choicebox(msg=args.message, title=args.title, choices=args.choices) File ".../easygui-0.96-py2.7.egg/easygui.py", line 1017, in choicebox return choicebox(msg,title,choices) File ".../easygui-0.96-py2.7.egg/easygui.py", line 1045, in choicebox choices[index] = str(choices[index]) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 10: ordinal not in range(128)

But if the choice options are UTF-8 encoded strings, easygui returns the chosen value as unicode! So it's not compatible with both backends.

ponty commented 12 years ago
icemac commented 12 years ago

Am 18.02.2012 um 10:20 schrieb ponty:

Nice work! Thank you! :-D Tested it successfully with console and easygui backends.