diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/console/web/index.py | 25 | ||||
| -rw-r--r-- | examples/console/web/static/command.js | 21 |
2 files changed, 43 insertions, 3 deletions
diff --git a/examples/console/web/index.py b/examples/console/web/index.py index aec3498..571a9f1 100644 --- a/examples/console/web/index.py +++ b/examples/console/web/index.py @@ -1,6 +1,7 @@ from console.sitepage import SitePage from console.JSONComponent import JSONComponent from console.evalcontext import EvalContext +import time context = EvalContext() @@ -9,13 +10,35 @@ class index(SitePage): components = SitePage.components + [ JSONComponent(baseConfig='console')] + def awake(self, trans): + self.t1 = time.time() + SitePage.awake(self, trans) + def setup(self): self.options.title = 'Console' def jsonMethods(self): return ['run'] + + def actions(self): + return ['postrun'] def run(self, expr): + self.t2 = time.time() + if not expr.endswith('\n'): + expr += '\n' + result = context.exec_expr(expr) + self.t3 = time.time() + timing = '%s - %s\n%s' % ( + self.t2 - self.t1, self.t3 - self.t2, result) + return timing + + def postrun(self): + self.response().setHeader('content-type', 'text/plain') + expr = self.request().field('command', '') if not expr.endswith('\n'): expr += '\n' - return context.exec_expr(expr) + result = context.exec_expr(expr) + print [expr, result] + self.write(result) + diff --git a/examples/console/web/static/command.js b/examples/console/web/static/command.js index d5c7aa9..50146e2 100644 --- a/examples/console/web/static/command.js +++ b/examples/console/web/static/command.js @@ -1,5 +1,16 @@ output_html = '' +urllib = importModule('urllib'); + +function servlet_comm(s) { + urllib.sendRequest('post', + '?_action_=postrun', + 'command=' + escape(s, true), + [['Content-type', 'application/x-www-form-urlencoded']], + add_response); +} + + function send_command() { var command_short = document.getElementById('command'); var command_long = document.getElementById('command_long'); @@ -12,15 +23,21 @@ function send_command() { } command_short.value = ''; command_long.value = ''; - var result = servlet.run(command); output_html += '<span class="input">>>> ' + html_quote(command) + '</span>\n'; + servlet_comm(command); + return false; +} + +function add_response(res) { + var result = res.responseText; + var command_short = document.getElementById('command'); if (result != null) { output_html += '<span class="output">' + html_quote(result) + '<span>\n'; } refresh_display(); - return false; + command_short.focus(); } function refresh_display() { |
