code: def patch_adapter(
      requests_monitor,
      retries_enabled_session,
      is_internet_access_allowed,
  ):
      """
      Patch the default Adapter to provide the following features:
          - Retry failed requests. Makes test runs more stable.
          - Track statistics with RequestsMonitor.
          - Skip tests requiring Internet access when Internet access is not allowed.
      """
  
      if default_adapter_is_async:
  
          class AdapterProxy(BaseAdapterProxy, BaseAsyncAdapter):
              async def __aenter__(self):
                  assert await self.adapter.__aenter__() is self.adapter
                  return self
  
              async def __aexit__(self, exc_type, exc_val, exc_tb):
                  return await self.adapter.__aexit__(
                      exc_type, exc_val, exc_tb
                  )
  
              async def _wrapped_get(self, url, do_request):
                  res = None
                  gen = self._retries(url)
                  while True:
                      try:
                          next(gen)
                      except StopIteration:
                          break
                      assert res is None
                      try:
                          res = await do_request()
                      except Exception as e:
                          error_wait_seconds = gen.throw(e)
                          await asyncio.sleep(error_wait_seconds)
                      else:
                          assert gen.send(res) is None
                  assert res is not None
                  return res
  
      else:
  
          class AdapterProxy(BaseAdapterProxy, BaseSyncAdapter):
              def _wrapped_get(self, url, do_request):
                  res = None
                  gen = self._retries(url)
                  while True:
                      try:
                          next(gen)
                      except StopIteration:
                          break
                      assert res is None
                      try:
                          res = do_request()
                      except Exception as e:
                          error_wait_seconds = gen.throw(e)
                          sleep(error_wait_seconds)
                      else:
                          assert gen.send(res) is None
                  assert res is not None
                  return res
  
      # In order to take advantage of Keep-Alives in tests, the actual Adapter
      # should be persisted between the test runs, so this fixture must be
      # in the "session" scope.
      adapter_factory = partial(
          AdapterProxy,
          adapter_factory=default_adapter,
          requests_monitor=requests_monitor,
          retries_enabled_session=retries_enabled_session,
          is_internet_access_allowed=is_internet_access_allowed,
      )
      with patch.object(
          geopy.geocoders.options,
          "default_adapter_factory",
          adapter_factory,
      ):
          yield
  
imports: import asyncio
  import atexit
  import contextlib
  import importlib
  import os
  import types
  from collections import defaultdict
  from functools import partial
  from statistics import mean, median
  from time import sleep
  from timeit import default_timer
  from unittest.mock import patch
  from urllib.parse import urlparse
  import pytest
  import geopy.geocoders
  from geopy.adapters import AdapterHTTPError, BaseAsyncAdapter, BaseSyncAdapter
  from geopy.geocoders.base import _DEFAULT_ADAPTER_CLASS
label_desc: Use image node_id 14 for calling a global function with example usage: patch_adapter(requests_monitor, retries_enabled_session, is_internet_access_allowed) and returns: self, unknown, res, res