Browse Source

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.
pull/29/head
Joseph Davies 9 years ago
parent
commit
a15e01bcfa
  1. 7
      korman/plasma_attributes.py

7
korman/plasma_attributes.py

@ -65,6 +65,10 @@ class PlasmaAttributeVisitor(ast.NodeVisitor):
return self.generic_visit(node) return self.generic_visit(node)
def visit_Name(self, 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) return(node.id)
def visit_Num(self, node): def visit_Num(self, node):
@ -85,6 +89,9 @@ class PlasmaAttributeVisitor(ast.NodeVisitor):
elts.append(self.visit(x)) elts.append(self.visit(x))
return tuple(elts) return tuple(elts)
def visit_NameConstant(self, node):
return(node.value)
def generic_visit(self, node): def generic_visit(self, node):
ast.NodeVisitor.generic_visit(self, node) ast.NodeVisitor.generic_visit(self, node)

Loading…
Cancel
Save