parameters: (set_variables, input_string)
docstring: Replaces variable within the input_string with their corresponding values
    from the given set_variables.
docstring_summary: Replaces variable within the input_string with their corresponding values
    from the given set_variables.
docstring_tokens: Replaces variable within the input_string with their corresponding values from the given set_variables .
function: def replace_variables(set_variables, input_string):
    """
    Replaces variable within the input_string with their corresponding values
    from the given set_variables.
    """
    errors = False
  
    # In the case of a byte sequence, re.findall() will choke under python 3
    if sys.version_info.major > 2:
      if not isinstance(input_string, str):
        input_string = input_string.decode('utf-8')
  
    matches = set([v.upper() for v in re.findall(r'(?<!\\)\${([^}]+)}', input_string)])
    for name in matches:
      value = None
      # Check if syntax is correct
      var_name = get_var_name(name)
      if var_name is None:
        print('Error: Unknown substitution syntax (%s). ' % (name,) +
              'Use ${VAR:var_name}.', file=sys.stderr)
        errors = True
      else:
        # Replaces variable value
        if set_variables and var_name in set_variables:
          value = set_variables[var_name]
          if value is None:
            errors = True
          else:
            regexp = re.compile(r'(?<!\\)\${%s}' % (name,), re.IGNORECASE)
            input_string = regexp.sub(value, input_string)
        else:
          print('Error: Unknown variable %s' % (var_name), file=sys.stderr)
          errors = True
    if errors:
      return None
    else:
      return input_string
function_tokens: def replace_variables ( set_variables , input_string ) : errors = False # In the case of a byte sequence, re.findall() will choke under python 3 if sys . version_info . major > 2 : if not isinstance ( input_string , str ) : input_string = input_string . decode ( 'utf-8' ) matches = set ( [ v . upper ( ) for v in re . findall ( r'(?<!\\)\${([^}]+)}' , input_string ) ] ) for name in matches : value = None # Check if syntax is correct var_name = get_var_name ( name ) if var_name is None : print ( 'Error: Unknown substitution syntax (%s). ' % ( name , ) + 'Use ${VAR:var_name}.' , file = sys . stderr ) errors = True else : # Replaces variable value if set_variables and var_name in set_variables : value = set_variables [ var_name ] if value is None : errors = True else : regexp = re . compile ( r'(?<!\\)\${%s}' % ( name , ) , re . IGNORECASE ) input_string = regexp . sub ( value , input_string ) else : print ( 'Error: Unknown variable %s' % ( var_name ) , file = sys . stderr ) errors = True if errors : return None else : return input_string