def ensure_str(text):
 if isinstance(text, unicode):
  return text.encode(pyreadline_codepage, 'replace')
 return text

def ensure_str ( text ) : if isinstance ( text , unicode ) : return text . encode ( pyreadline_codepage , 'replace' ) return text
convert unicode to str using pyreadline_codepage .