[pypy-svn] r41369 - in pypy/dist/pypy/translator/js/examples: . console console/data data
fijal at codespeak.net
fijal at codespeak.net
Mon Mar 26 16:40:09 CEST 2007
Author: fijal
Date: Mon Mar 26 16:40:07 2007
New Revision: 41369
Added:
pypy/dist/pypy/translator/js/examples/data/error.html
pypy/dist/pypy/translator/js/examples/data/py-web1.png (contents, props changed)
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/data/index.html
pypy/dist/pypy/translator/js/examples/data/style.css
pypy/dist/pypy/translator/js/examples/overmind.py
Log:
Play1 revisited
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 Mon Mar 26 16:40:07 2007
@@ -6,10 +6,13 @@
class Glob(object):
def __init__(self):
self.console_running = False
+ self.next_console = ""
+ self.text_to_show = []
+ self.pss = []
glob = Glob()
-def add_text(txt):
+def add_text_to_dom(txt):
data_elem = dom.document.getElementById("data")
if data_elem.childNodes:
data = data_elem.childNodes[0].nodeValue + txt
@@ -19,6 +22,26 @@
data_elem.removeChild(data_elem.childNodes[0])
data_elem.appendChild(dom.document.createTextNode(data))
+
+def add_text(txt, server_flag, fn=add_text_to_dom):
+ if not server_flag:
+ if txt.find("\n") != len(txt) - 1:
+ if txt[-1] == '\n':
+ txt = txt[:-1]
+ lst = txt.split("\n")
+ add_text_to_dom(lst[0] + "\n")
+ glob.text_to_show += lst[1:]
+ else:
+ add_text_to_dom(txt)
+ else:
+ for ps in glob.pss:
+ if txt.startswith(ps) and glob.text_to_show:
+ txt = txt[len(ps):]
+ add_text_to_dom(ps + glob.text_to_show.pop(0) + "\n")
+ add_text(txt, True)
+ return
+ add_text_to_dom(txt)
+
def create_text(txt):
return dom.document.createTextNode(txt)
@@ -37,7 +60,7 @@
inp_elem.scrollIntoView()
inp_elem.focus()
exported_methods.refresh_empty(glob.sess_id, refresh_console)
- add_text(data)
+ add_text(data, True)
elif msg[0] == 'disconnected':
inp_elem.disabled = True
name_bar = dom.document.getElementById("namebar")
@@ -45,10 +68,16 @@
text = name_bar.lastChild.nodeValue
name_bar.removeChild(name_bar.lastChild)
name_bar.appendChild(create_text(text + " [DEFUNCT]"))
+ glob.console_running = False
+ if glob.next_console:
+ next = glob.next_console
+ glob.next_console = ""
+ load_console(next)
def set_sessid(data):
sessid = int(data[0])
help_msg = data[1]
+ glob.pss = data[2:]
glob.sess_id = sessid
inp_elem = dom.document.getElementById("inp")
inp_elem.disabled = False
@@ -70,7 +99,7 @@
inp_elem = dom.document.getElementById("inp")
cmd = inp_elem.value
inp_elem.value = ''
- add_text(cmd + "\n")
+ add_text(cmd + "\n", False)
#if not cmd:
# exported_methods.refresh(glob.sess_id, cmd, empty_callback)
#else:
@@ -91,6 +120,8 @@
def load_console(python="python"):
if glob.console_running:
cleanup_console()
+ glob.next_console = python
+ return
inp_elem = dom.document.getElementById("inp")
main = dom.document.getElementById("main")
main.style.visibility = "visible"
@@ -100,7 +131,7 @@
exported_methods.get_console(python, set_sessid)
def add_snippet(snippet):
- add_text(snippet)
+ add_text(snippet, False)
exported_methods.refresh(glob.sess_id, snippet, refresh_console)
def execute_snippet(name='python', number=3):
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 Mon Mar 26 16:40:07 2007
@@ -12,6 +12,7 @@
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
+from py.__.green.greensock2 import ConnexionClosed
commproxy.USE_MOCHIKIT = True
@@ -25,6 +26,8 @@
return rpython2javascript(client, FUNCTION_LIST)
def line_split(ret, max_len):
+ return ret
+ # XXX borken
to_ret = []
for line in ret.split("\n"):
if len(line) > max_len:
@@ -42,7 +45,7 @@
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']
+CONSOLES = ['python', 'pypy-c', 'pypy-c-thunk', 'pypy-c-taint', 'pypy-cli', 'pyrolog-c', 'pypy-c-jit']
class Sessions(object):
def __init__(self):
@@ -77,6 +80,15 @@
del self.sessions[pid]
del self.updating[pid]
+ def get_ps(self, python):
+ if python == 'python':
+ return ['>>> ', '... ']
+ if python.startswith('pypy'):
+ return ['>>>> ', '.... ']
+ if python == 'pyrolog-c':
+ return ['>?-']
+ return []
+
# We hack here, cause in exposed methods we don't have global 'server'
# state
sessions = Sessions()
@@ -85,31 +97,29 @@
@callback(retval=[str])
def get_console(self, python="python"):
retval = sessions.new_session(python)
- return [str(retval), sessions.docloader.get_html(python)]
+ return [str(retval), sessions.docloader.get_html(python)] +\
+ sessions.get_ps(python)
- @callback(retval=[str])
- def refresh(self, pid=0, to_write=""):
- #print "Refresh %s %d" % (to_write, int(pid))
+ def _refresh(self, pid, to_write):
try:
return ["refresh", sessions.update_session(int(pid), to_write)]
- except (KeyError, IOError, Killed):
+ except (KeyError, IOError, Killed, ConnexionClosed):
return ["disconnected"]
except Ignore:
- return ["ignore"]
+ return ["ignore"]
+
+ @callback(retval=[str])
+ def refresh(self, pid=0, to_write=""):
+ return self._refresh(pid, to_write)
@callback(retval=[str])
def refresh_empty(self, pid=0):
#print "Empty refresh %d" % int(pid)
- try:
- return ["refresh", sessions.update_session(int(pid), None)]
- except (KeyError, IOError, Killed):
- return ["disconnected"]
- except Ignore:
- return ["ignore"]
+ return self._refresh(pid, None)
@callback(retval=str)
def execute_snippet(self, name='aaa', number=3):
- return sessions.docloader.get_snippet(name, int(number))
+ return sessions.docloader.get_snippet(name, int(number)) + "\n"
@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 Mon Mar 26 16:40:07 2007
@@ -1,13 +1,13 @@
<html>
<head>
<script type="text/javascript" src="source.js"></script>
- <script src="MochiKit/MochiKit.js" type="text/javascript"></script>
+ <script src="http://mochikit.com/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>
</head>
<body onload="console_onload()">
- <a><img alt="PyPy" height="110" id="pyimg" src="http://codespeak.net/pypy/img/py-web1.png" width="149"/></a>
+ <a id="mainlink" href="http://codespeak.net/pypy/"><img alt="PyPy" height="110" id="pyimg" src="/py_web1.png" width="149"/></a>
<div id="metaspace">
<h1 class="title">PyPy[consoles]</h1>
<div class="menubar">
@@ -20,6 +20,7 @@
<li><a href="javascript:load_console('pypy-c')">pypy-c with stackless and transparent proxy</a></li>
<li><a href="javascript:load_console('pypy-c-thunk')">pypy-c with thunk objspace</a></li>
<li><a href="javascript:load_console('pypy-c-taint')">pypy-c with taint objspace</a></li>
+ <li><a href="javascript:load_console('pypy-c-jit')">pypy-c with jit</a></li>
<li><a href="javascript:load_console('pypy-cli')">pypy-cli</a></li>
<li><a href="javascript:load_console('pyrolog-c')">pyrolog-c</a></li>
<li><b><a href="javascript:cleanup_console()">kill console</a></b></li>
Added: pypy/dist/pypy/translator/js/examples/data/error.html
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js/examples/data/error.html Mon Mar 26 16:40:07 2007
@@ -0,0 +1,19 @@
+<html>
+<head>
+ <title>%(message)s</title>
+</head>
+<body>
+ <link href="style.css" media="screen" rel="stylesheet" type="text/css"/>
+</body>
+ <a href="http://codespeak.net/pypy/"><img alt="PyPy" height="110" id="pyimg" src="py_web1.png" width="149"/></a>
+ <div id="metaspace">
+ <h1 class="title">PyPy[error]</h1>
+ <div class="menubar">
+ <a href="console">Python consoles</a> - <a href="http://play1.codespeak.net:8058/">ANSI terminal</a> - <a href="/bnb">Bub'n'Bros JavaScript version</a>
+ </div>
+ </div>
+ <div id="main">
+ <h3 class="error">%(message)s</h3>
+ <p>%(explain)s</p>
+ </div>
+</html>
Modified: pypy/dist/pypy/translator/js/examples/data/index.html
==============================================================================
--- pypy/dist/pypy/translator/js/examples/data/index.html (original)
+++ pypy/dist/pypy/translator/js/examples/data/index.html Mon Mar 26 16:40:07 2007
@@ -5,7 +5,7 @@
<link href="style.css" media="screen" rel="stylesheet" type="text/css"/>
</head>
<body>
- <a><img alt="PyPy" height="110" id="pyimg" src="http://codespeak.net/pypy/img/py-web1.png" width="149"/></a>
+ <a id="mainlink" href="http://codespeak.net/pypy/"><img alt="PyPy" height="110" id="pyimg" src="py_web1.png" width="149"/></a>
<div id="metaspace">
<h1 class="title">PyPy[js]</h1>
Added: pypy/dist/pypy/translator/js/examples/data/py-web1.png
==============================================================================
Binary file. No diff available.
Modified: pypy/dist/pypy/translator/js/examples/data/style.css
==============================================================================
--- pypy/dist/pypy/translator/js/examples/data/style.css (original)
+++ pypy/dist/pypy/translator/js/examples/data/style.css Mon Mar 26 16:40:07 2007
@@ -48,4 +48,9 @@
}
.main {
-}
\ No newline at end of file
+}
+
+.error {
+ color: red;
+ font-weight: bold;
+}
Modified: pypy/dist/pypy/translator/js/examples/overmind.py
==============================================================================
--- pypy/dist/pypy/translator/js/examples/overmind.py (original)
+++ pypy/dist/pypy/translator/js/examples/overmind.py Mon Mar 26 16:40:07 2007
@@ -11,6 +11,7 @@
from pypy.rpython.ootypesystem.bltregistry import described
from pypy.translator.js.main import rpython2javascript
from pypy.translator.js.examples.console import console
+from py.__.green.server.httpserver import GreenHTTPServer
import os
import py
@@ -23,12 +24,16 @@
import over_client
return rpython2javascript(over_client, FUNCTION_LIST)
+static_dir = py.path.local(__file__).dirpath().join("data")
+
class Root(server.Collection):
- static_dir = py.path.local(__file__).dirpath().join("data")
index = server.FsFile(static_dir.join("index.html"))
- style_css = server.FsFile(static_dir.join("style.css"))
+ style_css = server.FsFile(static_dir.join("style.css"),
+ content_type="text/css")
terminal = server.Static(static_dir.join("terminal.html"))
console = console.Root()
+ py_web1_png = server.FsFile(static_dir.join("py-web1.png"),
+ content_type="image/png")
def source_js(self):
if hasattr(self.server, 'source'):
@@ -52,12 +57,13 @@
class Handler(server.NewHandler):
application = Root()
+
+ error_message_format = static_dir.join('error.html').read()
#console = server.Static(os.path.join(static_dir, "launcher.html"))
if __name__ == '__main__':
try:
addr = ('', 8008)
- from py.__.green.server.httpserver import GreenHTTPServer
httpd = server.create_server(server_address=addr, handler=Handler,
server=GreenHTTPServer)
httpd.serve_forever()
More information about the Pypy-commit
mailing list