Add __str__ and __repr__ to String/Attribute/Tag/Root Nodes, fixes #3863
This commit is contained in:
parent
1e00ff83b4
commit
96a030805a
1 changed files with 28 additions and 0 deletions
|
@ -94,6 +94,13 @@ class StringNode:
|
|||
else:
|
||||
return "'%s'" % self.data.decode("utf8", "ignore")
|
||||
|
||||
def __str__(self):
|
||||
return "StringNode({})".format(self.debug())
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
|
||||
|
||||
class AttributeNode:
|
||||
"""
|
||||
A WML attribute. For example the "id=Elfish Archer" in:
|
||||
|
@ -145,6 +152,13 @@ class AttributeNode:
|
|||
def get_name(self):
|
||||
return self.name.decode("utf8")
|
||||
|
||||
def __str__(self):
|
||||
return "AttributeNode({})".format(self.debug())
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
|
||||
|
||||
class TagNode:
|
||||
"""
|
||||
A WML tag. For example the "unit" in this example:
|
||||
|
@ -274,6 +288,13 @@ class TagNode:
|
|||
def get_name(self):
|
||||
return self.name.decode("utf8")
|
||||
|
||||
def __str__(self):
|
||||
return "TagNode({})".format(self.get_name())
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
|
||||
|
||||
class RootNode(TagNode):
|
||||
"""
|
||||
The root node. There is exactly one such node.
|
||||
|
@ -288,6 +309,13 @@ class RootNode(TagNode):
|
|||
s += subline + "\n"
|
||||
return s
|
||||
|
||||
def __str__(self):
|
||||
return "RootNode()"
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
|
||||
|
||||
class Parser:
|
||||
def __init__(self, wesnoth_exe = None, config_dir = None,
|
||||
data_dir = None):
|
||||
|
|
Loading…
Add table
Reference in a new issue