<s> from robot import utils <EOL> from . logger import LOGGER <EOL> from . loggerhelper import IsLogged <EOL> def DebugFile ( path ) : <EOL> if path == '<STR_LIT>' : <EOL> LOGGER . info ( '<STR_LIT>' ) <EOL> return None <EOL> try : <EOL> outfile = open ( path , '<STR_LIT:w>' ) <EOL> except EnvironmentError , err : <EOL> LOGGER . error ( "<STR_LIT>" % ( path , err . strerror ) ) <EOL> return None <EOL> else : <EOL> LOGGER . info ( '<STR_LIT>' % path ) <EOL> return _DebugFileWriter ( outfile ) <EOL> class _DebugFileWriter : <EOL> _separators = { '<STR_LIT>' : '<STR_LIT:=>' , '<STR_LIT>' : '<STR_LIT:->' , '<STR_LIT>' : '<STR_LIT>' } <EOL> _setup_or_teardown = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , outfile ) : <EOL> self . _indent = <NUM_LIT:0> <EOL> self . _kw_level = <NUM_LIT:0> <EOL> self . _separator_written_last = False <EOL> self . _outfile = outfile <EOL> self . _is_logged = IsLogged ( '<STR_LIT>' ) <EOL> def start_suite ( self , suite ) : <EOL> self . _separator ( '<STR_LIT>' ) <EOL> self . _start ( '<STR_LIT>' , suite . longname ) <EOL> self . _separator ( '<STR_LIT>' ) <EOL> def end_suite ( self , suite ) : <EOL> self . _separator ( '<STR_LIT>' ) <EOL> self . _end ( '<STR_LIT>' , suite . longname , suite . elapsedtime ) <EOL> self . _separator ( '<STR_LIT>' ) <EOL> if self . _indent == <NUM_LIT:0> : <EOL> LOGGER . output_file ( '<STR_LIT>' , self . _outfile . name ) <EOL> self . close ( ) <EOL> def start_test ( self , test ) : <EOL> self . _separator ( '<STR_LIT>' ) <EOL> self . _start ( '<STR_LIT>' , test . name ) <EOL> self . _separator ( '<STR_LIT>' ) <EOL> def end_test ( self , test ) : <EOL> self . _separator ( '<STR_LIT>' ) <EOL> self . _end ( '<STR_LIT>' , test . name , test . elapsedtime ) <EOL> self . _separator ( '<STR_LIT>' ) <EOL> def start_keyword ( self , kw ) : <EOL> if self . _kw_level == <NUM_LIT:0> : <EOL> self . _separator ( '<STR_LIT>' ) <EOL> self . _start ( self . _get_kw_type ( kw ) , kw . name , kw . args ) <EOL> self . _kw_level += <NUM_LIT:1> <EOL> def end_keyword ( self , kw ) : <EOL> self . _end ( self . _get_kw_type ( kw ) , kw . name , kw . elapsedtime ) <EOL> self . _kw_level -= <NUM_LIT:1> <EOL> def log_message ( self , msg ) : <EOL> if self . _is_logged ( msg . level ) : <EOL> self . _write ( msg . message ) <EOL> def close ( self ) : <EOL> if not self . _outfile . closed : <EOL> self . _outfile . close ( ) <EOL> def _get_kw_type ( self , kw ) : <EOL> if kw . type in self . _setup_or_teardown : <EOL> return kw . type . upper ( ) <EOL> return '<STR_LIT>' <EOL> def _start ( self , type_ , name , args = '<STR_LIT>' ) : <EOL> args = '<STR_LIT:U+0020>' + utils . seq2str2 ( args ) <EOL> self . _write ( '<STR_LIT>' % ( '<STR_LIT:->' * self . _indent , type_ , name , args ) ) <EOL> self . _indent += <NUM_LIT:1> <EOL> def _end ( self , type_ , name , elapsed ) : <EOL> self . _indent -= <NUM_LIT:1> <EOL> self . _write ( '<STR_LIT>' % ( '<STR_LIT:->' * self . _indent , type_ , name , elapsed ) ) <EOL> def _separator ( self , type_ ) : <EOL> self . _write ( self . _separators [ type_ ] * <NUM_LIT> , separator = True ) <EOL> def _write ( self , text , separator = False ) : <EOL> if not ( separator and self . _separator_written_last ) : <EOL> self . _outfile . write ( text . encode ( '<STR_LIT>' ) . rstrip ( ) + '<STR_LIT:\n>' ) <EOL> self . _outfile . flush ( ) <EOL> self . _separator_written_last = separator </s>
