import ast


def class_node(code):
    """Return AST node for first class in code string.

    :param str code: Code, e.g. 'class Foo(object):pass
    :return: AST node for class in code.
    :rtype: ast object
    """
    module = ast.parse(code)
    for node in ast.walk(module):
        if isinstance(node, ast.ClassDef):
            return node
    raise ValueError("Code has no class: " + code)