def fromargskw(argskw, argspecs, slf_or_clsm = False):
    """Turns a linearized list of args into (args, keywords) form
    according to given argspecs (like inspect module provides).
    """
    res_args = argskw
    try:
        kwds = argspecs.keywords
    except AttributeError:
        kwds = argspecs.varkw
    if not kwds is None:
        res_kw = argskw[-1]
        res_args = argskw[:-1]
    else:
        res_kw = None
    if not argspecs.varargs is None:
        vargs_pos = (len(argspecs.args)-1) \
                if slf_or_clsm else len(argspecs.args)
        if vargs_pos > 0:
            res_lst = list(argskw[:vargs_pos])
            res_lst.extend(argskw[vargs_pos])
            res_args = tuple(res_lst)
        else:
            res_args = argskw[0]
    try:
        if len(argspecs.kwonlyargs) > 0:
            res_kw = {} if res_kw is None else dict(res_kw)
            ipos = -len(argspecs.kwonlyargs) - (0 if kwds is None else 1)
            for name in argspecs.kwonlyargs:
                res_kw[name] = argskw[ipos]
                ipos += 1
    except AttributeError:
        pass
    if res_kw is None:
        res_kw = {}
    return res_args, res_kw
Turns a linearized list of args into (args, keywords) form
    according to given argspecs (like inspect module provides).