code: def _read_fileobject(fileobj, filename, mmap_mode=None):
      """Utility function opening the right fileobject from a filename.
  
      The magic number is used to choose between the type of file object to open:
      * regular file object (default)
      * zlib file object
      * gzip file object
      * bz2 file object
      * lzma file object (for xz and lzma compressor)
  
      Parameters
      ----------
      fileobj: file object
      compressor: str in {'zlib', 'gzip', 'bz2', 'lzma', 'xz', 'compat',
                          'not-compressed'}
      filename: str
          filename path corresponding to the fileobj parameter.
      mmap_mode: str
          memory map mode that should be used to open the pickle file. This
          parameter is useful to verify that the user is not trying to one with
          compression. Default: None.
  
      Returns
      -------
          a file like object
  
      """
      # Detect if the fileobj contains compressed data.
      compressor = _detect_compressor(fileobj)
      if isinstance(fileobj, tuple(_COMPRESSOR_CLASSES)):
          compressor = fileobj.__class__.__name__
      if compressor == "compat":
          # Compatibility with old pickle mode: simply return the input
          # filename "as-is" and let the compatibility function be called by the
          # caller.
          warnings.warn(
              "The file '%s' has been generated with a joblib "
              "version less than 0.10. "
              "Please regenerate this pickle file." % filename,
              DeprecationWarning,
              stacklevel=2,
          )
          yield filename
      else:
          # Checking if incompatible load parameters with the type of file:
          # mmap_mode cannot be used with compressed file or in memory buffers
          # such as io.BytesIO.
          if (
              compressor in _COMPRESSORS
              or isinstance(fileobj, tuple(_COMPRESSOR_CLASSES))
          ) and mmap_mode is not None:
              warnings.warn(
                  'File "%(filename)s" is compressed using '
                  '"%(compressor)s" which is not compatible with '
                  'mmap_mode "%(mmap_mode)s" flag passed. mmap_mode '
                  "option will be ignored." % locals(),
                  stacklevel=2,
              )
          if isinstance(fileobj, io.BytesIO) and mmap_mode is not None:
              warnings.warn(
                  "In memory persistence is not compatible with "
                  'mmap_mode "%(mmap_mode)s" flag passed. mmap_mode '
                  "option will be ignored." % locals(),
                  stacklevel=2,
              )
  
          # if the passed fileobj is in the supported list of decompressor
          # objects (GzipFile, BZ2File, LzmaFile), we simply return it.
          if isinstance(fileobj, tuple(_COMPRESSOR_CLASSES)):
              yield fileobj
          # otherwise, based on the compressor detected in the file, we open the
          # correct decompressor file object, wrapped in a buffer.
          elif compressor == "zlib":
              yield _buffered_read_file(BinaryZlibFile(fileobj, "rb"))
          elif compressor == "gzip":
              yield _buffered_read_file(BinaryGzipFile(fileobj, "rb"))
          elif compressor == "bz2":
              if PY3_OR_LATER:
                  yield _buffered_read_file(bz2.BZ2File(fileobj, "rb"))
              else:
                  # In python 2, BZ2File doesn't support a fileobj opened in
                  # binary mode. In this case, we pass the filename.
                  yield _buffered_read_file(
                      bz2.BZ2File(fileobj.name, "rb")
                  )
          elif compressor == "lzma" or compressor == "xz":
              if lzma is not None:
                  yield _buffered_read_file(
                      lzma.LZMAFile(fileobj, "rb")
                  )
              else:
                  raise NotImplementedError(
                      "Lzma decompression is not "
                      "available for this version of "
                      "python ({0}.{1})".format(
                          sys.version_info[0], sys.version_info[1]
                      )
                  )
          # No compression detected => returning the input file object (open)
          else:
              yield fileobj
  
imports: import pickle
  import sys
  import io
  import zlib
  import gzip
  import bz2
  import warnings
  import contextlib
  from contextlib import closing
  from ._compat import PY3_OR_LATER, PY26, PY27, _basestring
label_desc: Use image node_id 4 for calling a global function with example usage: _read_fileobject(fileobj, filename, mmap_mode) without return types