<s> import re <EOL> from robotide import utils <EOL> _VAR_BODY = r'<STR_LIT>' <EOL> _SCALAR_VARIABLE_MATCHER = re . compile ( r'<STR_LIT>' + _VAR_BODY + '<STR_LIT>' ) <EOL> _SCALAR_VARIABLE_LINE_MATCHER = re . compile ( r'<STR_LIT>' + _VAR_BODY + '<STR_LIT>' ) <EOL> _LIST_VARIABLE_MATCHER = re . compile ( r'<STR_LIT>' + _VAR_BODY + '<STR_LIT>' ) <EOL> _DICT_VARIABLE_MATCHER = re . compile ( r'<STR_LIT>' + _VAR_BODY + '<STR_LIT>' ) <EOL> _LIST_VARIABLE_SUBITEM_END_MATCHER = re . compile ( r'<STR_LIT>' ) <EOL> _DICT_VARIABLE_SUBITEM_END_MATCHER = re . compile ( r'<STR_LIT>' ) <EOL> def is_variable ( value ) : <EOL> return is_scalar_variable ( value ) or is_list_variable ( value ) or is_dict_variable ( value ) <EOL> def is_scalar_variable ( value ) : <EOL> return _SCALAR_VARIABLE_LINE_MATCHER . match ( value . strip ( ) ) <EOL> def is_list_variable ( value ) : <EOL> return _LIST_VARIABLE_MATCHER . match ( value . strip ( ) ) <EOL> def is_dict_variable ( value ) : <EOL> return _DICT_VARIABLE_MATCHER . match ( value . strip ( ) ) <EOL> def is_list_variable_subitem ( value ) : <EOL> return is_list_variable ( value ) and _LIST_VARIABLE_SUBITEM_END_MATCHER . search ( value ) <EOL> def is_dict_var_access ( value ) : <EOL> return is_dict_variable ( value ) and _DICT_VARIABLE_SUBITEM_END_MATCHER . search ( value ) <EOL> def get_variable ( value ) : <EOL> """<STR_LIT>""" <EOL> match = is_variable ( value ) <EOL> return match . groups ( ) [ <NUM_LIT:0> ] if match else None <EOL> def get_variable_basename ( value ) : <EOL> "<STR_LIT>" <EOL> if is_list_variable ( value ) or is_dict_variable ( value ) : <EOL> return get_variable ( value ) <EOL> match = re . match ( '<STR_LIT>' , value ) <EOL> if not match : <EOL> return None <EOL> return '<STR_LIT>' % ( match . groups ( ) [ <NUM_LIT:0> ] . strip ( ) ) <EOL> def find_variable_basenames ( value ) : <EOL> return [ get_variable_basename ( var ) <EOL> for var in re . findall ( '<STR_LIT>' , value ) ] <EOL> def contains_scalar_variable ( value ) : <EOL> return bool ( _SCALAR_VARIABLE_MATCHER . findall ( value ) ) <EOL> def value_contains_variable ( value , varname ) : <EOL> return utils . Matcher ( "<STR_LIT>" % varname ) . match ( value ) </s>
