def _stream_encoding(stream, default='utf-8'):
 encoding = config['terminal_encoding'].get()
 if encoding:
  return encoding
 if (not hasattr(stream, 'encoding')):
  return default
 return (stream.encoding or default)

def _stream_encoding ( stream , default = 'utf-8' ) : encoding = config [ 'terminal_encoding' ] . get ( ) if encoding : return encoding if ( not hasattr ( stream , 'encoding' ) ) : return default return ( stream . encoding or default )
a helper for _in_encoding and _out_encoding: get the streams preferred encoding .