def _get_lines_from_file(filename, lineno, context_lines):
 try:
  source = open(filename).readlines()
  lower_bound = max(0, (lineno - context_lines))
  upper_bound = (lineno + context_lines)
  pre_context = [line.strip('\n') for line in source[lower_bound:lineno]]
  context_line = source[lineno].strip('\n')
  post_context = [line.strip('\n') for line in source[(lineno + 1):upper_bound]]
  return (lower_bound, pre_context, context_line, post_context)
 except (OSError, IOError):
  return (None, [], None, [])

def _get_lines_from_file ( filename , lineno , context_lines ) : try : source = open ( filename ) . readlines ( ) lower_bound = max ( 0 , ( lineno - context_lines ) ) upper_bound = ( lineno + context_lines ) pre_context = [ line . strip ( '\n' ) for line in source [ lower_bound : lineno ] ] context_line = source [ lineno ] . strip ( '\n' ) post_context = [ line . strip ( '\n' ) for line in source [ ( lineno + 1 ) : upper_bound ] ] return ( lower_bound , pre_context , context_line , post_context ) except ( OSError , IOError ) : return ( None , [ ] , None , [ ] )
returns context_lines before and after lineno from file .