def _write_with_fallback(s, write, fileobj):
 if ((IPythonIOStream is not None) and isinstance(fileobj, IPythonIOStream)):
  write = fileobj.stream.write
 try:
  write(s)
  return write
 except UnicodeEncodeError:
  pass
 enc = locale.getpreferredencoding()
 try:
  Writer = codecs.getwriter(enc)
 except LookupError:
  Writer = codecs.getwriter(_DEFAULT_ENCODING)
 f = Writer(fileobj)
 write = f.write
 try:
  write(s)
  return write
 except UnicodeEncodeError:
  Writer = codecs.getwriter(u'latin-1')
  f = Writer(fileobj)
  write = f.write
 write(s)
 return write

def _write_with_fallback ( s , write , fileobj ) : if ( ( IPythonIOStream is not None ) and isinstance ( fileobj , IPythonIOStream ) ) : write = fileobj . stream . write try : write ( s ) return write except UnicodeEncodeError : pass enc = locale . getpreferredencoding ( ) try : Writer = codecs . getwriter ( enc ) except LookupError : Writer = codecs . getwriter ( _DEFAULT_ENCODING ) f = Writer ( fileobj ) write = f . write try : write ( s ) return write except UnicodeEncodeError : Writer = codecs . getwriter ( u'latin-1' ) f = Writer ( fileobj ) write = f . write write ( s ) return write
write the supplied string with the given write function like write(s) .