def escape_paths(paths, prefix=default_prefix): return [ prefix + ParameterKeyEscaper.escape(path[len(prefix) :]) if path.startswith(prefix) else path for path in paths ]
def escape_paths(paths, prefix=default_prefix): escaped_paths = [] for path in paths: if path == prefix: raise errors.bad_request.ValidationError("invalid task field", path=path) escaped_paths.append(prefix + ParameterKeyEscaper.escape(path[len(prefix):]) if path.startswith(prefix) else path) return escaped_paths
def unprepare_from_saved(call: APICall, tasks_data: Union[Sequence[dict], dict]): if isinstance(tasks_data, dict): tasks_data = [tasks_data] conform_output_tags(call, tasks_data) for task_data in tasks_data: parameters = safe_get(task_data, "execution/parameters") if parameters is not None: # Escape keys to make them mongo-safe parameters = { ParameterKeyEscaper.unescape(k): v for k, v in parameters.items() } dpath.set(task_data, "execution/parameters", parameters)
def prepare_for_save(call: APICall, fields: dict): conform_tag_fields(call, fields) # Strip all script fields (remove leading and trailing whitespace chars) to avoid unusable names and paths for field in task_script_fields: try: path = f"script/{field}" value = dpath.get(fields, path) if isinstance(value, str): value = value.strip() dpath.set(fields, path, value) except KeyError: pass parameters = safe_get(fields, "execution/parameters") if parameters is not None: # Escape keys to make them mongo-safe parameters = {ParameterKeyEscaper.escape(k): v for k, v in parameters.items()} dpath.set(fields, "execution/parameters", parameters) return fields