<s> from robot . errors import DataError <EOL> class XmlElementHandler ( object ) : <EOL> def __init__ ( self , execution_result , root_handler = None ) : <EOL> self . _stack = [ ( execution_result , root_handler or RootHandler ( ) ) ] <EOL> def start ( self , elem ) : <EOL> result , handler = self . _stack [ - <NUM_LIT:1> ] <EOL> self . _stack . append ( handler . handle_child ( elem , result ) ) <EOL> def end ( self , elem ) : <EOL> result , handler = self . _stack . pop ( ) <EOL> handler . end ( elem , result ) <EOL> class _Handler ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _child_map = dict ( ( c . tag , c ) for c in self . _children ( ) ) <EOL> def _children ( self ) : <EOL> return [ ] <EOL> def handle_child ( self , elem , result ) : <EOL> try : <EOL> handler = self . _child_map [ elem . tag ] <EOL> except KeyError : <EOL> raise DataError ( "<STR_LIT>" % elem . tag ) <EOL> return handler . start ( elem , result ) , handler <EOL> def start ( self , elem , result ) : <EOL> return result <EOL> def end ( self , elem , result ) : <EOL> pass <EOL> def _timestamp ( self , elem , attr_name ) : <EOL> timestamp = elem . get ( attr_name ) <EOL> return timestamp if timestamp != '<STR_LIT>' else None <EOL> class RootHandler ( _Handler ) : <EOL> def _children ( self ) : <EOL> return [ RobotHandler ( ) ] <EOL> class RobotHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def start ( self , elem , result ) : <EOL> result . generator = elem . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( ) [ <NUM_LIT:0> ] . upper ( ) <EOL> return result <EOL> def _children ( self ) : <EOL> return [ RootSuiteHandler ( ) , StatisticsHandler ( ) , ErrorsHandler ( ) ] <EOL> class SuiteHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def start ( self , elem , result ) : <EOL> return result . suites . create ( name = elem . get ( '<STR_LIT:name>' ) , <EOL> source = elem . get ( '<STR_LIT:source>' , '<STR_LIT>' ) ) <EOL> def _children ( self ) : <EOL> return [ DocHandler ( ) , MetadataHandler ( ) , SuiteStatusHandler ( ) , <EOL> KeywordHandler ( ) , TestCaseHandler ( ) , self ] <EOL> class RootSuiteHandler ( SuiteHandler ) : <EOL> def start ( self , elem , result ) : <EOL> result . suite . name = elem . get ( '<STR_LIT:name>' ) <EOL> result . suite . source = elem . get ( '<STR_LIT:source>' , '<STR_LIT>' ) <EOL> return result . suite <EOL> def _children ( self ) : <EOL> return SuiteHandler . _children ( self ) [ : - <NUM_LIT:1> ] + [ SuiteHandler ( ) ] <EOL> class TestCaseHandler ( _Handler ) : <EOL> tag = '<STR_LIT:test>' <EOL> def start ( self , elem , result ) : <EOL> return result . tests . create ( name = elem . get ( '<STR_LIT:name>' ) , <EOL> timeout = elem . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def _children ( self ) : <EOL> return [ DocHandler ( ) , TagsHandler ( ) , TestStatusHandler ( ) , KeywordHandler ( ) ] <EOL> class KeywordHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def start ( self , elem , result ) : <EOL> return result . keywords . create ( name = elem . get ( '<STR_LIT:name>' ) , <EOL> timeout = elem . get ( '<STR_LIT>' ) , <EOL> type = elem . get ( '<STR_LIT:type>' ) ) <EOL> def _children ( self ) : <EOL> return [ DocHandler ( ) , ArgumentsHandler ( ) , KeywordStatusHandler ( ) , <EOL> MessageHandler ( ) , self ] <EOL> class MessageHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def end ( self , elem , result ) : <EOL> result . messages . create ( elem . text or '<STR_LIT>' , <EOL> elem . get ( '<STR_LIT>' ) , <EOL> elem . get ( '<STR_LIT:html>' , '<STR_LIT>' ) == '<STR_LIT:yes>' , <EOL> self . _timestamp ( elem , '<STR_LIT>' ) ) <EOL> class _StatusHandler ( _Handler ) : <EOL> tag = '<STR_LIT:status>' <EOL> def _set_status ( self , elem , result ) : <EOL> result . status = elem . get ( '<STR_LIT:status>' , '<STR_LIT>' ) <EOL> def _set_message ( self , elem , result ) : <EOL> result . message = elem . text or '<STR_LIT>' <EOL> def _set_times ( self , elem , result ) : <EOL> result . starttime = self . _timestamp ( elem , '<STR_LIT>' ) <EOL> result . endtime = self . _timestamp ( elem , '<STR_LIT>' ) <EOL> class KeywordStatusHandler ( _StatusHandler ) : <EOL> def end ( self , elem , result ) : <EOL> self . _set_status ( elem , result ) <EOL> self . _set_times ( elem , result ) <EOL> class SuiteStatusHandler ( _StatusHandler ) : <EOL> def end ( self , elem , result ) : <EOL> self . _set_message ( elem , result ) <EOL> self . _set_times ( elem , result ) <EOL> class TestStatusHandler ( _StatusHandler ) : <EOL> def end ( self , elem , result ) : <EOL> self . _set_status ( elem , result ) <EOL> self . _set_message ( elem , result ) <EOL> self . _set_times ( elem , result ) <EOL> class DocHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def end ( self , elem , result ) : <EOL> result . doc = elem . text or '<STR_LIT>' <EOL> class MetadataHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def _children ( self ) : <EOL> return [ MetadataItemHandler ( ) ] <EOL> class MetadataItemHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def end ( self , elem , result ) : <EOL> result . metadata [ elem . get ( '<STR_LIT:name>' ) ] = elem . text or '<STR_LIT>' <EOL> class TagsHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def _children ( self ) : <EOL> return [ TagHandler ( ) ] <EOL> class TagHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def end ( self , elem , result ) : <EOL> result . tags . add ( elem . text or '<STR_LIT>' ) <EOL> class ArgumentsHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def _children ( self ) : <EOL> return [ ArgumentHandler ( ) ] <EOL> class ArgumentHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def end ( self , elem , result ) : <EOL> result . args . append ( elem . text or '<STR_LIT>' ) <EOL> class ErrorsHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def start ( self , elem , result ) : <EOL> return result . errors <EOL> def _children ( self ) : <EOL> return [ MessageHandler ( ) ] <EOL> class StatisticsHandler ( _Handler ) : <EOL> tag = '<STR_LIT>' <EOL> def handle_child ( self , elem , result ) : <EOL> return result , self </s>
