code: def _expand_variables(self, config, hostname):
          
  
          if "hostname" in config:
              config["hostname"] = config["hostname"].replace("%h", hostname)
          else:
              config["hostname"] = hostname
  
          if "port" in config:
              port = config["port"]
          else:
              port = SSH_PORT
  
          user = os.getenv("USER")
          if "user" in config:
              remoteuser = config["user"]
          else:
              remoteuser = user
  
          host = socket.gethostname().split(".")[0]
          fqdn = LazyFqdn(config, host)
          homedir = os.path.expanduser("~")
          replacements = {
              "controlpath": [
                  ("%h", config["hostname"]),
                  ("%l", fqdn),
                  ("%L", host),
                  ("%n", hostname),
                  ("%p", port),
                  ("%r", remoteuser),
                  ("%u", user),
              ],
              "identityfile": [
                  ("~", homedir),
                  ("%d", homedir),
                  ("%h", config["hostname"]),
                  ("%l", fqdn),
                  ("%u", user),
                  ("%r", remoteuser),
              ],
              "proxycommand": [
                  ("~", homedir),
                  ("%h", config["hostname"]),
                  ("%p", port),
                  ("%r", remoteuser),
              ],
          }
  
          for k in config:
              if config[k] is None:
                  continue
              if k in replacements:
                  for find, replace in replacements[k]:
                      if isinstance(config[k], list):
                          for item in range(len(config[k])):
                              if find in config[k][item]:
                                  config[k][item] = config[k][item].replace(
                                      find, str(replace)
                                  )
                      else:
                          if find in config[k]:
                              config[k] = config[k].replace(find, str(replace))
          return config
docs: Return a dict of config options with expanded substitutions
          for a given hostname.
  
          Please refer to man ``ssh_config`` for the parameters that
          are replaced.
  
          :param dict config: the config for the hostname
          :param str hostname: the hostname that the config belongs to