'Magic to hook various function calls in sslstrip'

def hook(self):

    frame = sys._getframe(1)
    fname = frame.f_code.co_name
    (keys, _, _, values) = inspect.getargvalues(frame)
    args = {}
    for key in keys:
        args[key] = values[key]
    if ((fname == 'handleResponse') or (fname == 'handleHeader') or (fname == 'handleEndHeaders')):
        args['request'] = args['self']
        args['response'] = args['self'].client
    else:
        args['request'] = args['self']
    del args['self']
    log.debug('hooking    {}()'.format(fname))
    try:
        if self.plugin_mthds:
            for f in self.plugin_mthds[fname]:
                a = f(**args)
                if (a != None):
                    args = a
    except Exception as e:
        log.error('Exception    occurred    in    hooked    function')
        traceback.print_exc()
    return args
