def ustr(what):
    """Converts object "what" to unicode string using it's own __str__ method if accessible or unicode method otherwise."""
    if isinstance(what, unicode): return what
    try: r=what.__str__()
    except AttributeError: r=str(what)
    if not isinstance(r, unicode): return unicode(r,ENCODING)
    return r
Converts object "what" to unicode string using it's own __str__ method if accessible or unicode method otherwise.
chrome-cordova/gcmServer/xmpp/simplexml.py