Finished 'step' and 'answer' request handlers.

parent 5ae33360
...@@ -37,11 +37,13 @@ class Step(object): ...@@ -37,11 +37,13 @@ class Step(object):
response = parser.run([last_line]) response = parser.run([last_line])
if response: if response:
response = response.rewrite(include_step=True, response = parser.rewrite(include_step=True,
check_implicit=True) check_implicit=True)
if response: if response:
return json.dumps({'step': str(response)}) hint, step = response
return json.dumps({'step': str(step),
'hint': str(hint)})
return json.dumps({'hint': 'No further reduction is possible.'}) return json.dumps({'hint': 'No further reduction is possible.'})
except Exception as e: except Exception as e:
...@@ -60,12 +62,15 @@ class Answer(object): ...@@ -60,12 +62,15 @@ class Answer(object):
response = parser.run([last_line]) response = parser.run([last_line])
if response: if response:
steps = response.rewrite_all(include_step=True) steps = parser.rewrite_all(include_steps=True)
if steps: if steps:
hints, steps = zip(*steps) out = []
return json.dumps({'hints': map(str, hints),
'steps': map(str, steps)}) for h, s in steps:
out.append(dict(hint=str(h), step=str(s)))
return json.dumps({'steps': out})
return json.dumps({'hint': 'No further reduction is possible.'}) return json.dumps({'hint': 'No further reduction is possible.'})
except Exception as e: except Exception as e:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment