[pypy-svn] r41226 - in pypy/dist/pypy/translator/js/examples/console: . data test
fijal at codespeak.net
fijal at codespeak.net
Sat Mar 24 10:52:27 CET 2007
Author: fijal
Date: Sat Mar 24 10:52:25 2007
New Revision: 41226
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/data/console.html
pypy/dist/pypy/translator/js/examples/console/docloader.py
pypy/dist/pypy/translator/js/examples/console/test/test_docloader.py
Log:
Minor improvements to the console demo, use doc files instead of inlined ones.
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 Sat Mar 24 10:52:25 2007
@@ -50,6 +50,12 @@
sessid = int(data[0])
help_msg = data[1]
glob.sess_id = sessid
+ inp_elem = dom.document.getElementById("inp")
+ inp_elem.disabled = False
+ name_bar = dom.document.getElementById("namebar")
+ name_bar.style.color = "black"
+ name_bar.removeChild(name_bar.lastChild)
+ name_bar.appendChild(create_text("Python console"))
dom.document.getElementById("helpcontents").innerHTML = help_msg
exported_methods.refresh_empty(sessid, refresh_console)
@@ -97,8 +103,8 @@
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 execute_snippet(name='python', number=3):
+ exported_methods.execute_snippet(name, number, add_snippet)
def console_onload():
#createLoggingPane(True)
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 Sat Mar 24 10:52:25 2007
@@ -10,61 +10,12 @@
from pypy.translator.js.lib.support import callback
from pypy.translator.js import commproxy
from pypy.translator.js.examples.console.session import Interpreter, Killed
+from pypy.translator.js.examples.console.docloader import DocLoader
from py.__.green.server.httpserver import GreenHTTPServer
commproxy.USE_MOCHIKIT = True
-SNIPPETS = [
- """from tputil import make_proxy
-history = []
-def recorder(operation):
- history.append(operation)
- return operation.delegate()
-
-l = make_proxy(recorder, obj=[])
-""",
- """from __pypy__ import thunk
-def f():
- print 'computing...'
- return 6*7
-
-x = thunk(f)
-""",
- """from __pypy__ import taint
-x = taint(6)
-"""]
-
FUNCTION_LIST = ["load_console", "console_onload", "execute_snippet"]
-HELP = {'python':"just Python, play as you like :)",
- 'pypy-c':
-'''
-This is the PyPy standard interpreter translated to C with the following features:
-<ul>
- <li><b>Stackless</b> - You can use all stackless features including
- tasklets, channels, coroutines and greenlets, more information and some
- examples can be found in the
- <a href="http://codespeak.net/pypy/dist/pypy/doc/stackless.html">PyPy stackless documentation</a>.
- </li>
- <li><b>Transparent proxy</b> - This is a unique PyPy interpreter feature,
- which allows you to provide an 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>. 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>. Example (<a href="javascript:execute_snippet(1)">execute</a>):
- <pre>%s</pre>
- And try <i>x</i>.
-''' % (SNIPPETS[1],),
- 'pypy-c-taint':'''The PyPy standard interpreter compiled to C using
- the <a href="http://codespeak.net/pypy/dist/pypy/doc/objspace-proxies.html#the-taint-object-space">taint object space</a>. Example (<a href="javascript:execute_snippet(2)">execute</a>):
- <pre>%s</pre>
- Now try hard getting to value of <i>x</i> :-)
- ''' % (SNIPPETS[2],),
- 'pypy-cli':'''The PyPy standard interpreter compiled to CLI''',
- 'pyrolog-c':'''The Prolog interpreter compiled to C'''}
class Ignore(Exception):
pass
@@ -90,11 +41,14 @@
for x in range(6):
STATIC_DIR = STATIC_DIR.dirpath()
STATIC_DIR = STATIC_DIR.join("compiled")
+DOCDIR = STATIC_DIR.dirpath().join("pypy", "doc", "play1")
+CONSOLES = ['pypy-c', 'pypy-c-thunk', 'pypy-c-taint', 'pypy-cli', 'pyrolog-c']
class Sessions(object):
def __init__(self):
self.sessions = {}
self.updating = {}
+ self.docloader = DocLoader(docdir=DOCDIR, consoles=CONSOLES)
def new_session(self, python="python"):
if not py.path.local().sysfind(python):
@@ -131,7 +85,7 @@
@callback(retval=[str])
def get_console(self, python="python"):
retval = sessions.new_session(python)
- return [str(retval), HELP[python]]
+ return [str(retval), sessions.docloader.get_html(python)]
@callback(retval=[str])
def refresh(self, pid=0, to_write=""):
@@ -154,8 +108,8 @@
return ["ignore"]
@callback(retval=str)
- def execute_snippet(self, number=3):
- return SNIPPETS[int(number)]
+ def execute_snippet(self, name='aaa', number=3):
+ return sessions.docloader.get_snippet(name, int(number))
@callback()
def kill_console(self, pid=0):
Modified: pypy/dist/pypy/translator/js/examples/console/data/console.html
==============================================================================
--- pypy/dist/pypy/translator/js/examples/console/data/console.html (original)
+++ pypy/dist/pypy/translator/js/examples/console/data/console.html Sat Mar 24 10:52:25 2007
@@ -1,7 +1,7 @@
<html>
<head>
<script type="text/javascript" src="source.js"></script>
- <script src="http://mochikit.com/MochiKit/MochiKit.js" type="text/javascript"></script>
+ <script src="MochiKit/MochiKit.js" type="text/javascript"></script>
<script src="source.js"></script>
<link href="style.css" media="screen" rel="stylesheet" type="text/css"/>
<title>Console</title>
Modified: pypy/dist/pypy/translator/js/examples/console/docloader.py
==============================================================================
--- pypy/dist/pypy/translator/js/examples/console/docloader.py (original)
+++ pypy/dist/pypy/translator/js/examples/console/docloader.py Sat Mar 24 10:52:25 2007
@@ -5,7 +5,7 @@
import py
-class LoadDoc(object):
+class DocLoader(object):
def __init__(self, consoles, docdir, testfile='test_snippets.py'):
self.consoles = consoles
self.docdir = py.path.local(docdir)
Modified: pypy/dist/pypy/translator/js/examples/console/test/test_docloader.py
==============================================================================
--- pypy/dist/pypy/translator/js/examples/console/test/test_docloader.py (original)
+++ pypy/dist/pypy/translator/js/examples/console/test/test_docloader.py Sat Mar 24 10:52:25 2007
@@ -1,16 +1,16 @@
import py
from pypy.tool.udir import udir
-from pypy.translator.js.examples.console.docloader import LoadDoc
+from pypy.translator.js.examples.console.docloader import DocLoader
def test_load_html():
tmpdir = udir.ensure("docloader", dir=1)
help = tmpdir.ensure("one.html").write("<a href='dupa'>%s</a>")
- code = tmpdir.ensure("test_snippets.py").write(str(py.code.Source('''
+ code = tmpdir.ensure("test_snippets2.py").write(str(py.code.Source('''
class AppTest_one(object):
def test_snippet_1(self):
x = 1
''')) + '\n')
- ld = LoadDoc(docdir=tmpdir, consoles=['one'])
+ ld = DocLoader(docdir=tmpdir, consoles=['one'], testfile='test_snippets2.py')
assert ld.get_html('one') == "<a href='dupa'>x = 1</a>"
assert ld.get_snippet('one', 0) == 'x = 1'
More information about the Pypy-commit
mailing list