[PyQt] sipForceConvertToType and Unicode in PyKDE4

Luca Beltrame einar at heavensinferno.net
Mon May 6 19:20:11 BST 2013


Hello,                                                                         
                                                                               
recently it turned out that KLocalizedString in PyKDE4 is not working properly
in Python 3 and Python 2. The code path hasn't changed since 2008.             
                                                                               
What it looks like is that unicode strings are passed with "ascii", then
encoded with utf-8. In Py2, if this process fails fails, the object gets
passed as bytes, and works.In Py3, it doesn't work because encoding with ascii
raises and exception. It only works if the object is passed in bytes.
                                                                               
IOW, unicode-containing strings that weren't manually encoded to utf-8 byte
strings will not work. (analysis here: https://gist.github.com/flying-sheep/5520997 )
                                                                               
Ultimately, this is what the code does in PyKDE4:
                                                                               
KLocalizedString result = base;
QString *arg;                                                                  
int iserr = 0;                                                                 
                                                                               
                                                                               
for (int i=0; i < PyTuple_Size(list); i++) {                                   
     PyObject *pyarg = PyTuple_GET_ITEM (list, i);                             
                                                                               
// ... further down in the code  

   }                                                                           

    result = result.subs(*arg);                                                
    sipReleaseType(arg,sipType_QString,state);                                 
    arg = 0;                                                                   
}                                                                              
                                                                               
return result.toString();                                                      
                                                                               
"base" is a  KlocalizedString passed to the function, and so is sipIsErr.
*list is a PyObject.                                                           
                                                                               
At least from the initial investigation, the error seems to fall here in this 
code. Phil, where should I look to debug this problem further? Or are there
alternatives to debug these conversions so I can find the real culprit? 
                                                                               
-- 
Luca Beltrame - KDE Forums team
KDE Science supporter
GPG key ID: 6E1A4E79
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130506/e1cc7330/attachment.pgp>


More information about the PyQt mailing list