code: def _wrap_io_open(file, mode, encoding, errors):
      """On Python 2, :func:`io.open` returns a text file wrapper that
      requires passing ``unicode`` to ``write``. Need to open the file in
      binary mode then wrap it in a subclass that can write ``str`` and
      ``unicode``.
  
      Also handles not passing ``encoding`` and ``errors`` in binary mode.
      """
      binary = "b" in mode
  
      if binary:
          kwargs = {}
      else:
          kwargs = {"encoding": encoding, "errors": errors}
  
      if not PY2 or binary:
          return io.open(file, mode, **kwargs)
  
      f = io.open(file, "{}b".format(mode.replace("t", "")))
      return _make_text_stream(f, **kwargs)
  
imports: import codecs
  import io
  import os
  import re
  import sys
  from weakref import WeakKeyDictionary
label_desc: Use image node_id 6 for calling a global function with example usage: _wrap_io_open(file, mode, encoding, errors) and returns: _make_text_stream, io