[pypy-svn] r40976 - in pypy/dist/pypy/translator/js/examples/console: . test
fijal at codespeak.net
fijal at codespeak.net
Wed Mar 21 21:50:19 CET 2007
Author: fijal
Date: Wed Mar 21 21:50:18 2007
New Revision: 40976
Modified:
pypy/dist/pypy/translator/js/examples/console/client.py
pypy/dist/pypy/translator/js/examples/console/console.py
pypy/dist/pypy/translator/js/examples/console/session.py
pypy/dist/pypy/translator/js/examples/console/test/test_session.py
Log:
Improve console a bit. Unfortunately huge amount of logic which I've written
didn't make it's way here, because it was completely useless.
Modified: pypy/dist/pypy/translator/js/examples/console/client.py
==============================================================================
--- pypy/dist/pypy/translator/js/examples/console/client.py (original)
+++ pypy/dist/pypy/translator/js/examples/console/client.py Wed Mar 21 21:50:18 2007
@@ -30,6 +30,7 @@
#inp_elem.disabled = False
if msg[0] == "refresh":
inp_elem.scrollIntoView()
+ inp_elem.focus()
data = msg[1]
exported_methods.refresh_empty(glob.sess_id, refresh_console)
add_text(data)
@@ -63,11 +64,14 @@
def nothing(msg):
pass
+def nothing2(msg):
+ pass
+
def cleanup_console():
inp_elem = dom.document.getElementById("inp")
inp_elem.disabled = True
set_text("")
- exported_methods.kill_console(glob.sess_id, nothing)
+ exported_methods.kill_console(glob.sess_id, nothing2)
def load_console(python="python"):
if glob.console_running:
@@ -80,6 +84,13 @@
glob.console_running = True
exported_methods.get_console(python, set_sessid)
+def add_snippet(snippet):
+ add_text(snippet)
+ exported_methods.refresh(glob.sess_id, snippet, refresh_console)
+
+def execute_snippet(number=3):
+ exported_methods.execute_snippet(number, add_snippet)
+
def console_onload():
#createLoggingPane(True)
#inp_elem = dom.document.getElementById("inp")
Modified: pypy/dist/pypy/translator/js/examples/console/console.py
==============================================================================
--- pypy/dist/pypy/translator/js/examples/console/console.py (original)
+++ pypy/dist/pypy/translator/js/examples/console/console.py Wed Mar 21 21:50:18 2007
@@ -14,7 +14,17 @@
commproxy.USE_MOCHIKIT = True
-FUNCTION_LIST = ["load_console", "console_onload"]
+SNIPPETS = [
+ """from tputil import make_instance_proxy
+history = []
+def recorder(invocation):
+ history.append(invocation)
+ return invocation.perform()
+
+l = make_instance_proxy([], recorder)
+"""]
+
+FUNCTION_LIST = ["load_console", "console_onload", "execute_snippet"]
HELP = {'python':"just Python, play as you like :)",
'pypy-c':
'''
@@ -28,9 +38,11 @@
<li><b>Transparent proxy</b> - This is a unique PyPy interpreter feature,
which allows you to provide application-level controller for any kind of
object. Details and snippets can be found in the
- <a href="http://codespeak.net/pypy/dist/pypy/doc/objspace-proxies.html#tproxy">transparent proxy documentation</a>.</li>
+ <a href="http://codespeak.net/pypy/dist/pypy/doc/objspace-proxies.html#tproxy">transparent proxy documentation</a>. Example (<a href="javascript:execute_snippet(0)">execute</a>):
+ <pre>%s</pre>
+ </li>
</ul>
-''',
+''' % (SNIPPETS[0],),
'pypy-c-thunk':'''The PyPy standard interpreter compiled to C using
the <a href="http://codespeak.net/pypy/dist/pypy/doc/objspace-proxies.html#the-thunk-object-space">thunk object space</a>''',
'pypy-c-taint':'''The PyPy standard interpreter compiled to C using
@@ -99,7 +111,7 @@
sessions = Sessions()
class ExportedMethods(server.ExportedMethods):
- @callback(args=[str], retval=[str])
+ @callback(retval=[str])
def get_console(self, python="python"):
retval = sessions.new_session(python)
return [str(retval), HELP[python]]
@@ -124,6 +136,10 @@
except Ignore:
return ["ignore"]
+ @callback(retval=str)
+ def execute_snippet(self, number=3):
+ return SNIPPETS[int(number)]
+
@callback()
def kill_console(self, pid=0):
sessions.kill_session(int(pid))
Modified: pypy/dist/pypy/translator/js/examples/console/session.py
==============================================================================
--- pypy/dist/pypy/translator/js/examples/console/session.py (original)
+++ pypy/dist/pypy/translator/js/examples/console/session.py Wed Mar 21 21:50:18 2007
@@ -37,12 +37,11 @@
return data
def write_only(self, to_write):
- if to_write:
+ if to_write is not None:
self.pipe.stdin.write(to_write)
def interact(self, to_write=None):
- if to_write is not None:
- self.pipe.stdin.write(to_write)
+ self.write_only(to_write)
return self.timeout_read(self.read_fd, self.timeout)
def close(self):
Modified: pypy/dist/pypy/translator/js/examples/console/test/test_session.py
==============================================================================
--- pypy/dist/pypy/translator/js/examples/console/test/test_session.py (original)
+++ pypy/dist/pypy/translator/js/examples/console/test/test_session.py Wed Mar 21 21:50:18 2007
@@ -31,3 +31,15 @@
one, two = allof(g, f)
assert two.startswith(">>")
assert one.startswith("Traceback")
+
+def test_multiline_command():
+ i = Interpreter("python", timeout=3)
+ while not i.interact().endswith(">>> "):
+ pass
+ val = i.interact("def f(x):\n y = x + 3\n return y\n\nf(8)\n")
+ while val is not None:
+ assert 'Traceback' not in val
+ assert 'Syntax' not in val
+ print val
+ val = i.interact()
+
More information about the Pypy-commit
mailing list