def put_method(self, match_obj): sbst = substitutor.Substitutor() rlock = threading.RLock() time.sleep(sbst.getSleepTime()) with rlock: sbst.put(match_obj.group(1), match_obj.group(2)) self.wfile.write('OK'.encode())
def get_method(self, match_obj): sbst = substitutor.Substitutor() time.sleep(sbst.getSleepTime()) self.wfile.write('VALUE\n'.encode()) try: self.wfile.write(sbst.get(match_obj.group(1), None).encode()) except substitutor.InfiniteRecursionException: self.wfile.write('ERROR: Infinite recursion'.encode())
def run(verbose): # Validate integrity of data cache. relation_checker_utility.check(verbose) # Ask the user for input and substitute it into one simplified equation simplifiedequation = substitutor.Substitutor().finalEquation print("You provided the following equation: ") print(simplifiedequation) # Ask how many runs numruns = int(input("How many problems would you like for this equation?")) # Generate and display output. print("Original Equation:") print(simplifiedequation) print() print("Presenting " + str(numruns) + " word problems.") print() generator = testing.EnglishProblemGenerator(simplifiedequation) for run in range(numruns): print(str(run + 1) + ". " + generator.generate_problem_for_equation())
def test_replacement(self): sbst = substitutor.Substitutor() sbst.put("k1", "one") sbst.put("k2", "two") sbst.put("keys", "1: ${k1}, 2: ${k2}") self.assertEquals("1: one, 2: two", sbst.get("keys"))
def test_emptyReplacement(self): sbst = substitutor.Substitutor() sbst.put("k", "bla-${inexistent}-bla") self.assertEquals("bla--bla", sbst.get("k"))
def set_sleep_method(self, match_obj): sbst = substitutor.Substitutor() rlock = threading.RLock() with rlock: sbst.setSleepTime(int(match_obj.group(1))) self.wfile.write('OK'.encode())