code: def resolve_redirects(max_hops=3):
      def outer_wrapper(fn):
          def inner_wrapper(request, *args, **kwargs):
              initial_url = (
                  request.full_url
                  if isinstance(request, Request)
                  else request
              )
              url = _get_redirect_url(initial_url, max_hops=max_hops)
  
              if url == initial_url:
                  return fn(request, *args, **kwargs)
  
              warnings.warn(
                  f"The URL {initial_url} ultimately redirects to {url}."
              )
  
              if not isinstance(request, Request):
                  return fn(url, *args, **kwargs)
  
              request_attrs = {
                  attr: getattr(request, attr)
                  for attr in (
                      "data",
                      "headers",
                      "origin_req_host",
                      "unverifiable",
                  )
              }
              # the 'method' attribute does only exist if the request was created with it
              if hasattr(request, "method"):
                  request_attrs["method"] = request.method
  
              return fn(Request(url, **request_attrs), *args, **kwargs)
  
          return inner_wrapper
  
      return outer_wrapper
  
imports: import contextlib
  import itertools
  import tempfile
  import time
  import traceback
  import unittest.mock
  import warnings
  from datetime import datetime
  from distutils import dir_util
  from os import path
  from urllib.error import HTTPError, URLError
  from urllib.parse import urlparse
  from urllib.request import Request, urlopen
  import pytest
  from torchvision import datasets
  from torchvision.datasets.utils import _get_redirect_url, USER_AGENT
label_desc: Use image node_id 2 for calling a global function with example usage: resolve_redirects(max_hops) and returns: outer_wrapper, inner_wrapper, fn, fn, fn