<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ensure_unicode(text):

 u"""helper to ensure that text passed to WriteConsoleW is unicode"""

    if isinstance(text, str):
        try:
            return text.decode(pyreadline_codepage, u"replace")
        except (LookupError, TypeError):
            return text.decode(u"ascii", u"replace")
    return text