code: def _gen_open(f):
      if isinstance(f, int):  # file descriptor
          return io.open(f, "rb", closefd=False)
      elif not isinstance(f, six.string_types):
          raise TypeError(
              "expected {str, int, 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/py2/sklearn/datasets/svmlight_format.py
imports: from contextlib import closing
  import io
  import os.path
  import numpy
  import scipy.sparse
  from ._svmlight_format import _load_svmlight_file
  from ..None import __version__
  from ..externals import six
  from ..externals.six import u, b
  from ..externals.six.moves import range, zip
  from ..utils import check_array
  from ..utils.fixes import frombuffer_empty
label_desc: Use image node_id 2 for calling a global function with example usage: _gen_open(f) and returns: io, gzip, BZ2File, open