Enable the character() function in the template debugger

This commit is contained in:
Charles Haley 2021-04-23 21:57:39 +01:00
parent 2a6a773f8a
commit 76dde80604

View File

@ -250,7 +250,7 @@ class PrintNode(Node):
class CharacterNode(Node): class CharacterNode(Node):
def __init__(self, line_number, expression): def __init__(self, line_number, expression):
Node.__init__(self, line_number, 'character') Node.__init__(self, line_number, 'character()')
self.node_type = self.NODE_CHARACTER self.node_type = self.NODE_CHARACTER
self.expression = expression self.expression = expression
@ -1076,11 +1076,16 @@ class _Interpreter(object):
'backslash': '\\', 'backslash': '\\',
} }
def do_node_character(self, prog): def do_node_character(self, prog):
key = self.expr(prog.expression) try:
ret = self.characters.get(key, None) key = self.expr(prog.expression)
if ret is None: ret = self.characters.get(key, None)
self.error(_("Function {0}: invalid character name '{1}") if ret is None:
.format('character', key), prog.line_number) self.error(_("Function {0}: invalid character name '{1}")
.format('character', key), prog.line_number)
if (self.break_reporter):
self.break_reporter(prog.node_name, ret, prog.line_number)
except (StopException, ValueError) as e:
raise e
return ret return ret
def do_node_print(self, prog): def do_node_print(self, prog):