<s> from robot . libraries import BuiltIn <EOL> from keywordgroup import KeywordGroup <EOL> BUILTIN = BuiltIn . BuiltIn ( ) <EOL> class RunOnFailure ( KeywordGroup ) : <EOL> def __init__ ( self ) : <EOL> self . _run_on_failure_keyword = None <EOL> self . _running_on_failure_routine = False <EOL> def register_keyword_to_run_on_failure ( self , keyword ) : <EOL> """<STR_LIT>""" <EOL> print keyword <EOL> old_keyword = self . _run_on_failure_keyword <EOL> old_keyword_text = old_keyword if old_keyword is not None else "<STR_LIT>" <EOL> new_keyword = keyword if keyword . strip ( ) . lower ( ) != "<STR_LIT>" else None <EOL> new_keyword_text = new_keyword if new_keyword is not None else "<STR_LIT>" <EOL> self . _run_on_failure_keyword = new_keyword <EOL> self . _info ( '<STR_LIT>' % new_keyword_text ) <EOL> return old_keyword_text <EOL> def _run_on_failure ( self ) : <EOL> if self . _run_on_failure_keyword is None : <EOL> return <EOL> if self . _running_on_failure_routine : <EOL> return <EOL> self . _running_on_failure_routine = True <EOL> try : <EOL> BUILTIN . run_keyword ( self . _run_on_failure_keyword ) <EOL> except Exception , err : <EOL> self . _run_on_failure_error ( err ) <EOL> finally : <EOL> self . _running_on_failure_routine = False <EOL> def _run_on_failure_error ( self , err ) : <EOL> err = "<STR_LIT>" % ( self . _run_on_failure_keyword , err ) <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> self . _warn ( err ) <EOL> return <EOL> raise Exception ( err ) </s>
