<s> import re <EOL> from robotide import robotapi , utils <EOL> from robotide . utils import variablematcher <EOL> from robotide . controller . basecontroller import _BaseController <EOL> from robotide . controller . cellinfo import ( CellPosition , CellType , CellInfo , <EOL> CellContent , ContentType ) <EOL> from robotide . namespace . local_namespace import LocalNamespace <EOL> class StepController ( _BaseController ) : <EOL> _GIVEN_WHEN_THEN_MATCHER = re . compile ( r'<STR_LIT>' , <EOL> re . I ) <EOL> def __init__ ( self , parent , step ) : <EOL> self . _init ( parent , step ) <EOL> self . _step . args = self . _change_last_empty_to_empty_var ( <EOL> self . _step . args , self . _step . comment ) <EOL> def _init ( self , parent , step ) : <EOL> self . parent = parent <EOL> self . _step = step <EOL> self . _cell_info_cache = { } <EOL> @ property <EOL> def display_name ( self ) : <EOL> return '<STR_LIT>' <EOL> @ property <EOL> def datafile_controller ( self ) : <EOL> return self . parent . datafile_controller <EOL> def _change_last_empty_to_empty_var ( self , args , comment ) : <EOL> if comment : <EOL> return args <EOL> return args [ : - <NUM_LIT:1> ] + [ '<STR_LIT>' ] if args and args [ - <NUM_LIT:1> ] == '<STR_LIT>' else args <EOL> def get_keyword_info ( self , kw ) : <EOL> if not kw : <EOL> return None <EOL> return self . parent . get_keyword_info ( kw ) <EOL> def __eq__ ( self , other ) : <EOL> if self is other : <EOL> return True <EOL> return self . _steps_are_equal ( self . _step , other . _step ) <EOL> def _steps_are_equal ( self , fst , snd ) : <EOL> if fst is snd : <EOL> return True <EOL> if not snd : <EOL> return False <EOL> return ( fst . assign == snd . assign and <EOL> fst . name == snd . name and <EOL> fst . args == snd . args ) <EOL> def get_value ( self , col ) : <EOL> values = self . as_list ( ) <EOL> if len ( values ) <= col : <EOL> return '<STR_LIT>' <EOL> return values [ col ] <EOL> def get_cell_info ( self , col ) : <EOL> if col not in self . _cell_info_cache : <EOL> position = self . _get_cell_position ( col ) <EOL> content = self . _get_content_with_type ( col , position ) <EOL> self . _cell_info_cache [ col ] = self . _build_cell_info ( <EOL> content , position ) <EOL> return self . _cell_info_cache [ col ] <EOL> @ property <EOL> def assignments ( self ) : <EOL> return self . _step . assign <EOL> def is_assigning ( self , value ) : <EOL> for assignment in self . assignments : <EOL> if assignment . replace ( '<STR_LIT:=>' , '<STR_LIT>' ) . strip ( ) == value . replace ( '<STR_LIT:=>' , '<STR_LIT>' ) . strip ( ) : <EOL> return True <EOL> return False <EOL> def _build_cell_info ( self , content , position ) : <EOL> return CellInfo ( content , position ) <EOL> def _get_cell_position ( self , col ) : <EOL> if self . parent . has_template ( ) : <EOL> return CellPosition ( CellType . UNKNOWN , None ) <EOL> col -= len ( self . _step . assign ) <EOL> if col < <NUM_LIT:0> : <EOL> return CellPosition ( CellType . ASSIGN , None ) <EOL> if col == <NUM_LIT:0> : <EOL> return CellPosition ( CellType . KEYWORD , None ) <EOL> info = self . get_keyword_info ( self . _step . name ) <EOL> if not info : <EOL> return CellPosition ( CellType . UNKNOWN , None ) <EOL> args = info . arguments <EOL> args_amount = len ( args ) <EOL> if args_amount == <NUM_LIT:0> : <EOL> return CellPosition ( CellType . MUST_BE_EMPTY , None ) <EOL> if col >= args_amount and self . _last_argument_is_varargs ( args ) : <EOL> return CellPosition ( CellType . OPTIONAL , args [ - <NUM_LIT:1> ] ) <EOL> if self . _has_list_or_dict_var_value_before ( col - <NUM_LIT:1> ) : <EOL> return CellPosition ( CellType . UNKNOWN , None ) <EOL> if col > args_amount : <EOL> return CellPosition ( CellType . MUST_BE_EMPTY , None ) <EOL> if col <= self . _number_of_mandatory_arguments ( args , args_amount ) : <EOL> return CellPosition ( CellType . MANDATORY , args [ col - <NUM_LIT:1> ] ) <EOL> return CellPosition ( CellType . OPTIONAL , args [ col - <NUM_LIT:1> ] ) <EOL> def _number_of_mandatory_arguments ( self , args , args_amount ) : <EOL> defaults = [ arg for arg in args if '<STR_LIT:=>' in arg ] <EOL> n = args_amount - len ( defaults ) <EOL> if self . _last_argument_is_varargs ( args ) : <EOL> n -= <NUM_LIT:1> <EOL> return n <EOL> def _last_argument_is_varargs ( self , args ) : <EOL> return args [ - <NUM_LIT:1> ] . startswith ( '<STR_LIT:*>' ) <EOL> def _has_list_or_dict_var_value_before ( self , arg_index ) : <EOL> for idx , value in enumerate ( self . args ) : <EOL> if idx > arg_index : <EOL> return False <EOL> if variablematcher . is_list_variable ( value ) and not variablematcher . is_list_variable_subitem ( value ) : <EOL> return True <EOL> if robotapi . is_dict_var ( value ) and not variablematcher . is_dict_var_access ( value ) : <EOL> return True <EOL> return False <EOL> def _get_content_with_type ( self , col , position ) : <EOL> value = self . get_value ( col ) <EOL> if self . _is_commented ( col ) : <EOL> return CellContent ( ContentType . COMMENTED , value ) <EOL> if self . _get_last_none_empty_col_idx ( ) < col : <EOL> return CellContent ( ContentType . EMPTY , value ) <EOL> if variablematcher . is_variable ( value ) : <EOL> if self . _is_unknow_variable ( value , position ) : <EOL> return CellContent ( ContentType . UNKNOWN_VARIABLE , value ) <EOL> return CellContent ( ContentType . VARIABLE , value ) <EOL> if self . is_user_keyword ( value ) : <EOL> return CellContent ( <EOL> ContentType . USER_KEYWORD , value , <EOL> self . get_keyword_info ( value ) . source ) <EOL> if self . is_library_keyword ( value ) : <EOL> return CellContent ( <EOL> ContentType . LIBRARY_KEYWORD , value , <EOL> self . get_keyword_info ( value ) . source ) <EOL> return CellContent ( ContentType . STRING , value ) <EOL> def _is_unknow_variable ( self , value , position ) : <EOL> if position . type == CellType . ASSIGN : <EOL> return False <EOL> is_known = self . _get_local_namespace ( ) . has_name ( value ) <EOL> if is_known : <EOL> return False <EOL> inner_value = value [ <NUM_LIT:2> : - <NUM_LIT:1> ] <EOL> modified = re . split ( r'<STR_LIT>' , inner_value , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> return not self . _get_local_namespace ( ) . has_name ( <EOL> '<STR_LIT>' % ( value [ <NUM_LIT:0> ] , modified ) ) <EOL> def _get_local_namespace ( self ) : <EOL> index = self . parent . index_of_step ( self . _step ) <EOL> return LocalNamespace ( <EOL> self . parent , self . datafile_controller . _namespace , index ) <EOL> def _get_last_none_empty_col_idx ( self ) : <EOL> values = self . as_list ( ) <EOL> for i in reversed ( range ( len ( values ) ) ) : <EOL> if values [ i ] . strip ( ) != '<STR_LIT>' : <EOL> return i <EOL> return None <EOL> def is_modifiable ( self ) : <EOL> return self . datafile_controller . is_modifiable ( ) <EOL> def is_user_keyword ( self , value ) : <EOL> return self . parent . is_user_keyword ( value ) <EOL> def is_library_keyword ( self , value ) : <EOL> return self . parent . is_library_keyword ( value ) <EOL> def as_list ( self ) : <EOL> return self . _step . as_list ( ) <EOL> def contains_variable ( self , name ) : <EOL> return any ( variablematcher . value_contains_variable ( item , name ) <EOL> for item in self . as_list ( ) ) <EOL> def contains_variable_assignment ( self , name ) : <EOL> return any ( variablematcher . value_contains_variable ( item , "<STR_LIT>" % name ) <EOL> for item in self . as_list ( ) ) <EOL> def contains_keyword ( self , name ) : <EOL> return any ( self . _kw_name_match ( item , name ) <EOL> for item in [ self . keyword or '<STR_LIT>' ] + self . args ) <EOL> def _kw_name_match ( self , item , expected ) : <EOL> if isinstance ( expected , basestring ) : <EOL> return utils . eq ( item , expected ) or ( <EOL> self . _GIVEN_WHEN_THEN_MATCHER . match ( item ) and <EOL> utils . eq ( <EOL> self . _GIVEN_WHEN_THEN_MATCHER . sub ( '<STR_LIT>' , item ) , expected ) ) <EOL> return expected . match ( item ) <EOL> def replace_keyword ( self , new_name , old_name ) : <EOL> if self . _kw_name_match ( self . keyword or '<STR_LIT>' , old_name ) : <EOL> self . _step . name = self . _kw_name_replace ( <EOL> self . keyword , new_name , old_name ) <EOL> for index , value in enumerate ( self . args ) : <EOL> if self . _kw_name_match ( value , old_name ) : <EOL> self . _step . args [ index ] = self . _kw_name_replace ( <EOL> value , new_name , old_name ) <EOL> def _kw_name_replace ( self , old_value , new_match , old_match ) : <EOL> old_prefix_matcher = self . _GIVEN_WHEN_THEN_MATCHER . match ( old_value ) <EOL> if not old_prefix_matcher : <EOL> return new_match <EOL> old_prefix = old_prefix_matcher . group ( <NUM_LIT:0> ) <EOL> old_match_matcher = self . _GIVEN_WHEN_THEN_MATCHER . match ( old_match ) <EOL> if old_match_matcher and old_match_matcher . group ( <NUM_LIT:0> ) == old_prefix : <EOL> return new_match <EOL> return old_prefix + new_match <EOL> @ property <EOL> def datafile ( self ) : <EOL> return self . parent . datafile <EOL> @ property <EOL> def keyword ( self ) : <EOL> return self . _step . name <EOL> @ property <EOL> def assign ( self ) : <EOL> return self . _step . assign <EOL> @ property <EOL> def args ( self ) : <EOL> return self . _step . args <EOL> @ property <EOL> def vars ( self ) : <EOL> return self . _step . vars <EOL> def change ( self , col , new_value ) : <EOL> cells = self . as_list ( ) <EOL> if col >= len ( cells ) : <EOL> cells = cells + [ '<STR_LIT>' for _ in range ( col - len ( cells ) + <NUM_LIT:1> ) ] <EOL> cells [ col ] = new_value <EOL> comment = self . _get_comment ( cells ) <EOL> if comment : <EOL> cells . pop ( ) <EOL> self . _recreate ( cells , comment ) <EOL> def comment ( self ) : <EOL> self . shift_right ( <NUM_LIT:0> ) <EOL> self . change ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> def _is_commented ( self , col ) : <EOL> if self . _has_comment_keyword ( ) : <EOL> return col > self . _keyword_column <EOL> for i in range ( min ( col + <NUM_LIT:1> , len ( self . as_list ( ) ) ) ) : <EOL> if self . get_value ( i ) . strip ( ) . startswith ( '<STR_LIT:#>' ) : <EOL> return True <EOL> return False <EOL> @ property <EOL> def _keyword_column ( self ) : <EOL> return <NUM_LIT:0> <EOL> def _has_comment_keyword ( self ) : <EOL> if self . keyword is None : <EOL> return False <EOL> return self . keyword . strip ( ) . lower ( ) == "<STR_LIT>" <EOL> def uncomment ( self ) : <EOL> if self . _step . name == '<STR_LIT>' : <EOL> self . shift_left ( <NUM_LIT:0> ) <EOL> def shift_right ( self , from_column ) : <EOL> cells = self . as_list ( ) <EOL> comment = self . _get_comment ( cells ) <EOL> if len ( cells ) > from_column : <EOL> if comment : <EOL> cells . pop ( ) <EOL> cells = cells [ : from_column ] + [ '<STR_LIT>' ] + cells [ from_column : ] <EOL> self . _recreate ( cells , comment ) <EOL> def shift_left ( self , from_column ) : <EOL> cells = self . as_list ( ) <EOL> comment = self . _get_comment ( cells ) <EOL> if len ( cells ) > from_column : <EOL> if comment : <EOL> cells . pop ( ) <EOL> cells = cells [ : from_column ] + cells [ from_column + <NUM_LIT:1> : ] <EOL> self . _recreate ( cells , comment ) <EOL> def insert_before ( self , new_step ) : <EOL> steps = self . parent . get_raw_steps ( ) <EOL> index = steps . index ( self . _step ) <EOL> self . parent . set_raw_steps ( steps [ : index ] + [ new_step ] + steps [ index : ] ) <EOL> def insert_after ( self , new_step ) : <EOL> steps = self . parent . get_raw_steps ( ) <EOL> index = steps . index ( self . _step ) + <NUM_LIT:1> <EOL> self . parent . set_raw_steps ( steps [ : index ] + [ new_step ] + steps [ index : ] ) <EOL> def remove_empty_columns_from_end ( self ) : <EOL> cells = self . as_list ( ) <EOL> while cells != [ ] and cells [ - <NUM_LIT:1> ] . strip ( ) == '<STR_LIT>' : <EOL> cells . pop ( ) <EOL> self . _recreate ( cells ) <EOL> def remove_empty_columns_from_beginning ( self ) : <EOL> cells = self . _step . as_list ( ) <EOL> while cells != [ ] and cells [ <NUM_LIT:0> ] . strip ( ) == '<STR_LIT>' : <EOL> cells = cells [ <NUM_LIT:1> : ] <EOL> self . _recreate ( cells ) <EOL> def remove ( self ) : <EOL> self . parent . data . steps . remove ( self . _step ) <EOL> self . parent . _clear_cached_steps ( ) <EOL> def move_up ( self ) : <EOL> previous_step = self . parent . step ( self . _index ( ) - <NUM_LIT:1> ) <EOL> self . remove ( ) <EOL> previous_step . insert_before ( self . _step ) <EOL> def move_down ( self ) : <EOL> next_step = self . parent . step ( self . _index ( ) + <NUM_LIT:1> ) <EOL> self . remove ( ) <EOL> next_step . insert_after ( self . _step ) <EOL> def _index ( self ) : <EOL> return self . parent . index_of_step ( self . _step ) <EOL> def has_only_comment ( self ) : <EOL> non_empty_cells = [ cell for cell <EOL> in self . _step . as_list ( ) if cell . strip ( ) != '<STR_LIT>' ] <EOL> return len ( non_empty_cells ) == <NUM_LIT:1> and non_empty_cells [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) <EOL> def _get_comment ( self , cells ) : <EOL> if not cells : <EOL> return None <EOL> return cells [ - <NUM_LIT:1> ] [ <NUM_LIT:2> : ] . strip ( ) if cells [ - <NUM_LIT:1> ] . startswith ( '<STR_LIT>' ) else None <EOL> def _recreate ( self , cells , comment = None ) : <EOL> if self . _is_partial_for_loop_step ( cells ) : <EOL> self . _recreate_as_partial_for_loop ( cells , comment ) <EOL> elif self . _is_intended_step ( cells ) : <EOL> i = self . _index ( ) <EOL> previous_step = self . parent . step ( i - <NUM_LIT:1> ) <EOL> if type ( previous_step ) == ForLoopStepController : <EOL> self . _recreate_as_intended_step ( <EOL> previous_step , cells , comment , i ) <EOL> elif type ( previous_step ) == IntendedStepController : <EOL> self . _recreate_as_intended_step ( <EOL> previous_step . parent , cells , comment , i ) <EOL> else : <EOL> self . _step . __init__ ( cells , comment ) <EOL> else : <EOL> self . _step . __init__ ( cells , comment ) <EOL> def _is_partial_for_loop_step ( self , cells ) : <EOL> return cells and cells [ <NUM_LIT:0> ] . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) . upper ( ) == '<STR_LIT>' <EOL> def _is_intended_step ( self , cells ) : <EOL> return cells and not cells [ <NUM_LIT:0> ] . strip ( ) and any ( c . strip ( ) for c in cells ) and self . _index ( ) > <NUM_LIT:0> <EOL> def _recreate_as_partial_for_loop ( self , cells , comment ) : <EOL> index = self . _index ( ) <EOL> self . parent . replace_step ( index , PartialForLoop ( <EOL> cells [ <NUM_LIT:1> : ] , first_cell = cells [ <NUM_LIT:0> ] , comment = comment ) ) <EOL> self . _recreate_next_step ( index ) <EOL> def _recreate_as_intended_step ( self , for_loop_step , cells , comment , index ) : <EOL> self . remove ( ) <EOL> for_loop_step . add_step ( robotapi . Step ( cells [ <NUM_LIT:1> : ] , comment ) ) <EOL> self . _recreate_next_step ( index ) <EOL> def _recreate_next_step ( self , index ) : <EOL> if len ( self . parent . steps ) > index + <NUM_LIT:1> : <EOL> next_step = self . parent . step ( index + <NUM_LIT:1> ) <EOL> next_step . _recreate ( next_step . as_list ( ) ) <EOL> def notify_value_changed ( self ) : <EOL> self . parent . notify_steps_changed ( ) <EOL> class PartialForLoop ( robotapi . ForLoop ) : <EOL> def __init__ ( self , cells , first_cell = '<STR_LIT>' , comment = None ) : <EOL> self . _cells = cells <EOL> self . _first_cell = first_cell <EOL> robotapi . ForLoop . __init__ ( self , cells , comment ) <EOL> def as_list ( self , indent = False , include_comment = False ) : <EOL> return [ self . _first_cell ] + self . _cells + self . comment . as_list ( ) <EOL> class ForLoopStepController ( StepController ) : <EOL> def __init__ ( self , parent , step ) : <EOL> self . _init ( parent , step ) <EOL> @ property <EOL> def name ( self ) : <EOL> return self . parent . name <EOL> @ property <EOL> def assignments ( self ) : <EOL> return self . _step . vars <EOL> def move_up ( self ) : <EOL> previous_step = self . parent . step ( self . _index ( ) - <NUM_LIT:1> ) <EOL> if isinstance ( previous_step , ForLoopStepController ) : <EOL> self . _swap_forloop_headers ( previous_step ) <EOL> else : <EOL> self . get_raw_steps ( ) . insert ( <NUM_LIT:0> , previous_step . _step ) <EOL> previous_step . remove ( ) <EOL> def _swap_forloop_headers ( self , previous_step ) : <EOL> previous_step . _step . steps = self . _step . steps <EOL> self . _step . steps = [ ] <EOL> steps = self . parent . get_raw_steps ( ) <EOL> i = steps . index ( self . _step ) <EOL> steps [ i - <NUM_LIT:1> ] = self . _step <EOL> steps [ i ] = previous_step . _step <EOL> self . parent . set_raw_steps ( steps ) <EOL> def move_down ( self ) : <EOL> next_step = self . step ( self . _index ( ) + <NUM_LIT:1> ) <EOL> next_step . move_up ( ) <EOL> if len ( self . _step . steps ) == <NUM_LIT:0> : <EOL> self . _recreate_complete_for_loop_header ( cells = self . as_list ( ) ) <EOL> def insert_after ( self , new_step ) : <EOL> self . get_raw_steps ( ) . insert ( <NUM_LIT:0> , new_step ) <EOL> def step ( self , index ) : <EOL> return self . parent . step ( index ) <EOL> def _has_comment_keyword ( self ) : <EOL> return False <EOL> def get_raw_steps ( self ) : <EOL> return self . _step . steps <EOL> def set_raw_steps ( self , steps ) : <EOL> self . _step . steps = steps <EOL> def _get_cell_position ( self , col ) : <EOL> until_range = len ( self . _step . vars ) + <NUM_LIT:1> <EOL> flavor = self . _step . flavor <EOL> if col == <NUM_LIT:0> : <EOL> return CellPosition ( CellType . MANDATORY , None ) <EOL> if col < until_range : <EOL> return CellPosition ( CellType . ASSIGN , None ) <EOL> if col == until_range : <EOL> return CellPosition ( CellType . MANDATORY , None ) <EOL> if '<STR_LIT>' not in flavor : <EOL> return CellPosition ( CellType . OPTIONAL , None ) <EOL> if col <= until_range + <NUM_LIT:1> : <EOL> return CellPosition ( CellType . MANDATORY , None ) <EOL> if col <= until_range + <NUM_LIT:3> : <EOL> return CellPosition ( CellType . OPTIONAL , None ) <EOL> return CellPosition ( CellType . MUST_BE_EMPTY , None ) <EOL> def _build_cell_info ( self , content , position ) : <EOL> return CellInfo ( content , position , for_loop = True ) <EOL> @ property <EOL> def steps ( self ) : <EOL> return [ IntendedStepController ( self , sub_step ) <EOL> for sub_step in self . get_raw_steps ( ) ] <EOL> def index_of_step ( self , step ) : <EOL> index_in_for_loop = self . get_raw_steps ( ) . index ( step ) <EOL> return self . _index ( ) + index_in_for_loop + <NUM_LIT:1> <EOL> def _get_comment ( self , cells ) : <EOL> return None <EOL> def comment ( self ) : <EOL> self . _replace_with_new_cells ( [ '<STR_LIT>' ] + self . as_list ( ) ) <EOL> def uncomment ( self ) : <EOL> pass <EOL> def contains_keyword ( self , name ) : <EOL> return False <EOL> def add_step ( self , step ) : <EOL> self . get_raw_steps ( ) . append ( step ) <EOL> def _recreate ( self , cells , comment = None ) : <EOL> if not self . _represent_valid_for_loop_header ( cells ) : <EOL> self . _recreate_partial_for_loop_header ( cells , comment ) <EOL> else : <EOL> self . _recreate_complete_for_loop_header ( cells ) <EOL> def _recreate_complete_for_loop_header ( self , cells ) : <EOL> steps = self . get_raw_steps ( ) <EOL> self . _step . __init__ ( cells [ <NUM_LIT:1> : ] ) <EOL> self . set_raw_steps ( steps ) <EOL> def _recreate_partial_for_loop_header ( self , cells , comment ) : <EOL> if not cells or cells [ <NUM_LIT:0> ] . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) . upper ( ) != '<STR_LIT>' : <EOL> self . _replace_with_new_cells ( cells ) <EOL> else : <EOL> steps = self . get_raw_steps ( ) <EOL> i = self . _index ( ) <EOL> StepController . _recreate_as_partial_for_loop ( self , cells , comment ) <EOL> self . parent . step ( i ) . set_raw_steps ( steps ) <EOL> def remove ( self ) : <EOL> steps = self . parent . data . steps <EOL> index = steps . index ( self . _step ) <EOL> steps . remove ( self . _step ) <EOL> self . parent . data . steps = steps [ : index ] + self . get_raw_steps ( ) + steps [ index : ] <EOL> self . _step . steps = [ ] <EOL> def _represent_valid_for_loop_header ( self , cells ) : <EOL> if not cells : <EOL> return False <EOL> if cells [ <NUM_LIT:0> ] != self . as_list ( ) [ <NUM_LIT:0> ] : <EOL> return False <EOL> in_token_index = len ( self . vars ) + <NUM_LIT:1> <EOL> if len ( cells ) <= in_token_index : <EOL> return False <EOL> if len ( self . as_list ( ) ) <= in_token_index : <EOL> return False <EOL> if cells [ in_token_index ] != self . as_list ( ) [ in_token_index ] : <EOL> return False <EOL> return True <EOL> def _replace_with_new_cells ( self , cells ) : <EOL> index = self . parent . index_of_step ( self . _step ) <EOL> self . parent . replace_step ( index , robotapi . Step ( cells ) ) <EOL> self . get_raw_steps ( ) . reverse ( ) <EOL> for substep in self . steps : <EOL> self . parent . add_step ( index + <NUM_LIT:1> , robotapi . Step ( substep . as_list ( ) ) ) <EOL> def notify_steps_changed ( self ) : <EOL> self . notify_value_changed ( ) <EOL> def has_template ( self ) : <EOL> return self . parent . has_template ( ) <EOL> class IntendedStepController ( StepController ) : <EOL> _invalid = False <EOL> @ property <EOL> def _keyword_column ( self ) : <EOL> return <NUM_LIT:1> <EOL> def as_list ( self ) : <EOL> return [ '<STR_LIT>' ] + self . _step . as_list ( ) <EOL> def _get_cell_position ( self , col ) : <EOL> if col == <NUM_LIT:0> : <EOL> return CellPosition ( CellType . MUST_BE_EMPTY , None ) <EOL> return StepController . _get_cell_position ( self , col - <NUM_LIT:1> ) <EOL> def _get_local_namespace ( self ) : <EOL> p = self . parent . parent <EOL> index = p . index_of_step ( self . _step ) <EOL> return LocalNamespace ( p , self . datafile_controller . _namespace , index ) <EOL> def _get_content_with_type ( self , col , position ) : <EOL> if col == <NUM_LIT:0> : <EOL> return CellContent ( ContentType . EMPTY , None ) <EOL> return StepController . _get_content_with_type ( self , col , position ) <EOL> def comment ( self ) : <EOL> self . _step . __init__ ( [ '<STR_LIT>' ] + self . _step . as_list ( ) ) <EOL> def uncomment ( self ) : <EOL> if self . _step . name == '<STR_LIT>' : <EOL> self . _step . __init__ ( self . _step . as_list ( ) [ <NUM_LIT:1> : ] ) <EOL> def _recreate ( self , cells , comment = None ) : <EOL> if cells == [ ] or cells [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> self . _step . __init__ ( cells [ <NUM_LIT:1> : ] , comment = comment ) <EOL> if self . _step not in self . parent . get_raw_steps ( ) : <EOL> self . parent . add_step ( self . _step ) <EOL> else : <EOL> self . _recreate_as_normal_step ( cells , comment ) <EOL> self . _invalid = True <EOL> def _recreate_as_normal_step ( self , cells , comment = None ) : <EOL> steps = self . parent . steps <EOL> index = [ s . _step for s in steps ] . index ( self . _step ) <EOL> for i , step in reversed ( list ( enumerate ( steps ) ) ) : <EOL> if i == index : <EOL> break <EOL> step . _replace_with_normal_step ( i ) <EOL> self . _replace_with_normal_step ( index , cells , comment ) <EOL> def _replace_with_normal_step ( self , index , cells = None , comment = None ) : <EOL> index_of_parent = self . parent . parent . index_of_step ( self . parent . _step ) <EOL> self . parent . parent . add_step ( <EOL> index_of_parent + index + <NUM_LIT:2> , <EOL> robotapi . Step ( cells or self . as_list ( ) , comment = comment ) ) <EOL> self . parent . get_raw_steps ( ) . pop ( index ) <EOL> def remove ( self ) : <EOL> self . parent . get_raw_steps ( ) . remove ( self . _step ) <EOL> @ utils . overrides ( StepController ) <EOL> def remove_empty_columns_from_end ( self ) : <EOL> if self . _invalid : <EOL> return <EOL> StepController . remove_empty_columns_from_end ( self ) </s>
