def get_file_writer(file_handle, do_gzip, do_bzip):
 ofile = None
 if (do_gzip and do_bzip):
  raise ValueError(u'Cannot specify both bzip and gzip compression!')
 if do_gzip:
  ofile = gzip.GzipFile(fileobj=file_handle, mode=u'w')
 elif do_bzip:
  ofile = bz2file.open(file_handle, mode=u'w')
 else:
  ofile = file_handle
 return ofile

def get_file_writer ( file_handle , do_gzip , do_bzip ) : ofile = None if ( do_gzip and do_bzip ) : raise ValueError ( u'Cannot specify both bzip and gzip compression!' ) if do_gzip : ofile = gzip . GzipFile ( fileobj = file_handle , mode = u'w' ) elif do_bzip : ofile = bz2file . open ( file_handle , mode = u'w' ) else : ofile = file_handle return ofile
generate and return a file object with specified compression .