Get Parser

Classe TgParser parses the radios response to the get RPC.

Class Information:

class tgtools.parsers.status.tgparser.TgParser(xml: str, prefix_tokens: dict[str, str] = None)

A parser for the XML response of the ‘get’ RPC (or any valid XML part thereof). The XML string is converted to an lxml.etree, which is then parsed by the following high-level sections: interfaces, inventory, ipv4, common_node, common_sectors, common_links, dn_node, dn_sectors, dn_links, system, user_bridge.

Each high-level section is tokenised into a list of dictionaries, where the keys of each dictionary comprise some fixed prefix data_tokens, and the more informative data_tokens (specific for each section). The values corresponding to each key (token) is derived from the input XML. The list for each section is pointed-to by the mapping TgParser.parsed. The data_tokens (keys for each dictionary) are pointed to by the mapping TgParser.data_tokens. For example:

  • TgParser.parsed[‘interfaces’] is a list of dictionaries, each describing one of the individual interface under this section, using certain data_tokens and their respective values.

  • TgParser.data_tokens[‘interfaces’] is a list of these data_tokens.

Some high-level sections are combined to offer a more concise view:
  • radio-dn/node and radio-common/node are combined in section node,

  • radio-dn/sectors and radio-common/sectors are combined in section sectors,

  • radio-dn/links and radio-common/links are combined in section links.

__init__(xml: str, prefix_tokens: dict[str, str] = None)
Parameters:
  • xml (str) – an XML string to be parsed.

  • prefix_tokens (dict[str, str]) – an optional dictionary with fixed data_tokens that are prefixed for all output dictionaries. Typical keys are ‘route’ (denoting how a radio was accessed), and ‘timestamp’ (the time at which the XML was obtained from the radio).

combine_tokens(section_out: str, section_in1: str, section_in2: str, token: str = '') list[dict]

Combines data_tokens of two different sections. If token is provided, then elements from the two sections are matched based on the value of that token. Otherwise, matching is in order (i-th element in section_in1 combined with i-th element in section_in2).

Parameters:
  • section_out (str) – Name of the new output (combined) section.

  • section_in1 (str) – Name of the first section (of the two) to combine.

  • section_in2 (str) – Name of the second section (of the two) to combine.

  • token (str) – an optional token for pair-matching elements from section_in1 and section_in2.

Returns:

List of dictionaries, each dictionary includes data_tokens combined from both section_in1 and section_in2.

Return type:

list[dict]

tokenise()

Executes all the different tokenise_… methods corresponding to each high-level section. Then use TgParser.combine_tokens() to combine some sections together for a more comprehensive view.

Tokenise the radio_common/links section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

tokenise_common_node() list[dict]

Tokenise the radio_common/node-config section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

tokenise_common_sectors() list[dict]

Tokenise the radio_common/sectors-config section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

Tokenise the radio_dn/links/configured section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

tokenise_dn_node() list[dict]

Tokenise the radio_dn/node-config section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

tokenise_dn_sectors() list[dict]

Tokenise the radio_dn/sectors-config section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

tokenise_interfaces() list[dict]

Tokenise the interface section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

tokenise_inventory() list[dict]

Tokenise the inventory section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

tokenise_ipv4() list[dict]

Tokenise the ip/ipv4 section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

tokenise_system() list[dict]

Tokenise the system section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

tokenise_user_bridge() list[dict]

Tokenise the radio_common/links section of the input XML.

Updates TgParser.parsed and TgParser.data_tokens.

Returns:

List of dictionaries, each representing (in data_tokens) elements of this section.

Return type:

list[dict]

errors: list[Err]

A list of error messages, each represented as tg.utils.errlog.Err.

local: str

The name of the radio (as derived from the system section)

parsed: dict[str, list]

The main output of this class: a mapping from each section name to a list of dictionaries, where each dictionary comprises some data_tokens.

remote_cns: list[str]

A list of all connected remote CNs (as derived from the radio-dn/links section).

tokens: dict[str, list]

A mapping from each section name to a list of its respective data_tokens.

xml: str

The XML input (argument specified when instantiating this class).

xml_etree: Element

The lxml.etree representation of xml