code: def _write_fileobject(filename, compress=("zlib", 3)):
      """Return the right compressor file object in write mode."""
      compressmethod = compress[0]
      compresslevel = compress[1]
      if compressmethod == "gzip":
          return _buffered_write_file(
              BinaryGzipFile(
                  filename, "wb", compresslevel=compresslevel
              )
          )
      elif compressmethod == "bz2" and bz2 is not None:
          return _buffered_write_file(
              bz2.BZ2File(filename, "wb", compresslevel=compresslevel)
          )
      elif lzma is not None and compressmethod == "xz":
          return _buffered_write_file(
              lzma.LZMAFile(
                  filename,
                  "wb",
                  check=lzma.CHECK_NONE,
                  preset=compresslevel,
              )
          )
      elif lzma is not None and compressmethod == "lzma":
          return _buffered_write_file(
              lzma.LZMAFile(
                  filename,
                  "wb",
                  preset=compresslevel,
                  format=lzma.FORMAT_ALONE,
              )
          )
      else:
          return _buffered_write_file(
              BinaryZlibFile(
                  filename, "wb", compresslevel=compresslevel
              )
          )
  
imports: import pickle
  import sys
  import io
  import zlib
  import gzip
  import warnings
  import contextlib
  from contextlib import closing
  from ._compat import PY3_OR_LATER, PY27, _basestring
label_desc: Use image node_id 6 for calling a global function with example usage: _write_fileobject(filename, compress) and returns: _buffered_write_file, _buffered_write_file, _buffered_write_file, _buffered_write_file, _buffered_write_file