def _import(self, path): with io.open(path, encoding='UTF-8') as stream: variables = yaml.load(stream) if not is_dict_like(variables): raise DataError('YAML variable file must be a mapping, got %s.' % type_name(variables)) return variables.items()
def _import(self, path): with open(path) as stream: variables = yaml.load(stream) if not is_dict_like(variables): raise DataError('YAML variable file must be a mapping, got %s.' % type_name(variables)) return variables.items()
def _validate(self, name, value): if name[0] == '@' and not is_list_like(value): raise DataError("Invalid variable '%s': Expected list-like value, " "got %s." % (name, type_name(value))) if name[0] == '&' and not is_dict_like(value): raise DataError("Invalid variable '%s': Expected dict-like value, " "got %s." % (name, type_name(value)))
def _decorate(self, name, value): if is_dict_like(value): name = '&{%s}' % name elif is_list_like(value): name = '@{%s}' % name else: name = '${%s}' % name return name, value
def _get_variable_item(self, name, variable, item): if is_dict_like(variable): return self._get_dict_variable_item(name, variable, item) if is_list_like(variable): return self._get_list_variable_item(name, variable, item) raise VariableError("Variable '%s' is %s, not list or dictionary, " "and thus accessing item '%s' from it is not " "possible." % (name, type_name(variable), item))
def _get_dynamic(self, var_file, args): get_variables = (getattr(var_file, 'get_variables', None) or getattr(var_file, 'getVariables')) variables = get_variables(*args) if is_dict_like(variables): return variables.items() raise DataError("Expected '%s' to return dict-like value, got %s." % (get_variables.__name__, type_name(variables)))
def _convert(self, value): if isinstance(value, xmlrpclib.Binary): return bytes(value.data) if is_dict_like(value): return DotDict((k, self._convert(v)) for k, v in value.items()) if is_list_like(value): return [self._convert(v) for v in value] return value
def _convert(self, value): if isinstance(value, xmlrpclib.Binary): return str(value) if is_dict_like(value): return DotDict((k, self._convert(v)) for k, v in value.items()) if is_list_like(value): return [self._convert(v) for v in value] return value
def __init__(self, result): if not (is_dict_like(result) and 'status' in result): raise RuntimeError('Invalid remote result dictionary: %s' % result) self.status = result['status'] self.output = unic(self._get(result, 'output')) self.return_ = self._get(result, 'return') self.error = unic(self._get(result, 'error')) self.traceback = unic(self._get(result, 'traceback')) self.fatal = bool(self._get(result, 'fatal', False)) self.continuable = bool(self._get(result, 'continuable', False))
def __init__(self, result): if not (is_dict_like(result) and 'status' in result): raise RuntimeError('Invalid remote result dictionary: %s' % result) self.status = result['status'] self.output = self._get(result, 'output') self.return_ = self._get(result, 'return') self.error = self._get(result, 'error') self.traceback = self._get(result, 'traceback') self.fatal = bool(self._get(result, 'fatal', False)) self.continuable = bool(self._get(result, 'continuable', False))
def _undecorate(self, name, value): validate_var(name) if name[0] == '@': if not is_list_like(value): self._raise_cannot_set_type(name, value, 'list') value = list(value) if name[0] == '&': if not is_dict_like(value): self._raise_cannot_set_type(name, value, 'dictionary') value = DotDict(value) return name[2:-1], value
def validate(self, types): if types is None: return None if not types: return {} if is_dict_like(types): return self.validate_type_dict(types) if is_list_like(types): return self.convert_type_list_to_dict(types) raise DataError('Type information must be given as a dictionary or ' 'a list, got %s.' % type_name(types))
def _validate_value(self, value, identifier, name): if identifier == '@': if not is_list_like(value): raise VariableError("Value of variable '%s' is not list or " "list-like." % name) return list(value) if identifier == '&': if not is_dict_like(value): raise VariableError("Value of variable '%s' is not dictionary " "or dictionary-like." % name) return DotDict(value) return value
def _validate_value(self, value, identifier, name): if identifier == '@': if not is_list_like(value): raise VariableError("Value of variable '%s' is not list or " "list-like." % name) # TODO: Is converting to list needed or would checking be enough? # TODO: Check this and DotDict usage below in RF 3.1. return list(value) if identifier == '&': if not is_dict_like(value): raise VariableError("Value of variable '%s' is not dictionary " "or dictionary-like." % name) # TODO: Is converting to DotDict needed? Check in RF 3.1. return DotDict(value) return value
def _take_copy_of_mutable_value(self, value): if is_dict_like(value): return dict(value) if is_list_like(value): return list(value) return value
def _extra_arg_has_kwargs(self, positional, named): if named or len(positional) != self._maxargs + 1: return False return is_dict_like(positional[-1])
def _dot_dict(self, value): if is_dict_like(value): value = DotDict((n, self._dot_dict(v)) for n, v in value.items()) return value
def _get_list_index_name_mapping(self, names, list_length): if not names: return {} if is_dict_like(names): return dict((int(index), names[index]) for index in names) return dict(zip(range(list_length), names))