Browse Source

Merge pull request #29 from Deledrius/NameConstant_fixes

Fix parsing of Python scripts which use variable Booleans.
pull/30/head
Adam Johnson 9 years ago
parent
commit
2883289e06
  1. 13
      korman/plasma_attributes.py

13
korman/plasma_attributes.py

@ -65,13 +65,17 @@ class PlasmaAttributeVisitor(ast.NodeVisitor):
return self.generic_visit(node) return self.generic_visit(node)
def visit_Name(self, node): def visit_Name(self, node):
return(node.id) # 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): def visit_Num(self, node):
return(node.n) return node.n
def visit_Str(self, node): def visit_Str(self, node):
return(node.s) return node.s
def visit_List(self, node): def visit_List(self, node):
elts = [] elts = []
@ -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