#NEWLINE# def fix_missing_locations( node ) : #NEWLINE# #INDENT# '\n    When you compile a node tree with compile(), the compiler expects lineno and\n    col_offset attributes for every node that supports them.  This is rather\n    tedious to fill in for generated nodes, so this helper adds these attributes\n    recursively where not already set, by setting them to the values of the\n    parent node.  It works recursively starting at *node*.\n    ' #NEWLINE# def _fix( node , lineno , col_offset ) : #NEWLINE# #INDENT# if ( 'lineno' in node . _attributes ) : #NEWLINE# #INDENT# if ( not hasattr ( node , 'lineno' ) ) : #NEWLINE# #INDENT# node . lineno = lineno #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# lineno = node . lineno #NEWLINE# #UNINDENT# #UNINDENT# if ( 'col_offset' in node . _attributes ) : #NEWLINE# #INDENT# if ( not hasattr ( node , 'col_offset' ) ) : #NEWLINE# #INDENT# node . col_offset = col_offset #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# col_offset = node . col_offset #NEWLINE# #UNINDENT# #UNINDENT# for child in iter_child_nodes ( node ) : #NEWLINE# #INDENT# _fix ( child , lineno , col_offset ) #NEWLINE# #UNINDENT# #UNINDENT# _fix ( node , 1 , 0 ) #NEWLINE# return node