code: def cached_path(
      url_or_filename,
      download_config=None,
      **download_kwargs,
  ) -> str:
      """
      Given something that might be a URL (or might be a local path),
      determine which. If it's a URL, download the file and cache it, and
      return the path to the cached file. If it's already a local path,
      make sure the file exists and then return the path.
  
      Return:
          Local path (string)
  
      Raises:
          FileNotFoundError: in case of non-recoverable file
              (non-existent or no cache on disk)
          ConnectionError: in case of unreachable url
              and no cache on disk
          ValueError: if it couldn't parse the url or filename correctly
          requests.exceptions.ConnectionError: in case of internet connection issue
      """
      if download_config is None:
          download_config = DownloadConfig(**download_kwargs)
  
      cache_dir = (
          download_config.cache_dir or config.DOWNLOADED_EVALUATE_PATH
      )
      if isinstance(cache_dir, Path):
          cache_dir = str(cache_dir)
      if isinstance(url_or_filename, Path):
          url_or_filename = str(url_or_filename)
  
      if is_remote_url(url_or_filename):
          # URL, so get it from the cache (downloading if necessary)
          output_path = get_from_cache(
              url_or_filename,
              cache_dir=cache_dir,
              force_download=download_config.force_download,
              proxies=download_config.proxies,
              resume_download=download_config.resume_download,
              user_agent=download_config.user_agent,
              local_files_only=download_config.local_files_only,
              use_etag=download_config.use_etag,
              max_retries=download_config.max_retries,
              use_auth_token=download_config.use_auth_token,
              ignore_url_params=download_config.ignore_url_params,
              download_desc=download_config.download_desc,
          )
      elif os.path.exists(url_or_filename):
          # File, and it exists.
          output_path = url_or_filename
      elif is_local_path(url_or_filename):
          # File, but it doesn't exist.
          raise FileNotFoundError(
              f"Local file {url_or_filename} doesn't exist"
          )
      else:
          # Something unknown
          raise ValueError(
              f"unable to parse {url_or_filename} as a URL or as a local path"
          )
  
      if output_path is None:
          return output_path
  
      if download_config.extract_compressed_file:
          output_path = ExtractManager(
              cache_dir=download_config.cache_dir
          ).extract(
              output_path, force_extract=download_config.force_extract
          )
  
      return output_path
  
imports: import copy
  import io
  import json
  import os
  import posixpath
  import re
  import shutil
  import sys
  import tempfile
  import time
  import urllib
  from contextlib import closing, contextmanager
  from functools import partial
  from hashlib import sha256
  from pathlib import Path
  from typing import List, Optional, Type, TypeVar, Union
  from urllib.parse import urljoin, urlparse
  import requests
  from datasets import DownloadConfig
  from datasets.utils.extract import ExtractManager
  from datasets.utils.filelock import FileLock
  from ..None import __version__, config
  from .None import logging
label_desc: Use image node_id 12 for calling a global function with example usage: cached_path(url_or_filename, download_config) and returns: output_path, output_path