def get_best_encoding(stream):
 rv = (getattr(stream, 'encoding', None) or sys.getdefaultencoding())
 if is_ascii_encoding(rv):
  return 'utf-8'
 return rv

def get_best_encoding ( stream ) : rv = ( getattr ( stream , 'encoding' , None ) or sys . getdefaultencoding ( ) ) if is_ascii_encoding ( rv ) : return 'utf-8' return rv
returns the default stream encoding if not found .