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 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:
          # based on the compressor detected in the file, we open the
          # correct decompressor file object, wrapped in a buffer.
          if compressor == "zlib":
              fileobj = _buffered_read_file(
                  BinaryZlibFile(fileobj, "rb")
              )
          elif compressor == "gzip":
              fileobj = _buffered_read_file(
                  BinaryGzipFile(fileobj, "rb")
              )
          elif compressor == "bz2" and bz2 is not None:
              if PY3_OR_LATER:
                  fileobj = _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.
                  fileobj = _buffered_read_file(
                      bz2.BZ2File(fileobj.name, "rb")
                  )
          elif compressor == "lzma" or compressor == "xz":
              if PY3_OR_LATER and lzma is not None:
                  # We support lzma only in python 3 because in python 2 users
                  # may have installed the pyliblzma package, which also provides
                  # the lzma module, but that unfortunately doesn't fully support
                  # the buffer interface required by joblib.
                  # See https://github.com/joblib/joblib/issues/403 for details.
                  fileobj = _buffered_read_file(
                      lzma.LZMAFile(fileobj, "rb")
                  )
              else:
                  raise NotImplementedError(
                      "Lzma decompression is not "
                      "supported for this version of "
                      "python ({}.{})".format(
                          sys.version_info[0], sys.version_info[1]
                      )
                  )
          # 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 mmap_mode is not None:
              if isinstance(fileobj, io.BytesIO):
                  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,
                  )
              elif compressor != "not-compressed":
                  warnings.warn(
                      'mmap_mode "%(mmap_mode)s" is not compatible '
                      "with compressed file %(filename)s. "
                      '"%(mmap_mode)s" flag will be ignored.'
                      % locals(),
                      stacklevel=2,
                  )
              elif not _is_raw_file(fileobj):
                  warnings.warn(
                      '"%(fileobj)r" is not a raw file, mmap_mode '
                      '"%(mmap_mode)s" flag will be ignored.'
                      % locals(),
                      stacklevel=2,
                  )
  
          yield fileobj
  
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 5 for calling a global function with example usage: _read_fileobject(fileobj, filename, mmap_mode) without return types