def getdefaultencoding(prefer_stream=True):
 enc = None
 if prefer_stream:
  enc = get_stream_enc(sys.stdin)
 if ((not enc) or (enc == 'ascii')):
  try:
   enc = locale.getpreferredencoding()
  except Exception:
   pass
 enc = (enc or sys.getdefaultencoding())
 if (enc == 'cp0'):
  warnings.warn('Invalid code page cp0 detected - using cp1252 instead.If cp1252 is incorrect please ensure a valid code page is defined for the process.', RuntimeWarning)
  return 'cp1252'
 return enc

def getdefaultencoding ( prefer_stream = True ) : enc = None if prefer_stream : enc = get_stream_enc ( sys . stdin ) if ( ( not enc ) or ( enc == 'ascii' ) ) : try : enc = locale . getpreferredencoding ( ) except Exception : pass enc = ( enc or sys . getdefaultencoding ( ) ) if ( enc == 'cp0' ) : warnings . warn ( 'Invalid code page cp0 detected - using cp1252 instead.If cp1252 is incorrect please ensure a valid code page is defined for the process.' , RuntimeWarning ) return 'cp1252' return enc
return ipythons guess for the default encoding for bytes as text .