From a15e01bcfa49ddf89fad842648973fd259164116 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Thu, 11 Feb 2016 05:33:01 -0800 Subject: [PATCH 1/2] 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) From b350f0b67bfc14d835597a65707d51cb67ffa58c Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Thu, 11 Feb 2016 19:28:35 -0800 Subject: [PATCH 2/2] Use return statement consistently. --- korman/plasma_attributes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/korman/plasma_attributes.py b/korman/plasma_attributes.py index a3cd415..478aedf 100644 --- a/korman/plasma_attributes.py +++ b/korman/plasma_attributes.py @@ -69,13 +69,13 @@ class PlasmaAttributeVisitor(ast.NodeVisitor): # 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) + return node.id def visit_Num(self, node): - return(node.n) + return node.n def visit_Str(self, node): - return(node.s) + return node.s def visit_List(self, node): elts = [] @@ -90,7 +90,7 @@ class PlasmaAttributeVisitor(ast.NodeVisitor): return tuple(elts) def visit_NameConstant(self, node): - return(node.value) + return node.value def generic_visit(self, node): ast.NodeVisitor.generic_visit(self, node)