def sasimport(modname):
    """Import specified module from the SasView sas package.

    modname  -- absolute module name contained in the sas package.

    When specified import does not work directly, try older API-s and raise
    DeprecationWarning.  Raise ImportError if nothing works.
    """
    if not modname.startswith('sas.'):
        emsg = 'Module name must start with "sas."'
        raise ValueError(emsg)
    mobj = None
    try:
        exec('import %s as mobj' % modname)
    except ImportError:
        pass
    else:
        return mobj
    modsans = 'sans' + modname[3:]
    import warnings
    wfmt = (
        'Using obsolete package %r instead of %r.  Please install SasView 3.1 or the srfit-sasview package from Anaconda.'
        )
    wmsg = wfmt % (modsans, modname)
    try:
        exec('import %s as mobj' % modsans)
        warnings.warn(wmsg, DeprecationWarning)
    except ImportError:
        pass
    else:
        return mobj
    if modname.startswith('sas.dataloader'):
        modloader = 'DataLoader' + modname[14:]
        wmsg = wfmt % (modloader, modname)
        try:
            exec('import %s as mobj' % modloader)
            warnings.warn(wmsg, DeprecationWarning)
        except ImportError:
            pass
        else:
            return mobj
    exec('import %s as mobj' % modname)
    raise AssertionError('The import above was supposed to fail.')
