Bug 689448 - RFE: Accept unicode in python bindings
Summary: RFE: Accept unicode in python bindings
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Fedora
Classification: Fedora
Component: newt
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
low
Target Milestone: ---
Assignee: Miroslav Lichvar
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-03-21 14:51 UTC by Miroslav Suchý
Modified: 2018-07-27 13:24 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-07-27 13:24:52 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Miroslav Suchý 2011-03-21 14:51:50 UTC
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.")

to 

# -*- 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:
http://docs.python.org/howto/unicode.html#the-unicode-type
and:
>>> type(u"žžž")
<type 'unicode'>
>>> type("žžž")
<type 'str'>

And it will work if you pass as parameter:
 u"žžž".encode('utf-8')

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 20:01:38 UTC
I spent some time investigating this. And the cause is best described here:
http://docs.python.org/c-api/arg.html

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:

http://fedoraproject.org/wiki/Features/PythonEncodingUsesSystemLocale
And in mailing thread:
http://thread.gmane.org/gmane.comp.python.devel/109914

So one solution is to put into snackmodule.c:
PyUnicode_SetDefaultEncoding("utf-8");
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.

Comment 2 Miroslav Lichvar 2018-07-27 13:24:52 UTC
I've moved this RFE to the upstream tracker: https://pagure.io/newt/issue/7


Note You need to log in before you can comment on or make changes to this bug.