def ensure_unicode(s):
 if isinstance(s, unicode):
  return s
 if hasattr(s, 'decode'):
  return s.decode()
 msg = 'Object %s is neither a bytes object nor has an encode method'
 raise TypeError((msg % s))

def ensure_unicode ( s ) : if isinstance ( s , unicode ) : return s if hasattr ( s , 'decode' ) : return s . decode ( ) msg = 'Object %s is neither a bytes object nor has an encode method' raise TypeError ( ( msg % s ) )
helper to ensure that text passed to writeconsolew is unicode .