def set_server_setting(settings, server=_DEFAULT_SERVER):
    if not settings:
        _LOG.warning('No settings provided')
        return False

    # Some fields are formatted like '{data}'. Salt tries to convert these to dicts
    # automatically on input, so convert them back to the proper format.
    settings = _normalize_server_settings(**settings)

    current_settings = get_server_setting(settings=settings.keys(), server=server)

    if settings == current_settings:
        _LOG.debug('Settings already contain the provided values.')
        return True

    # Note that we must fetch all properties of IIsSmtpServerSetting below, since
    # filtering for specific properties and then attempting to set them will cause
    # an error like: wmi.x_wmi Unexpected COM Error -2147352567
    with salt.utils.winapi.Com():
        try:
            connection = wmi.WMI(namespace=_WMI_NAMESPACE)
            objs = connection.IIsSmtpServerSetting(Name=server)[0]
        except wmi.x_wmi as error:
            _LOG.error('Encountered WMI error: %s', error.com_error)
        except (AttributeError, IndexError) as error:
            _LOG.error('Error getting IIsSmtpServerSetting: %s', error)

        for setting in settings:
            if str(settings[setting]) != str(current_settings[setting]):
                try:
                    setattr(objs, setting, settings[setting])
                except wmi.x_wmi as error:
                    _LOG.error('Encountered WMI error: %s', error.com_error)
                except AttributeError as error:
                    _LOG.error('Error setting %s: %s', setting, error)

    # Get the settings post-change so that we can verify tht all properties
    # were modified successfully. Track the ones that weren't.
    new_settings = get_server_setting(settings=settings.keys(), server=server)
    failed_settings = dict()

    for setting in settings:
        if str(settings[setting]) != str(new_settings[setting]):
            failed_settings[setting] = settings[setting]
    if failed_settings:
        _LOG.error('Failed to change settings: %s', failed_settings)
        return False

    _LOG.debug('Settings configured successfully: %s', settings.keys())
    return True
Avoid potentially expensive list comprehension over self.queryset()
dataset/ETHPy150Open saltstack/salt/salt/modules/win_smtp_server.py/set_server_setting--crossover with--dataset/ETHPy150Open theatlantic/django-cropduster/cropduster/views/forms.py/ThumbFormSet._existing_object