18 from robot.errors import (DataError, ExecutionStatus, HandlerExecutionFailed,
20 from robot.utils import (ErrorDetails, format_assign_message, get_error_message,
21 is_number, is_string, prepr, type_name)
29 self.
assignmentassignment = [validator.validate(var)
for var
in assignment]
31 except DataError
as err:
61 is_dict=variable[0] ==
'&')
66 raise DataError(
"Assign mark '=' can be used only with the last variable.",
68 if variable.endswith(
'='):
70 return variable[:-1].rstrip()
75 raise DataError(
'Assignment can contain only one list variable.',
78 raise DataError(
'Dictionary variable cannot be assigned with other '
79 'variables.', syntax=
True)
89 _valid_extended_attr = re.compile(
r'^[_a-zA-Z]\w*$')
101 if not isinstance(error, ExecutionStatus):
103 if error.can_continue(self.
_context_context):
104 self.
assignassign(error.return_value)
108 context.trace(
lambda:
'Return: %s' %
prepr(return_value))
110 for name, value
in resolver.resolve(return_value):
111 if not self.
_extended_assign_extended_assign(name, value, context.variables):
112 value = self.
_normal_assign_normal_assign(name, value, context.variables)
116 if name[0] !=
'$' or '.' not in name
or name
in variables:
118 base, attr = [token.strip()
for token
in name[2:-1].rsplit(
'.', 1)]
120 var = variables.replace_scalar(
'${%s}' % base)
121 except VariableError:
127 setattr(var, attr, value)
129 raise VariableError(
"Setting attribute '%s' to variable '${%s}' failed: %s"
140 variables[name] = value
142 return value
if name[0] ==
'$' else variables[name]
148 if len(assignment) == 1:
150 if any(a[0] ==
'@' for a
in assignment):
167 if return_value
is None:
169 return_value = {
'$':
None,
'@': [],
'&': {}}[identifier]
170 return [(self.
_variable_variable, return_value)]
181 self.
_validate_validate(len(return_value))
182 return self.
_resolve_resolve(return_value)
185 if return_value
is None:
190 return list(return_value)
195 self.
_raise_raise(
'Expected list-like value, got %s.' %
type_name(ret))
201 raise NotImplementedError
204 raise NotImplementedError
211 self.
_raise_raise(
'Expected %d return values, got %d.'
215 return list(zip(self.
_variables_variables, return_value))
221 _MultiReturnValueResolver.__init__(self, variables)
226 self.
_raise_raise(
'Expected %d or more return values, got %d.'
230 before_vars, list_var, after_vars \
232 before_items, list_items, after_items \
233 = self.
_split_return_split_return(return_value, before_vars, after_vars)
234 before = list(zip(before_vars, before_items))
235 after = list(zip(after_vars, after_items))
236 return before + [(list_var, list_items)] + after
239 list_index = [v[0]
for v
in variables].index(
'@')
240 return (variables[:list_index],
241 variables[list_index],
242 variables[list_index+1:])
245 list_start = len(before_vars)
246 list_end = len(return_value) - len(after_vars)
247 return (return_value[:list_start],
248 return_value[list_start:list_end],
249 return_value[list_end:])
Used when variable does not exist.
Object wrapping the last occurred exception.
def _validate_assign_mark(self, variable)
def _validate_state(self, is_list, is_dict)
def validate(self, variable)
def resolve(self, return_value)
def resolve(self, return_value)
def __init__(self, variable)
def _validate(self, return_count)
def _split_variables(self, variables)
def __init__(self, variables)
def _split_return(self, return_value, before_vars, after_vars)
def _resolve(self, return_value)
def _resolve(self, return_value)
def _validate(self, return_count)
def _normal_assign(self, name, value, variables)
def __exit__(self, etype, error, tb)
def _is_valid_extended_attribute(self, attr)
def _variable_supports_extended_assign(self, var)
def _extended_assign(self, name, value, variables)
def assign(self, return_value)
def __init__(self, assignment, context)
def assigner(self, context)
def __init__(self, assignment)
def validate_assignment(self)
def resolve(self, return_value)
def __init__(self, variables)
def _raise_expected_list(self, ret)
def _validate(self, return_count)
def _convert_to_list(self, return_value)
def _resolve(self, return_value)
def get_error_message()
Returns error message of the last occurred exception.
def type_name(item, capitalize=False)
Return "non-technical" type name for objects and types.
def format_assign_message(variable, value, cut_long=True)
def prepr(item, width=80)
def ReturnValueResolver(assignment)