code: def _resolve_paths_and_filesystem(
      paths: Union[str, List[str]],
      filesystem: "pyarrow.fs.FileSystem" = None,
  ) -> Tuple[List[str], "pyarrow.fs.FileSystem"]:
      """
      Resolves and normalizes all provided paths, infers a filesystem from the
      paths and ensures that all paths use the same filesystem.
  
      Args:
          paths: A single file/directory path or a list of file/directory paths.
              A list of paths can contain both files and directories.
          filesystem: The filesystem implementation that should be used for
              reading these files. If None, a filesystem will be inferred. If not
              None, the provided filesystem will still be validated against all
              filesystems inferred from the provided paths to ensure
              compatibility.
      """
      import pyarrow as pa
      from pyarrow.fs import (
          FileSystem,
          FSSpecHandler,
          PyFileSystem,
          _resolve_filesystem_and_path,
      )
  
      if isinstance(paths, str):
          paths = [paths]
      if isinstance(paths, pathlib.Path):
          paths = [str(paths)]
      elif not isinstance(paths, list) or any(
          not isinstance(p, str) for p in paths
      ):
          raise ValueError(
              "Expected `paths` to be a `str`, `pathlib.Path`, or `list[str]`, but got "
              f"`{paths}`."
          )
      elif len(paths) == 0:
          raise ValueError("Must provide at least one path.")
  
      need_unwrap_path_protocol = True
      if filesystem and not isinstance(filesystem, FileSystem):
          err_msg = (
              f"The filesystem passed must either conform to "
              f"pyarrow.fs.FileSystem, or "
              f"fsspec.spec.AbstractFileSystem. The provided "
              f"filesystem was: {filesystem}"
          )
          try:
              import fsspec
              from fsspec.implementations.http import HTTPFileSystem
          except ModuleNotFoundError:
              # If filesystem is not a pyarrow filesystem and fsspec isn't
              # installed, then filesystem is neither a pyarrow filesystem nor
              # an fsspec filesystem, so we raise a TypeError.
              raise TypeError(err_msg) from None
          if not isinstance(filesystem, fsspec.spec.AbstractFileSystem):
              raise TypeError(err_msg) from None
          if isinstance(filesystem, HTTPFileSystem):
              # If filesystem is fsspec HTTPFileSystem, the protocol/scheme of paths
              # should not be unwrapped/removed, because HTTPFileSystem expects full file
              # paths including protocol/scheme. This is different behavior compared to
              # file systems implementation in pyarrow.fs.FileSystem.
              need_unwrap_path_protocol = False
  
          filesystem = PyFileSystem(FSSpecHandler(filesystem))
  
      resolved_paths = []
      for path in paths:
          path = _resolve_custom_scheme(path)
          try:
              (
                  resolved_filesystem,
                  resolved_path,
              ) = _resolve_filesystem_and_path(path, filesystem)
          except pa.lib.ArrowInvalid as e:
              if "Cannot parse URI" in str(e):
                  (
                      resolved_filesystem,
                      resolved_path,
                  ) = _resolve_filesystem_and_path(
                      _encode_url(path), filesystem
                  )
                  resolved_path = _decode_url(resolved_path)
              elif "Unrecognized filesystem type in URI" in str(e):
                  scheme = urllib.parse.urlparse(
                      path, allow_fragments=False
                  ).scheme
                  if scheme in ["http", "https"]:
                      # If scheme of path is HTTP and filesystem is not resolved,
                      # try to use fsspec HTTPFileSystem. This expects fsspec is
                      # installed.
                      try:
                          from fsspec.implementations.http import (
                              HTTPFileSystem,
                          )
                      except ModuleNotFoundError:
                          raise ImportError(
                              "Please install fsspec to read files from HTTP."
                          ) from None
  
                      resolved_filesystem = PyFileSystem(
                          FSSpecHandler(HTTPFileSystem())
                      )
                      resolved_path = path
                      need_unwrap_path_protocol = False
                  else:
                      raise
              else:
                  raise
          if filesystem is None:
              filesystem = resolved_filesystem
          elif need_unwrap_path_protocol:
              resolved_path = _unwrap_protocol(resolved_path)
          resolved_path = filesystem.normalize_path(resolved_path)
          resolved_paths.append(resolved_path)
  
      return resolved_paths, filesystem
  
file_path: ray/python/ray/data/datasource/path_util.py
imports: import pathlib
  import sys
  import urllib
  from typing import TYPE_CHECKING, List, Optional, Tuple, Union
  from ray.data._internal.util import _resolve_custom_scheme
label_desc: Use image node_id 2 for calling a global function with example usage: _resolve_paths_and_filesystem(paths, filesystem) and returns: resolved_paths,  filesystem