<s> import time <EOL> from robot import utils <EOL> from . stringcache import StringIndex <EOL> class JsExecutionResult ( object ) : <EOL> def __init__ ( self , suite , statistics , errors , strings , basemillis = None , <EOL> split_results = None , min_level = None ) : <EOL> self . suite = suite <EOL> self . strings = strings <EOL> self . min_level = min_level <EOL> self . data = self . _get_data ( statistics , errors , basemillis or <NUM_LIT:0> ) <EOL> self . split_results = split_results or [ ] <EOL> def _get_data ( self , statistics , errors , basemillis ) : <EOL> gentime = time . localtime ( ) <EOL> return { <EOL> '<STR_LIT>' : statistics , <EOL> '<STR_LIT>' : errors , <EOL> '<STR_LIT>' : basemillis , <EOL> '<STR_LIT>' : long ( time . mktime ( gentime ) * <NUM_LIT:1000> ) - basemillis , <EOL> '<STR_LIT>' : utils . format_time ( gentime , gmtsep = '<STR_LIT:U+0020>' ) <EOL> } <EOL> def remove_data_not_needed_in_report ( self ) : <EOL> self . data . pop ( '<STR_LIT>' ) <EOL> remover = _KeywordRemover ( ) <EOL> self . suite = remover . remove_keywords ( self . suite ) <EOL> self . suite , self . strings = remover . remove_unused_strings ( self . suite , self . strings ) <EOL> class _KeywordRemover ( object ) : <EOL> def remove_keywords ( self , suite ) : <EOL> return self . _remove_keywords_from_suite ( suite ) <EOL> def _remove_keywords_from_suite ( self , suite ) : <EOL> return suite [ : <NUM_LIT:6> ] + ( self . _remove_keywords_from_suites ( suite [ <NUM_LIT:6> ] ) , <EOL> self . _remove_keywords_from_tests ( suite [ <NUM_LIT:7> ] ) , <EOL> ( ) , suite [ <NUM_LIT:9> ] ) <EOL> def _remove_keywords_from_suites ( self , suites ) : <EOL> return tuple ( self . _remove_keywords_from_suite ( s ) for s in suites ) <EOL> def _remove_keywords_from_tests ( self , tests ) : <EOL> return tuple ( self . _remove_keywords_from_test ( t ) for t in tests ) <EOL> def _remove_keywords_from_test ( self , test ) : <EOL> return test [ : - <NUM_LIT:1> ] + ( ( ) , ) <EOL> def remove_unused_strings ( self , model , strings ) : <EOL> used = set ( self . _get_used_indices ( model ) ) <EOL> remap = { } <EOL> strings = tuple ( self . _get_used_strings ( strings , used , remap ) ) <EOL> model = tuple ( self . _remap_string_indices ( model , remap ) ) <EOL> return model , strings <EOL> def _get_used_indices ( self , model ) : <EOL> for item in model : <EOL> if isinstance ( item , StringIndex ) : <EOL> yield item <EOL> elif isinstance ( item , tuple ) : <EOL> for i in self . _get_used_indices ( item ) : <EOL> yield i <EOL> def _get_used_strings ( self , strings , used_indices , remap ) : <EOL> offset = <NUM_LIT:0> <EOL> for index , string in enumerate ( strings ) : <EOL> if index in used_indices : <EOL> remap [ index ] = index - offset <EOL> yield string <EOL> else : <EOL> offset += <NUM_LIT:1> <EOL> def _remap_string_indices ( self , model , remap ) : <EOL> for item in model : <EOL> if isinstance ( item , StringIndex ) : <EOL> yield remap [ item ] <EOL> elif isinstance ( item , tuple ) : <EOL> yield tuple ( self . _remap_string_indices ( item , remap ) ) <EOL> else : <EOL> yield item </s>
