def importString(import_name):
    """Imports an object based on a string.

    The string can be either a module name and an object name, separated
    by a colon, or a (potentially dotted) module name.
    """
    if ':' in import_name:
        modname, obj = import_name.split(':', 1)
    elif '.' in import_name:
        modname, obj = import_name.rsplit('.', 1)
    else:
        modname, obj = import_name, None
    fromlist = [obj] if obj else []
    try:
        mod = __import__(modname, {}, {}, fromlist)
    except ImportError as err:
        raise ImportError(
            'Could not import %r: %s' % (import_name, err)) from err
    if not obj:
        return mod
    else:
        return getattr(mod, obj)