import linecache


def _code_block(filename, lineno, before=8, after=4):
    """Retrieve code blocks around a given line
    inside the source.

    :param filename: name of the source file
    :param lineno: line number
    :param before: number of lines before the line number
    :param after: number of line after the line number
    """
    min_n = max(lineno - before, 0)
    max_n = lineno + after

    line_fmt = "%" + str(len(str(max_n))) + "d|  %s"
    lines = []

    for n in range(min_n, max_n):
        line = linecache.getline(filename, n)
        if n > min_n and len(line) == 0:
            break
        print_line = line_fmt % (n, line)
        if n == lineno:
            print_line = "|> ".join(print_line.split("|  ", 1))
        lines.append(print_line)

    return lines