def override_arg(argname,value,args,kwargs,argspec):
    """overrides the given argname=value in args or kwargs as appropriate, returning (args, kwargs)"""
    if argname in kwargs:
        kwargs[argname] = value
        return (args, kwargs)
    regargs, varargs, varkwargs, defaults = argspec
    if argname in regargs:
        if isinstance(args, tuple):
            args = list(args)
        args[regargs.index(argname)] = value
    else:
        kwargs[argname] = value
    return (args, kwargs)