From: Benny M. <ben...@gm...> - 2009-07-02 08:07:39
|
Yeah, finally success :-) Gerald, is there a way to do something like inline functions in python? So, from the script Peter ran, it appears what is needed on windows is: d = sorted((locale.strxfrm(x.decode("utf-8").encode(code)),x) for x in b) Peter, can you check for certainty that strxfrm really does not work if unicode is passed, so change the above in d = sorted((locale.strxfrm(x.decode("utf-8")),x) for x in b) I see that in GRAMPS for the GTK models everything is converted to unicode already, no utf-8 is used. If that works anyway, it means strxfrm can internally change unicode to the os encoding, if not it means that strxfrm sees the unicode string in the internal python encoding. My suggestion would be a Utils functions: import platform import const """ Define a function that can convert to a sortkey in such a way that the C library function works correctly. In essence this means the C library needs to recieve the string in byte code corresponding to the encoding it is compiled with """ if platform in const.WINDOWS: # in windows the encoding is normally not utf-8 so for C functions one needs # to convert to the windows encoding, passing by unicode if needed import GrampsLocale conv_utf8_tosrtkey = lambda x: locale.strxfrm(x.decode("utf-8").encode(GrampsLocale.codeset)) conv_unicode_tosrtkey = lambda x: locale.strxfrm(x.encode(GrampsLocale.codeset)) else: # on unix internally unicode is utf-8 and C lib is also utf-8, so no conv needed conv_utf8_tosrtkey = lambda x: locale.strxfrm(x) conv_unicode_tosrtkey = lambda x: locale.strxfrm(x) It would be nice if these sortfunc could be inline somehow. Benny |