code: def _determine_mode(addr, mode):
      
      if isinstance(addr, tuple):
          host = addr[0]
      elif type(addr) == type(b"binary_string"):
          host = addr
      else:
          raise TypeError("'addr' needs to be a tuple or an bytestring!")
      if mode == MODE_AUTO:
          if host_is_local(host):
              return MODE_PRIMARY
  
          return MODE_SECONDARY
      elif mode in (MODE_SECONDARY, MODE_PRIMARY):
          return mode
      else:
          raise ValueError("Invalid mode {!r}!".format(mode))
docs: Returns the mode which should be used.
      If mode is MODE_AUTO, this is determined by checking if 'addr' points to the
      local host. If it does, return MODE_PRIMARY, else return MODE_SECONDARY.
      If mode is either MODE_PRIMARY or MODE_SECONDARY,
      return the 'mode' argument. Otherwise, a ValueError is raised.