inxs.lib module

This module contains common functions that can be used for either Rule s’ tests, as handler functions or simple transformation steps.

Community contributions are highly appreciated, but it’s hard to layout hard criteria for what belongs here and what not. In doubt open a pull request with your proposal as far as it proved functional to you, it doesn’t need to be polished at that point.

inxs.lib.add_html_classes[source]

Adds the string tokens passed as positional arguments to the classes attribute of a node specified by target. An argument can also be a sequence of strings or a Ref() that yields on of the two. Per default that is a Ref() to the matching node of a rule.

inxs.lib.append[source]

Appends the object referenced by symbol (default: the result of the previous handler function) to the object available as name in the Transformation._available_symbols. If the object is a delb.TagNode instance and copy_node is True, a copy that includes all descendant nodes is appended to the target.

inxs.lib.cleanup_namespaces(root: delb.nodes.TagNode, previous_result: Any) → Any[source]

Cleanup the namespaces of the tree. This should always be used at the end of a transformation when nodes’ namespaces have been changed.

inxs.lib.clear_attributes(node: delb.nodes.TagNode, previous_result: Any) → Any[source]

Deletes all attributes of an node.

inxs.lib.concatenate[source]

Concatenate the given parts which may be lists or strings as well as callables returning such.

inxs.lib.debug_dump_document[source]

Dumps all contents of the node referenced by name from the inxs.Transformation._available_symbols to the log at info level.

inxs.lib.debug_message[source]

Logs the provided message at info level.

inxs.lib.debug_symbols[source]

Logs the representation strings of the objects referenced by names in inxs.Transformation._available_symbols at info level.

inxs.lib.f(func, *args, **kwargs)[source]

Wraps the callable func which will be called as func(*args, **kwargs), the function and any argument can be given as inxs.Ref().

inxs.lib.get_attribute[source]

Gets the value of the node’s attribute named name.

inxs.lib.get_localname(node)[source]

Gets the node’s local tag name.

inxs.lib.get_text(node: delb.nodes.TagNode)[source]

Returns the content of the matched node’s descendants of delb.TextNode type.

inxs.lib.get_variable[source]

Gets the object referenced as name from the context. It is then available as symbol previous_result.

inxs.lib.has_attributes(node: delb.nodes.TagNode, _)[source]

Returns True if the node has attributes.

inxs.lib.has_children(node: delb.nodes.TagNode, _)[source]

Returns True if the node has descendants.

inxs.lib.has_matching_text[source]

Returns True if the text contained by the node and its descendants has a matches the provided pattern.

inxs.lib.has_text(node: delb.nodes.TagNode, _)[source]

Returns True if the node has any delb.TextNode.

inxs.lib.insert_fontawesome_icon[source]

Inserts the html markup for an icon from the fontawesome set with the given name at position of which only after is implemented atm.

It employs semantics for Font Awesome 5.

inxs.lib.join_to_string[source]

Joins the object referenced by symbol around the given separator and returns it.

inxs.lib.lowercase(previous_result)[source]

Processes previous_result to be all lower case.

inxs.lib.make_node(**node_args)[source]

Creates a new tag node in the root node’s context, takes the arguments of delb.TagNode.new_tag_node() that must be provided as keyword arguments. The node is then available as symbol previous_result.

inxs.lib.pop_attribute[source]

Pops the node’s attribute named name.

inxs.lib.pop_attributes[source]

Pops all attributes with name from names and returns a mapping with names and values. When ignore_missing is True KeyError exceptions pass silently.

inxs.lib.prefix_attributes(prefix: str, *attributes)[source]

Prefixes the attributes with prefix.

inxs.lib.put_variable[source]

Puts value``as ``name to the context namespace, by default the value is determined by a inxs.Ref() to previous_result.

inxs.lib.remove_attributes[source]

Removes all attributes with the keys provided as names from the node.

inxs.lib.remove_namespace(node: delb.nodes.TagNode, previous_result)[source]

Removes the namespace from the node. When used, cleanup_namespaces() should be applied at the end of the transformation.

inxs.lib.remove_node(node: delb.nodes.TagNode)[source]

A very simple handler that just removes a node and its descendants from a tree.

inxs.lib.remove_nodes[source]

Removes all nodes from their tree that are referenced in a list that is available as references. The nodes’ children are retained when keep_children is passed as True, or only the contained text when preserve_text is passed as True. The reference list is cleared afterwards if clear_ref is True.

inxs.lib.rename_attributes(translation_map: Mapping[str, str]) → Callable[source]

Renames the attributes of a node according to the provided translation_map that consists of old name keys and new name values.

inxs.lib.resolve_xpath_to_node[source]

Resolves the objects from the context namespace (which are supposed to be XPath expressions) referenced by names with the one node that the expression matches or None. This is useful when a copied tree is processed and ‘XPath pointers’ are passed to the context when a inxs.Transformation is called.

inxs.lib.set_attribute[source]

Sets an attribute name with value.

inxs.lib.set_localname[source]

Sets the node’s localname to name.

inxs.lib.set_text[source]

Sets the nodes’s first child node that is of delb.TextNode type to the one provided as text, it can also be a inxs.Ref(). If the first node isn’t a text node, one will be inserted.

inxs.lib.sort[source]

Sorts the object referenced by name in the context using key as key function.

inxs.lib.text_equals[source]

Tests whether the evaluated node’s text contained by its descendants is equal to text.