silo.low_code_steps.standard.selector module

class silo.low_code_steps.standard.selector.JMESPathParser

Bases: object

bad_action_arg_msg = "Action_argument 'index=true' was set; however, the result of the query did not yield _index and _value keys in its result. Please provide the step with a similar formatted value path: \n                jmespath:\n                index: true\n                value: path.to[].{ _index: index.path , _value: value.path }\n            "
get_paths(action_arg, context_logger)

Turns the given action argument into a JMESPathString type

Transform a action argument (arg derived from snippet arg) and turns it into the index and a value jmespath string. Provides argument checking.

Parameters
  • action_arg (dict) – step parameters provided by the snippet argument

  • context_logger (logger) – Logger for the step

Returns

index boolean, value str

Return type

JMESPathString()

Raises

ValueError – Raised if an invalid argument was given

static handle_merge_for_list_of_dicts(value_matches)

Handles merging JMESPath matches contained in an iterable

Parameters

value_matches (dict) – JMESPath matches

Returns

merged index value pairs

Return type

dict

static merge_index_matches_to_dict(value_matches)

Merges index and value JMESPath Expressions into key-value pairs

When a multiselect hash expression is used, a list of matches will be used to form key/value pairs which are then able to be turned into a dictionary. The simplest case is when the full path of the index and value match: path.to[n].{ _index: index_item, _value: value_item }

In this case, we know that the index and value are 1:1 and we can create the following dict entry:

d[index] = value

The more complicated cases are some varient of a sub-entry: path.to[n].sub.value and path.to[n].index Here, we see that path.to[n].sub != path.to[n] Thus, we remove additional levels on the value path to see if we can find a match. In this case, we do:

path.to[n].{ _index: index, _value: sub.value }
Parameters

value_matches (any) – result of a JMESPath multiselect hash search

Returns

Key-Value pairs of index and value expression results

Return type

dict or None

class silo.low_code_steps.standard.selector.JSONPathParser

Bases: object

format_parsed_values(match)
Takes matched values and extracts the values from it. If there is only one value in the

matched results, return just that object, not a list.

Parameters

match (list) – List of DataumInContext values

Returns

The value from the matched items

Return type

list

get_paths(action_arg, context_logger)

Turns action argument into index and value jsonpath strings.

Takes the action argument (arg derived from snippet arg) and turns it into

the index and value jsonpath strings. This is a helper to break down the function

Parameters
  • action_arg (str) – The jsonpath string provided by the snippet

  • context_logger (logger) – Logger for the step

Returns

index JSONPath, value JSONPath

Return type

JpathString()

Raises

ValueError – Raised if an invalid argument was given

merge_index_matches_to_dict(value_matches, index_matches)
If two jpaths were used, you get two lists of matches that can be used as key/value

pairs which are then able to be turned in to our tuples. The simplest case is when the full path of the index and value basically match: path.to[n].value and path.to[n].index

In this case, we knowt hat they are the same: path.to[n] == path.to[n] in this case, we can take the value and index and create the dict entry: d[index] = value

The more complicated cases are some varient of a sub-entry: path.to[n].sub.value and path.to[n].index Here, we see that path.to[n].sub != path.to[n] Thus, we remove additional levels on the value path to see if we can find a match. In this case, we do: path.to[n] = path.to[n]

To make it to the output dictionary, there must be a match between the value path and the index path as described here.

The items in the lists must, at a minimum, have a .value property and a .full_path property

:param list value_matches:DatumInContext matches for the values :param list index_matches:DatumInContext matches for the indexes (used in the tuples)

Returns

Keys are the index’s value and values are the collection value

Return type

dict

parse_jpath(jpath, cache=None)

Takes the jsonpath given and compiles it into a jsonpath object that you can use

Parameters
  • jpath (str) – The jsonpath expression to be compiled

  • cache (dict) – (Optional) A dictionary to prevent running the compilation more than once. Compiling jsonpath is surprisingly expensive.

Returns

A parser object that wil match for the jsonpath expression given

Return type

callable

parse_payload(jpath, payload, cache=None)

Takes a jpath expression and a decoded json payload and returns the data from jsonpath_ng

The cache dictionary is used to prevent needing to re-compile jsonpath’s which is a very expensive operation.

Parameters
  • jpath (str) – A valid jpath expression

  • payload (object) – Generally a Dictionary with decoded json payload

  • cache (dict) – (Optional) Dictionary-compatible cache object of compiled parsers, indexed by the jsonpath.

Returns

jsonpath_ng.DatumInContext objects (they have .value and .fullpath attributes)

Return type

list

remove_trailing_suffix(path, separator='.', count=1)
Given something that is path-like, remove the trailing parts. For example, given

this.is.it, return this.is

Parameters
  • path (str) – The string to remove the tail of

  • separator (str) – (Optional) The separator to remove the end of (defaults to .)

  • count (int) – (Optional) How many trailing parts to remove)

Returns

String with the trailing parts that have been removed

Return type

str

Raises

ValueError – If you gave an invalid type for e.g. path

silo.low_code_steps.standard.selector.simple_key(result, action_arg)

For dicts, lists, etc, return the keys specified with periods separating.

For example: Path.to.value.

silo.low_code_steps.standard.selector.store_data(action_arg, result_container)