#!/usr/bin/env python
+import re
import weakref
-import warnings
-from libraries.recipes import algorithms
+from util import algorithms
import operation
}
+_VARIABLE_VALIDATION_RE = re.compile("^[a-zA-Z0-9]+$")
+
+
+def validate_variable_name(variableName):
+ match = _VARIABLE_VALIDATION_RE.match(variableName)
+ if match is None:
+ raise RuntimeError("Invalid characters in '%s'" % variableName)
+
+
def parse_number(userInput):
try:
base = __BASE_MAPPINGS.get(userInput[0:2], 10)
def __init__(self, history, entry, errorReporting, constants, operations):
self.history = history
+ self.history._parse_value = self._parse_value
self.__entry = weakref.ref(entry)
self.__errorReporter = errorReporting
self.__entry().clear()
def push_entry(self):
- """
- @todo Add operation duplication. If value is empty, peek at the top
- item. If it has children, grab the last one, push it and reapply the
- operation. If there are no children then just duplicate the item
- """
-
value = self.__entry().get_value()
valueNode = None
except KeyError:
pass
+ validate_variable_name(userInput)
return operation.Variable(userInput)
def _apply_operation(self, Node):