From a15e01bcfa49ddf89fad842648973fd259164116 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Thu, 11 Feb 2016 05:33:01 -0800 Subject: [PATCH] Fix parsing of Python scripts which use variable Booleans. Some of Cyan's old scripts predate Python supporting Booleans, which leaves us with variables where we expected constant values. This change intercepts these cases and replaces them, avoiding an exception in Korman when it tries to shove one of these strings into a boolean attribute. Also included is a new visitor for proper name constants, support for which was added in Python 3.4. This will allow future scripts to use them and be recognized correctly. --- korman/plasma_attributes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/korman/plasma_attributes.py b/korman/plasma_attributes.py index 9cf651c..a3cd415 100644 --- a/korman/plasma_attributes.py +++ b/korman/plasma_attributes.py @@ -65,6 +65,10 @@ class PlasmaAttributeVisitor(ast.NodeVisitor): return self.generic_visit(node) def visit_Name(self, node): + # Workaround for old Cyan scripts: replace variables named "true" or "false" + # with the respective constant values True or False. + if node.id.lower() in {"true", "false"}: + return ast.literal_eval(node.id.capitalize()) return(node.id) def visit_Num(self, node): @@ -85,6 +89,9 @@ class PlasmaAttributeVisitor(ast.NodeVisitor): elts.append(self.visit(x)) return tuple(elts) + def visit_NameConstant(self, node): + return(node.value) + def generic_visit(self, node): ast.NodeVisitor.generic_visit(self, node)