def restore_attrs(wrapper):
    """
    Restore all attributes for a wrapped module to their original values
    (removing any which weren't originally set).

    """
    for key, value in wrapper._attrs_to_restore.iteritems():
        setattr(wrapper._wrapped_module, key, value)
    for setting in wrapper._delete_settings:
        try:
            delattr(wrapper._wrapped_module, setting)
        except AttributeError:
            pass
