from qt import *
from types import StringType


def from_utf8(utf8str):
    # for the given string in utf8 encoding, return
    # a QString instance in utf8 
    return QString.fromUtf8(utf8str)


def to_utf8(s):
    # for the given python string or QString, return a
    # python str that is utf-8 encoded
    if type(s) is StringType:
        # python string
        u = unicode(s, 'utf-8')
    else:
        # QString 
        u = unicode(s)
    #print "type u: ", type(u.encode('utf-8'))
    return u.encode('utf-8')
        
