Skip to content

Commit

Permalink
Add __str__ and __repr__ to String/Attribute/Tag/Root Nodes, fixes #3863
Browse files Browse the repository at this point in the history
  • Loading branch information
ProditorMagnus authored and Vultraz committed Jan 18, 2019
1 parent 05ab79f commit 3380c18
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions data/tools/wesnoth/wmlparser3.py
Expand Up @@ -94,6 +94,13 @@ def debug(self):
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:
Expand Down Expand Up @@ -145,6 +152,13 @@ def get_binary(self):
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:
Expand Down Expand Up @@ -274,6 +288,13 @@ def append(self, node):
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.
Expand All @@ -288,6 +309,13 @@ def debug(self):
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):
Expand Down

0 comments on commit 3380c18

Please sign in to comment.