summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-05-07 19:18:55 +0000
committerianb <devnull@localhost>2005-05-07 19:18:55 +0000
commite9dfa19430b660ef063b2a42947ecf97c766d44a (patch)
tree2e9dec669b0afaea009e6424297db2387708e3ed /examples
parent76fcfe11f5268dffd0b3f2aae256e3f8e83a8ed3 (diff)
downloadpaste-e9dfa19430b660ef063b2a42947ecf97c766d44a.tar.gz
Use urllib instead of jsonrpc
Diffstat (limited to 'examples')
-rw-r--r--examples/console/web/index.py25
-rw-r--r--examples/console/web/static/command.js21
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">&gt;&gt;&gt; '
+ 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() {