code: def _get_path_or_handle(
      path: FilePath | ReadBuffer[bytes] | WriteBuffer[bytes],
      fs: Any,
      storage_options: StorageOptions = None,
      mode: str = "rb",
      is_dir: bool = False,
  ) -> tuple[
      FilePath | ReadBuffer[bytes] | WriteBuffer[bytes],
      IOHandles[bytes] | None,
      Any,
  ]:
      """File handling for PyArrow."""
      path_or_handle = stringify_path(path)
      if is_fsspec_url(path_or_handle) and fs is None:
          fsspec = import_optional_dependency("fsspec")
  
          fs, path_or_handle = fsspec.core.url_to_fs(
              path_or_handle, **(storage_options or {})
          )
      elif storage_options and (
          not is_url(path_or_handle) or mode != "rb"
      ):
          # can't write to a remote url
          # without making use of fsspec at the moment
          raise ValueError(
              "storage_options passed with buffer, or non-supported URL"
          )
  
      handles = None
      if (
          not fs
          and not is_dir
          and isinstance(path_or_handle, str)
          and not os.path.isdir(path_or_handle)
      ):
          # use get_handle only when we are very certain that it is not a directory
          # fsspec resources can also point to directories
          # this branch is used for example when reading from non-fsspec URLs
          handles = get_handle(
              path_or_handle,
              mode,
              is_text=False,
              storage_options=storage_options,
          )
          fs = None
          path_or_handle = handles.handle
      return path_or_handle, handles, fs
  
imports: from __future__ import annotations
  import io
  import os
  from typing import Any, Literal
  import warnings
  from warnings import catch_warnings
  from pandas._libs import lib
  from pandas._typing import DtypeBackend, FilePath, ReadBuffer, StorageOptions, WriteBuffer
  from pandas.compat._optional import import_optional_dependency
  from pandas.errors import AbstractMethodError
  from pandas.util._decorators import doc
  from pandas.util._exceptions import find_stack_level
  from pandas.util._validators import check_dtype_backend
  import pandas
  from pandas import DataFrame, get_option
  from pandas.core.shared_docs import _shared_docs
  from pandas.util.version import Version
  from pandas.io.common import IOHandles, get_handle, is_fsspec_url, is_url, stringify_path
label_desc: Use image node_id 2 for calling a global function with example usage: _get_path_or_handle(path, fs, storage_options, mode, is_dir) and returns: path_or_handle,  handles,  fs