DefTree API¶
Element¶
-
class
deftree.
Element
(name)¶ Element class. This class defines the Element interface
-
append
(item)¶ Inserts the item at the end of this element’s internal list of children. Raises TypeError if item is not a
Element
orAttribute
-
attributes
([name, value])¶ Creates a tree iterator with the current element as the root. The iterator iterates over this element. Only
Attributes
. Name and value are optional and used for filters
-
clear
()¶ Resets an element. This function removes all children, clears all attributes
-
elements
([name])¶ Creates a tree iterator with the current element as the root. The iterator iterates over this element and all elements below it, in document (depth first) order. Only
Element
whose name equals name are returned from the iterator
-
get_attribute
(name[, value])¶ Returns the first
Attribute
instance whose name matches name and if value is not None whose value equal value. If none is found it returns None.
-
get_element
(name)¶ Returns the first
Element
whose name matches name, if none is found returns None.
-
index
(item)¶ Returns the index of the item in this element, raises ValueError if not found.
-
insert
(index, item)¶ Inserts the item at the given position in this element. Raises TypeError if item is not a
Element
orAttribute
-
iter
()¶ Creates a tree iterator with the current element as the root. The iterator iterates over this element and all elements below it, in document (depth first) order. Both
Element
andAttribute
are returned from the iterator.
-
iter_elements
(name[, value])¶ Creates a tree iterator with the current element as the root. The iterator iterates over this element and all elements below it, in document (depth first) order. Only
Element
are returned from the iterator.
-
Attribute¶
DefTree¶
-
class
deftree.
DefTree
¶ DefTree class. This class represents an entire element hierarchy.
-
dump
()¶ Write the the DefTree structure to sys.stdout. This function should be used for debugging only.
-
from_string
(text[, parser])¶ Parses a Defold document section from a string constant which it returns. parser is an optional parser instance. If not given the standard parser is used. Returns the root of
DefTree
.
-
get_document_path
()¶ Returns the path to the parsed document.
-
parse
(source[, parser])¶ Parses a Defold document into a
DefTree
which it returns. source is a file_path. parser is an optional parser instance. If not given the standard parser is used.
-
write
(file_path)¶ Writes the element tree to a file, as plain text. file_path needs to be a path.
-
Helpers¶
-
deftree.
parse
(source)¶ Parses a Defold document into a DefTree which it returns. source is a file_path. parser is an optional parser instance. If not given the standard parser is used.
-
deftree.
from_string
(text[, parser])¶ Parses a Defold document section from a string constant which it returns. parser is an optional parser instance. If not given the standard parser is used. Returns the root of
DefTree
.
-
deftree.
to_string
(element[, parser])¶ Generates a string representation of the Element, including all children. element is a
Element
instance.
-
deftree.
dump
(element[, parser])¶ Write element tree or element structure to sys.stdout. This function should be used for debugging only. element is either an
DefTree
, orElement
.
-
deftree.
validate
(string, path_or_string[, verbose])¶ Verifies that a document in string format equals a document in path_or_string. If Verbose is True it echoes the result. This function should be used for debugging only. Returns a bool representing the result