def _search(name, text, line, before=32, after=16):
    '''Find name in text lines within a range
       before and after a given line number.
    '''
    b = max(line - max(0, before), 1)  # 1-origin
    a = min(line + max(0, after), len(text))
    r = []  # search back- and forward
    for n, s in [(line, -1), (line+1, +1)]:
        while b <= n <= a:
            if text[n-1].find(name) < 0:
                n += s
            else:
                r.append(n)
                break  # while
    return r  # list of 0, 1 or 2 line numbers
Find name in text lines within a range
       before and after a given line number.
    
recipes/Python/534147_backtrace2line__stack_traces_source_file_name/recipe-534147.py