#7 RFE: Accept unicode in python bindings
Opened 2 years ago by mlichvar. Modified 2 years ago

This issue was moved here from https://bugzilla.redhat.com/show_bug.cgi?id=689448

Miroslav Suchý 2011-03-21 10:51:50 EDT

Current newt-python does not accept unicode for text parameters.

E.g. if you modify peanut.py from example:

t = TextboxReflowed(25, "Some text which needs to be wrapped at a good place.")


-- coding: utf-8 --

t = TextboxReflowed(25, u"žžž")

you will get:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)

It will work if you pass as parameter
i.e. object string encoded as utf-8 - but that is different from object unicode, see:

<type 'unicode'>
<type 'str'>

And it will work if you pass as parameter:

So this can be work arounded for sure. But it will be nice if newt-python can accept true unicode type.

Comment 1 Miroslav Suchý 2011-03-21 16:01:38 EDT

I spent some time investigating this. And the cause is best described here:

s (string or Unicode) [const char ]...Unicode objects are converted to C strings using the default encoding*...
(emphasis is mine)

And problem with default encoding is best described here:

And in mailing thread:

So one solution is to put into snackmodule.c:
but that is probably wrong approach.

Second option is to put at the begging each function of snack.py this:
if isinstance(text, unicode):
text = text.encode('utf-8')
for every text parameter.

Login to comment on this ticket.