def _get_class_frame_source(class_name):
    for frame_info in inspect.stack():
        try:
            with open(frame_info[1]) as fp:
                src = "".join(fp.readlines()[frame_info[2] - 1 :])
        except IOError:
            continue
        if re.search(r"\bclass\b\s+\b{}\b".format(class_name), src):
            reader = six.StringIO(src).readline
            tokens = tokenize.generate_tokens(reader)
            source_tokens = []
            indent_level = 0
            base_indent_level = 0
            has_base_level = False
            for token, value, _, _, _ in tokens:
                source_tokens.append((token, value))
                if token == tokenize.INDENT:
                    indent_level += 1
                elif token == tokenize.DEDENT:
                    indent_level -= 1
                    if has_base_level and indent_level <= base_indent_level:
                        return (
                            tokenize.untokenize(source_tokens),
                            frame_info[0].f_globals,
                            frame_info[0].f_locals,
                        )
                elif not has_base_level:
                    has_base_level = True
                    base_indent_level = indent_level
    raise TypeError(
        'Unable to retrieve source for class "{}"'.format(class_name)
    )