code: def _gen_open(f):
      if isinstance(f, int):  # file descriptor
          return open(f, "rb", closefd=False)
      elif isinstance(f, os.PathLike):
          f = os.fspath(f)
      elif not isinstance(f, str):
          raise TypeError(
              "expected {str, int, path-like, file-like}, got %s"
              % type(f)
          )
  
      _, ext = os.path.splitext(f)
      if ext == ".gz":
          import gzip
  
          return gzip.open(f, "rb")
      elif ext == ".bz2":
          from bz2 import BZ2File
  
          return BZ2File(f, "rb")
      else:
          return open(f, "rb")
  
file_path: catboost/contrib/python/scikit-learn/py3/sklearn/datasets/_svmlight_format_io.py
imports: import os.path
  from contextlib import closing
  from numbers import Integral
  import numpy
  import scipy.sparse
  from ..None import __version__
  from ..utils import IS_PYPY, check_array
  from ..utils._param_validation import HasMethods, Interval, StrOptions, validate_params
label_desc: Use image node_id 2 for calling a global function with example usage: _gen_open(f) and returns: open, gzip, BZ2File, open