Android Manifest Visitor

Simple module to parse Android Manifest files or XML files in general.

Use this package to react to specific XML nodes or their defined node attributes. Besides the default Android XML nodes, user-defined nodes can be visited as well.

The following example illustrates how to use a single AXmlVisitor to print out the application’s name and all activities:

 1from mastf.android import axml
 2
 3visitor = axml.AndroidManifestVisitor()
 4
 5@visitor.manifest("android:name")
 6def visit_name(element, name: str):
 7    print("Application Name:", name)
 8
 9@visitor.activity("android:name")
10def visit_activity(element, name: str):
11    print("Found activity:", name)
12
13visitor.visit_document(xml)
class mastf.android.axml._AXmlElement(name: str)[source]

Internal class used to store handlers mapped to a specific attribute or node.

Note that this class acts as a method decorator and should be used on methods that take the following arguments:

  • element: The current minidom element

  • value: The attribute’s value or None if a node will be visited

  • *args, **kwargs: Additional arguments provided within the do_visit function of an AXmlVisitor

Example:

>>> visitor = AXmlVisitor()
# type(manifest) := _AXmlElement
>>> @visitor.manifest("android:name")
... def visit_name(element, value):
...     pass
add(key: str, handler)[source]

Adds a new handler to the given attribute or node name.

This method call is equivalent to:

obj["key"] = value
Parameters:
  • key (str) – attribute or node name

  • handler (Callable[None, [Element, str, *args]]) – callback function

class mastf.android.axml.AXmlVisitorBase(name, bases, attrs: dict, **kwargs)[source]

Base class for XMLVisitor classes.

This class can be used on any declaring class that should store handler elements.

>>> class MyVisitorClass(AXmlVisitor):
...     class Meta:
...         nodes = [ 'manifest', 'uses-permission' ]

The example above includes two XML attributes which can be called:

>>> obj = MyVisitorClass()
>>> @obj.manifest("android:name")
... def visit_manifest_name(element, value: str):
...     pass
class mastf.android.axml.AXmlVisitor[source]

Implementation of a visitor-based XML reader.

end = <AXmlElement name=[None]>

Stores handlers than would be called after the attributes of an element should be visited.

start = <AXmlElement name=[None]>

Stores handlers than would be called before the attributes of an element should be visited.

visit_document(document: Document, *args, **kwargs)[source]

Reads the incoming document or parses a given buffer/string.

Parameters:

document (minidom.Document | str | bytes) – the document to read

visit_element(element: Element)[source]

Visits a single XML element.

Parameters:

element (minidom.Element) – the element to read