3. Appliers: argonodes.appliers

Appliers are functions or objects passed as parameters to a Node to allow modifications, additions, or exploration on the data of the Node, and/or its children.

The idea is identical to that of the Visitor pattern. There are two types of Appliers: Appliers that add/modify existing attributes in the Node, and Appliers that extract attributes from the Node. These Appliers are respectively functions and objects.

Basic usage: tree.apply(applier)

class argonodes.appliers.DistinctValues(sort='count', reverse=None)

Bases: object

Standalone Applier to check all distinct values for Nodes.

It is possible to sort the values by frequency or by path, in ascending or descending order. Once applied, this Applier keeps in memory the repetitions of values and children for the targeted Nodes. It is possible to retrieve them either with self.data, or with dedicated functions for more granularity.

Parameters
  • sort (str, either key or count.) – How to sort the gathered values.

  • reverse (bool, default None.) – Whether to reverse the sorting order or not.

property data: dict

Raw data. Immutable.

Returns

Raw data.

Return type

dict

get_found_values() dict

Return the values only.

Returns

A dictionary with the paths and the corresponding values.

Return type

dict

get_recurring_values(threshold=2) dict

Return the values only, filtered on a given threshold.

Parameters

threshold (int, default 2.) – How many times the value should occur to be considered as “recurring”.

Returns

A dictionary with the paths and the corresponding values, filtered on a given threshold.

Return type

dict

sort(sort, reverse=None) None

Change the sorting order.

Parameters
  • sort (str, either key or count.) – How to sort the gathered values.

  • reverse (bool, default None.) – Whether to reverse the sorting order or not.

to_list() list

Return a flattened version of data.

Returns

A flattened version of data.

Return type

list

class argonodes.appliers.FoundRegex

Bases: object

This standalone Applier will try to find a matching regex for each targeted Node.

It will try to find a uniquely matching regex for each targeted Node, based on the recurring values of that one. A failure to do so will result in a list of potential regex that may cover all the found cases. It is possible to retrieve them with self.data.

Note that this Applier makes use of another Applier, DistinctValues.

Warning, it uses an external package that you should install first: pip install tdda.

property data: dict

Raw data. Immutable.

Returns

Raw data.

Return type

dict

argonodes.appliers.ignore_node(node, rec=False, paths=None) None

Marks every targeted Node as “ignored” - subsequent functions shall take that into account for further actions (e.g., export).

Parameters
  • node (Node) – A given Node, usually a Tree.

  • rec (bool, default True.) – If True, the function shall be applied on all children.

  • paths (List[str] or str.) – What are the targeted paths.

argonodes.appliers.make_traversal(node, rec=True) None

Create the base traversal of a Node, usually a Tree.

Parameters
  • node (Node) – A given Node, usually a Tree.

  • rec (bool, default True.) – Must be True.