[pypy-svn] r38625 - in pypy/dist/pypy/translator/js/examples: . data
fijal at codespeak.net
fijal at codespeak.net
Mon Feb 12 19:08:01 CET 2007
Author: fijal
Date: Mon Feb 12 19:07:59 2007
New Revision: 38625
Added:
pypy/dist/pypy/translator/js/examples/data/
pypy/dist/pypy/translator/js/examples/data/index.html
pypy/dist/pypy/translator/js/examples/over_client.py
pypy/dist/pypy/translator/js/examples/overmind.py (contents, props changed)
Modified:
pypy/dist/pypy/translator/js/examples/pythonconsole.py
Log:
A (very preliminary) version of main script to be run on play1,
this is intermediate checkin, needs further tweaks
Added: pypy/dist/pypy/translator/js/examples/data/index.html
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js/examples/data/index.html Mon Feb 12 19:07:59 2007
@@ -0,0 +1,19 @@
+<html>
+<head>
+ <title>pypy.js various demos</title>
+ <script src="source.js"></script>
+</head>
+<body>
+ <h2 align="center">This site presents various demos and tutorials about pypy.js</h2>
+ <h3>Python console:</h3>
+ <p>No more, no less
+ <a href="javascript:launch_console()">Launch one for me</a>
+ <a href="source_link_here">Source</a>
+ </p>
+ <h3>Remote terminal:</h3>
+ <p>Fully ANSI-complaint remote terminal session:
+ <a href="javascript:launch_terminal()">Launch one for me</a>
+ <a href="source_link_here">Source</a>
+ </p>
+</body>
+</html>
Added: pypy/dist/pypy/translator/js/examples/over_client.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js/examples/over_client.py Mon Feb 12 19:07:59 2007
@@ -0,0 +1,12 @@
+
+""" Client side of overmind.py
+"""
+
+from pypy.translator.js.examples.overmind import exported_methods
+from pypy.translator.js.modules import dom
+
+def callback(arg):
+ dom.window.location = "http://localhost:%d" % arg
+
+def launch_console():
+ exported_methods.launch_console(callback)
Added: pypy/dist/pypy/translator/js/examples/overmind.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js/examples/overmind.py Mon Feb 12 19:07:59 2007
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+""" This is script which collects all the demos and
+run them when needed
+"""
+
+from pypy.translator.js.lib import server
+from pypy.translator.js.lib.support import callback
+from pypy.rpython.extfunc import _callable
+from pypy.rpython.ootypesystem.bltregistry import described
+from pypy.translator.js.main import rpython2javascript
+
+import os
+import py
+
+FUNCTION_LIST = ['launch_console']
+tempdir = py.test.ensuretemp("infos")
+TIMEOUT = 100
+
+def launch_console_in_new_process():
+ from pypy.translator.js.examples import pythonconsole
+ httpd = server.start_server(server_address=('', 0),
+ handler=pythonconsole.RequestHandler, timeout=TIMEOUT,
+ port_file=tempdir.join("console_pid"),
+ fork=True, server=pythonconsole.Server)
+ pythonconsole.httpd = httpd
+ port = int(tempdir.join("console_pid").read())
+ return port
+
+class ExportedMethods(server.ExportedMethods):
+ @callback(retval=int)
+ def launch_console(self):
+ """ Note that we rely here on threads not being invoked,
+ if we want to make this multiplayer, we need additional locking
+ XXX
+ """
+ return launch_console_in_new_process()
+
+exported_methods = ExportedMethods()
+
+def js_source(function_list):
+ import over_client
+ return rpython2javascript(over_client, FUNCTION_LIST)
+
+class Handler(server.Handler):
+ static_dir = str(py.path.local(__file__).dirpath().join("data"))
+ index = server.Static()
+ exported_methods = exported_methods
+
+ def source_js(self):
+ if hasattr(self.server, 'source'):
+ source = self.server.source
+ else:
+ source = js_source(FUNCTION_LIST)
+ self.server.source = source
+ return "text/javascript", source
+ source_js.exposed = True
+
+if __name__ == '__main__':
+ server.start_server(handler=Handler)
Modified: pypy/dist/pypy/translator/js/examples/pythonconsole.py
==============================================================================
--- pypy/dist/pypy/translator/js/examples/pythonconsole.py (original)
+++ pypy/dist/pypy/translator/js/examples/pythonconsole.py Mon Feb 12 19:07:59 2007
@@ -18,11 +18,13 @@
from pypy.rpython.extfunc import _callable
from pypy.translator.js.demo.jsdemo import support
+from pypy.translator.js.lib import server
commproxy.USE_MOCHIKIT = True
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from SocketServer import ThreadingMixIn
+import time
HTML_PAGE = """
<html>
@@ -141,6 +143,7 @@
def run_some_callback(self, cmd=[""]):
cmd = cmd[0]
+ self.server.last_activity = time.time()
if cmd:
buf = cStringIO.StringIO()
out1 = sys.stdout
@@ -181,8 +184,8 @@
httpd = Server(server_address, RequestHandler)
print 'http://127.0.0.1:%d' % (server_address[1],)
-def _main():
- build_http_server()
+def _main(address=('', 8001)):
+ build_http_server(server_address=address)
httpd.serve_forever()
if __name__ == '__main__':
More information about the Pypy-commit
mailing list