def write_block_to_file(data, lazy_file):
 binary = ('b' in str(getattr(lazy_file, 'mode', 'b')))
 with lazy_file as f:
  if isinstance(f, io.TextIOWrapper):
   binary = False
  if binary:
   ensure = ensure_bytes
  else:
   ensure = ensure_unicode
  if isinstance(data, (str, bytes, unicode)):
   f.write(ensure(data))
  elif isinstance(data, io.IOBase):
   out = True
   while out:
    out = data.read((64 * (2 ** 10)))
    f.write(ensure(out))
  else:
   start = False
   for d in data:
    if start:
     if binary:
      try:
       f.write('\n')
      except TypeError:
       binary = False
       f.write('\n')
     else:
      f.write(u'\n')
    else:
     start = True
    f.write(ensure(d))

def write_block_to_file ( data , lazy_file ) : binary = ( 'b' in str ( getattr ( lazy_file , 'mode' , 'b' ) ) ) with lazy_file as f : if isinstance ( f , io . TextIOWrapper ) : binary = False if binary : ensure = ensure_bytes else : ensure = ensure_unicode if isinstance ( data , ( str , bytes , unicode ) ) : f . write ( ensure ( data ) ) elif isinstance ( data , io . IOBase ) : out = True while out : out = data . read ( ( 64 * ( 2 ** 10 ) ) ) f . write ( ensure ( out ) ) else : start = False for d in data : if start : if binary : try : f . write ( '\n' ) except TypeError : binary = False f . write ( '\n' ) else : f . write ( u'\n' ) else : start = True f . write ( ensure ( d ) )
parameters data : data to write either str/bytes .