code: def offline(
      mode=OfflineSimulationMode.CONNECTION_FAILS, timeout=1e-16
  ):
      """
      Simulate offline mode.
  
      There are three offline simulation modes:
  
      CONNECTION_FAILS (default mode): a ConnectionError is raised for each network call.
          Connection errors are created by mocking socket.socket
      CONNECTION_TIMES_OUT: the connection hangs until it times out.
          The default timeout value is low (1e-16) to speed up the tests.
          Timeout errors are created by mocking requests.request
      HF_HUB_OFFLINE_SET_TO_1: the HF_HUB_OFFLINE_SET_TO_1 environment variable is set to 1.
          This makes the http/ftp calls of the library instantly fail and raise an OfflineModeEnabled error.
      """
      import socket
  
      from requests import request as online_request
  
      def timeout_request(method, url, **kwargs):
          # Change the url to an invalid url so that the connection hangs
          invalid_url = "https://10.255.255.1"
          if kwargs.get("timeout") is None:
              raise RequestWouldHangIndefinitelyError(
                  f"Tried a call to {url} in offline mode with no timeout set. Please set a timeout."
              )
          kwargs["timeout"] = timeout
          try:
              return online_request(method, invalid_url, **kwargs)
          except Exception as e:
              # The following changes in the error are just here to make the offline timeout error prettier
              e.request.url = url
              max_retry_error = e.args[0]
              max_retry_error.args = (
                  max_retry_error.args[0].replace(
                      "10.255.255.1", f"OfflineMock[{url}]"
                  ),
              )
              e.args = (max_retry_error,)
              raise
  
      def offline_socket(*args, **kwargs):
          raise socket.error("Offline mode is enabled.")
  
      if mode is OfflineSimulationMode.CONNECTION_FAILS:
          # inspired from https://stackoverflow.com/a/18601897
          with patch("socket.socket", offline_socket):
              with patch(
                  "huggingface_hub.utils._http.get_session"
              ) as get_session_mock:
                  with patch(
                      "huggingface_hub.file_download.get_session"
                  ) as get_session_mock:
                      get_session_mock.return_value = (
                          requests.Session()
                      )  # not an existing one
                      yield
      elif mode is OfflineSimulationMode.CONNECTION_TIMES_OUT:
          # inspired from https://stackoverflow.com/a/904609
          with patch("requests.request", timeout_request):
              with patch(
                  "huggingface_hub.utils._http.get_session"
              ) as get_session_mock:
                  with patch(
                      "huggingface_hub.file_download.get_session"
                  ) as get_session_mock:
                      get_session_mock().request = timeout_request
                      yield
      elif mode is OfflineSimulationMode.HF_HUB_OFFLINE_SET_TO_1:
          with patch("huggingface_hub.constants.HF_HUB_OFFLINE", True):
              reset_sessions()
              yield
          reset_sessions()
      else:
          raise ValueError(
              "Please use a value from the OfflineSimulationMode enum."
          )
  
imports: import inspect
  import os
  import shutil
  import stat
  import time
  import unittest
  import uuid
  from contextlib import contextmanager
  from enum import Enum
  from functools import wraps
  from pathlib import Path
  from typing import Callable, Optional, Type, TypeVar, Union
  from unittest.mock import Mock, patch
  import pytest
  import requests
  from huggingface_hub.utils import is_gradio_available, logging, reset_sessions
  from tests.testing_constants import ENDPOINT_PRODUCTION, ENDPOINT_PRODUCTION_URL_SCHEME
label_desc: Use image node_id 6 for calling a global function with example usage: offline(mode, timeout) and returns: online_request