[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] sipForceConvertToType and Unicode in PyKDE4
From:       Luca Beltrame <einar () heavensinferno ! net>
Date:       2013-05-06 18:20:11
Message-ID: 2177225.kAaC8Scdi8 () leon
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


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

["signature.asc" (application/pgp-signature)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic