<s> import __builtin__ <EOL> import itertools <EOL> def element_ancestry ( element ) : <EOL> """<STR_LIT>""" <EOL> return itertools . chain ( ( element , ) , element . parents ) <EOL> def search_ancestry ( element , predicate ) : <EOL> """<STR_LIT>""" <EOL> for obj in element_ancestry ( element ) : <EOL> try : <EOL> transform = predicate ( obj ) <EOL> if transform : <EOL> return transform <EOL> except AttributeError : <EOL> pass <EOL> def find_i18n_function ( element , finder ) : <EOL> """<STR_LIT>""" <EOL> transformer = search_ancestry ( element , finder ) <EOL> if transformer : <EOL> return transformer <EOL> try : <EOL> return finder ( __builtin__ ) <EOL> except AttributeError : <EOL> return None </s>
