def parse_spec(spec, default_module):
    """Parse a spec of the form module.class:kw1=val,kw2=val.

    Returns a triple of module, classname, arguments list and keyword dict.
    """
    name, args = (spec.split(':', 1) + [''])[:2]

    if '.' not in name:
        if default_module:
            module, klass = default_module, name
        else:
            module, klass = name, None
    else:
        module, klass = name.rsplit('.', 1)

    al = [a for a in args.split(',') if a and '=' not in a]
    kw = dict(a.split('=', 1) for a in args.split(',') if '=' in a)

    return module, klass, al, kw