def import_symbol(dotted_name):
    """Import an arbitrary symbol (including modules) by its dotted name"""
    try:
        spec = dotted_name.rsplit('.', 1)
        try:
            mod_name, attr = spec
        except ValueError:
            sym = __import__(dotted_name, None, None, [])
        else:
            mod = __import__(mod_name, None, None, [attr])
            sym = getattr(mod, attr)
    except (ImportError, AttributeError, ValueError):
        raise ImportError('Can not import %r' % dotted_name)
    return sym
