Skip to content

robot.variables.replacer

VariableReplacer

VariableReplacer(variables)
Source code in src/robot/variables/replacer.py
def __init__(self, variables):
    self._finder = VariableFinder(variables)

replace_list

1
2
3
replace_list(
    items, replace_until=None, ignore_errors=False
)

Replaces variables from a list of items.

If an item in a list is a @{list} variable its value is returned. Possible variables from other items are replaced using 'replace_scalar'. Result is always a list.

'replace_until' can be used to limit replacing arguments to certain index from the beginning. Used with Run Keyword variants that only want to resolve some arguments in the beginning and pass others to called keywords unmodified.

Source code in src/robot/variables/replacer.py
def replace_list(self, items, replace_until=None, ignore_errors=False):
    """Replaces variables from a list of items.

    If an item in a list is a @{list} variable its value is returned.
    Possible variables from other items are replaced using 'replace_scalar'.
    Result is always a list.

    'replace_until' can be used to limit replacing arguments to certain
    index from the beginning. Used with Run Keyword variants that only
    want to resolve some arguments in the beginning and pass others
    to called keywords unmodified.
    """
    items = list(items or [])
    if replace_until is not None:
        return self._replace_list_until(items, replace_until, ignore_errors)
    return self._replace_list(items, ignore_errors)

replace_scalar

replace_scalar(item, ignore_errors=False)

Replaces variables from a scalar item.

If the item is not a string it is returned as is. If it is a variable, its value is returned. Otherwise, possible variables are replaced with 'replace_string'. Result may be any object.

Source code in src/robot/variables/replacer.py
def replace_scalar(self, item, ignore_errors=False):
    """Replaces variables from a scalar item.

    If the item is not a string it is returned as is. If it is a variable,
    its value is returned. Otherwise, possible variables are replaced with
    'replace_string'. Result may be any object.
    """
    if isinstance(item, VariableMatch):
        match = item
    else:
        match = search_variable(item, ignore_errors=ignore_errors)
    if not match:
        return unescape(match.string)
    return self._replace_scalar(match, ignore_errors)

replace_string

1
2
3
replace_string(
    item, custom_unescaper=None, ignore_errors=False
)

Replaces variables from a string. Result is always a string.

Input can also be an already found VariableMatch.

Source code in src/robot/variables/replacer.py
def replace_string(self, item, custom_unescaper=None, ignore_errors=False):
    """Replaces variables from a string. Result is always a string.

    Input can also be an already found VariableMatch.
    """
    unescaper = custom_unescaper or unescape
    if isinstance(item, VariableMatch):
        match = item
    else:
        match = search_variable(item, ignore_errors=ignore_errors)
    if not match:
        return safe_str(unescaper(match.string))
    return self._replace_string(match, unescaper, ignore_errors)