geneva.actions.tree

Defines an action tree. Action trees are comprised of a trigger and a tree of actions.

exception tree.ActionTreeParseError

Bases: Exception

Exception thrown when an action tree is malformed or cannot be parsed.

class tree.ActionTree(direction, trigger=None)

Bases: object

Defines an ActionTree for the Geneva system.

__init__(direction, trigger=None)

Creates this action tree.

Parameters:
  • direction (str) – Direction this tree is facing (“out”, “in”)
  • trigger (actions.trigger.Trigger) – Trigger to use with this tree
add_action(new_action)

Adds an action to this action tree.

check(packet, logger)

Checks if this action tree should run on this packet.

choose_one()

Picks a random element in the tree.

contains(action)

Checks if an action is contained in the tree.

count_leaves()

Counts the number of leaves.

do_parse(node, string, logger)

Handles the preorder recursive parsing.

do_run(node, packet, logger)

Handles recursively running a packet down the tree.

get_parent(node)

Returns the parent of the given node and direction of the child.

get_rand_action(direction, request=None, allow_terminal=True, disabled=None)

Retrieves and initializes a random action that can run in the given direction.

get_slots()

Returns the number of locations a new action could be added.

initialize(num_actions, environment_id, allow_terminal=True, disabled=None)

Sets up this action tree with a given number of random actions. Note that the returned action trees may have less actions than num_actions if terminal actions are used.

mate(other_tree)

Mates this tree with another tree.

mutate()

Mutates this action tree with respect to a given direction.

parse(string, logger)

Parses a string representation of an action tree into this object.

preorder(node)

Yields a preorder traversal of the tree.

pretty_print(visual=False)

Pretty prints the tree.

pretty_print_help(root, visual=False, parent=None)
Pretty prints the tree.
  • root is the highest-level node you wish to start printing
  • [visual] controls whether a png should be created, by default, this is false.
  • [parent] is an optional parameter specifying the parent of a given node, should only be used by this function.

Returns the root with its children as an anytree node.

remove_action(action)

Removes a given action from the tree.

remove_one()

Removes a random leaf from the tree.

run(packet, logger)

Runs a packet through the action tree.

string_repr(node)

Yields a preorder traversal of the tree to create a string representation.

swap(my_donation, other_tree, other_donation)

Swaps a node in this tree with a node in another tree.