def conform_to_argspec(args, kwargs, argspec):
    """Attempts to take the arguments in arg and kwargs and return only those which can be used
       by the argspec given."""
    regargs, varargs, varkwargs, defaults = argspec
    N = len(regargs)
    newargs = list(args)
    newkwargs = kwargs.copy()
    if varargs is None:
        newargs = newargs[:N]
    else:
        pass
    for varname in regargs[len(newargs):]:
        try:
            newargs.append(newkwargs[varname])
            del newkwargs[varname]
        except KeyError:
            break
    if varkwargs is None:
        newkwargs = {}
    else:
        pass
    return newargs, newkwargs
