def get_template_exception_info(exc_type, exc_value, tb):
    origin, (start, end) = exc_value.source
    template_source = origin.reload()
    context_lines = 10
    line = 0
    upto = 0
    source_lines = []
    before = during = after = ""
    for num, next in enumerate(linebreak_iter(template_source)):
        if start >= upto and end <= next:
            line = num
            before = escape(template_source[upto:start])
            during = escape(template_source[start:end])
            after = escape(template_source[end:next])
        source_lines.append( (num, escape(template_source[upto:next])) )
        upto = next
    total = len(source_lines)

    top = max(1, line - context_lines)
    bottom = min(total, line + 1 + context_lines)

    template_info = {
        'message': exc_value.args[0],
        'source_lines': source_lines[top:bottom],
        'before': before,
        'during': during,
        'after': after,
        'top': top,
        'bottom': bottom,
        'total': total,
        'line': line,
        'name': origin.name,
    }
    exc_info = hasattr(exc_value, 'exc_info') and exc_value.exc_info or (exc_type, exc_value, tb)
    return exc_info + (template_info,)
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-0.96/django/views/debug.py/get_template_exception_info/original