def resolve_package_module(module, pkg, level, default=None):
    """Returns a 2-tuple of package and module name, even for relative
    imports
    """
    if level == 0:
        p, _, m = module.rpartition('.')
    elif level == 1:
        p = pkg
        m = module or default
    else:
        p = m = None
    return p, m
