code: def open_sesame(
      filepath: types.PathLike,
      *,
      mode: str = "rt",
      encoding: Optional[str] = None,
      errors: Optional[str] = None,
      newline: Optional[str] = None,
      compression: Literal[
          "infer", "bz2", "gzip", "xz", "zip"
      ] = "infer",
      make_dirs: bool = False,
  ) -> IO:
      """
      Open file ``filepath``. Automatically handle file compression, relative
      paths and symlinks, and missing intermediate directory creation, as needed.
  
      ``open_sesame`` may be used as a drop-in replacement for :func:`io.open`.
  
      Args:
          filepath: Path on disk (absolute or relative) of the file to open.
          mode: The mode in which ``filepath`` is opened.
          encoding: Name of the encoding used to decode or encode ``filepath``.
              Only applicable in text mode.
          errors: String specifying how encoding/decoding errors are handled.
              Only applicable in text mode.
          newline: String specifying how universal newlines mode works.
              Only applicable in text mode.
          compression: Type of compression, if any, with which ``filepath``
              is read from or written to disk. If None, no compression is used;
              if 'infer', compression is inferred from the extension on ``filepath``.
          make_dirs: If True, automatically create (sub)directories
              if not already present in order to write ``filepath``.
  
      Returns:
          file object
  
      Raises:
          TypeError: if ``filepath`` is not a string
          ValueError: if ``encoding`` is specified but ``mode`` is binary
          OSError: if ``filepath`` doesn't exist but ``mode`` is read
      """
      # check args
      if encoding and "t" not in mode:
          raise ValueError("encoding only applicable for text mode")
  
      # normalize filepath and make dirs, as needed
      filepath = utils.to_path(filepath).resolve()
      if make_dirs is True:
          _make_dirs(filepath, mode)
      elif mode.startswith("r") and not filepath.is_file():
          raise OSError(f"file '{filepath}' does not exist")
  
      compression = _get_compression(filepath, compression)
      f = _get_file_handle(
          filepath,
          mode,
          compression=compression,
          encoding=encoding,
          errors=errors,
          newline=newline,
      )
      return f
  
imports: from __future__ import annotations
  import bz2
  import gzip
  import io
  import itertools
  import logging
  import lzma
  import os
  import re
  import shutil
  import tarfile
  import urllib
  import zipfile
  from typing import IO, Iterable, Literal, Optional
  from cytoolz import itertoolz
  from ..None import constants
  from ..None import errors
  from ..None import types, utils
  from .http import write_http_stream
label_desc: Use image node_id 1 for calling a global function with example usage: open_sesame(filepath) and returns: f