# Path: utils/output.py
# def disablePrint(log_fpath=None):
#     sys.stdout.flush()
#     if log_fpath is None:
#         log_fpath = os.devnull
#     sys.stdout = open(log_fpath, 'w')
# 
# def enablePrint():
#     sys.stdout.flush()
#     log_f = sys.stdout
#     sys.stdout = sys.__stdout__
#     log_f.close()
# 
# Path: utils/load_externals.py



import tensorflow as tf
import numpy as np
import sys, os
import warnings
import click
from keras.models import Model
from utils.output import disablePrint, enablePrint
from utils import load_externals
from deepfool import deepfool
from universal_pert import universal_perturbation

            adv_x_list.append(pert_image)

            aux_info['r_tot'].append(r_tot)
            aux_info['loop_i'].append(loop_i)
            aux_info['k_i'].append(k_i)

    return np.vstack(adv_x_list), aux_info


def generate_universal_perturbation_examples(sess, model, x, y, X, Y, attack_params, verbose, attack_log_fpath):
    """
    Untargeted attack. Y is not needed.
    """

    # TODO: insert a uint8 filter to f.
    f, grad_fs = prepare_attack(sess, model, x, y, X, Y)

    params = {'delta': 0.2,
              'max_iter_uni': np.inf,
              'xi': 10,
              'p': np.inf,
              'num_classes': 10,
              'overshoot': 0.02,
              'max_iter_df': 10,
              }

    params = override_params(params, attack_params)

    if not verbose:

# Path: utils/output.py
# def disablePrint(log_fpath=None):
#     sys.stdout.flush()
#     if log_fpath is None:
#         log_fpath = os.devnull
#     sys.stdout = open(log_fpath, 'w')
# 
# def enablePrint():
#     sys.stdout.flush()
#     log_f = sys.stdout
#     sys.stdout = sys.__stdout__
#     log_f.close()
# 
# Path: utils/load_externals.py



# Path: attacks/deepfool_wrapper.py
import tensorflow as tf
import numpy as np
import sys, os
import warnings
import click
from keras.models import Model
from utils.output import disablePrint, enablePrint
from utils import load_externals
from deepfool import deepfool
from universal_pert import universal_perturbation


            adv_x_list.append(pert_image)

            aux_info['r_tot'].append(r_tot)
            aux_info['loop_i'].append(loop_i)
            aux_info['k_i'].append(k_i)

    return np.vstack(adv_x_list), aux_info


def generate_universal_perturbation_examples(sess, model, x, y, X, Y, attack_params, verbose, attack_log_fpath):
    """
    Untargeted attack. Y is not needed.
    """

    # TODO: insert a uint8 filter to f.
    f, grad_fs = prepare_attack(sess, model, x, y, X, Y)

    params = {'delta': 0.2,
              'max_iter_uni': np.inf,
              'xi': 10,
              'p': np.inf,
              'num_classes': 10,
              'overshoot': 0.02,
              'max_iter_df': 10,
              }

    params = override_params(params, attack_params)

    if not verbose:

        disablePrint(attack_log_fpath)