On Wednesday, March 30, 2016 at 11:32:50 AM UTC-5, Edward K. Ream wrote:

*​Important*: leoGlobals​.py has a number of convenience functions that 
> make these tests automatically. You should be particularly aware of:
>
> - g.isBytes, g.isInt, g.isString, g.isUnicode.
> - g.toUnicode, g.toEncodedString, g.isValidEncoding.
> - g.u, g.ue.
>
> If you use the above methods there should never be a need for direct calls 
> to unicode(s), encode(s) or decode(s).  The above methods are clearer, 
> safer, and do better error checking and recovery.
>
> I don't have time to go into details now, but I'll be doing a post on 
> there for devs.
>

*Important*: g.u and g.toUnicode are not always interchangeable. In fact, 
you should use g.u to convert Qt QStrings to unicode. Here is an example 
from quicksearch.py:

    t = g.u(self.ui.lineEdit.text())

Similarly, g.ue should be used to convert Qt bytes to unicode. Here is an 
example from LM.openZipFile:

    s = theFile.read(name)
    if g.isPython3:
        s = g.ue(s, 'utf-8')
    return StringIO(s)

Actually, the above code is dubious, because it will break if the mode of 
the open command changes.

In addition, the code sometimes does s = g.u('aString'), but this isn't 
really needed since Python 2.6(?) which supports unicode literals.

EKR

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to