[pypy-svn] r42055 - pypy/extradoc/talk/rupy2007/demos

fijal at codespeak.net fijal at codespeak.net
Sat Apr 14 18:38:47 CEST 2007


Author: fijal
Date: Sat Apr 14 18:38:47 2007
New Revision: 42055

Added:
   pypy/extradoc/talk/rupy2007/demos/serv.py
   pypy/extradoc/talk/rupy2007/demos/test_serv.py
   pypy/extradoc/talk/rupy2007/demos/thunk.py
Log:
Add some demos


Added: pypy/extradoc/talk/rupy2007/demos/serv.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/rupy2007/demos/serv.py	Sat Apr 14 18:38:47 2007
@@ -0,0 +1,44 @@
+from subprocess import Popen, PIPE
+
+from pypy.translator.js.lib import server
+from pypy.translator.js.lib.support import js_source, callback
+from pypy.translator.js.modules import dom
+
+HTML = """<html><head>
+<script src="stuff.js"></script>
+</head><body onload="start()">
+  <p id="s">Stuff</p>
+</body></html>"""
+
+def onupdate(msg):
+    dom.document.getElementById("s").innerHTML = msg
+    dom.setTimeout(start, 1000)
+
+def start():
+    exported_methods.update(onupdate)
+
+class ExportedMethods(server.ExportedMethods):
+    @callback(retval=str)
+    def update(self):
+        p = Popen('uptime', stdout=PIPE)
+        p.wait()
+        return p.stdout.read()
+
+exported_methods = ExportedMethods()
+
+class App(server.Collection):
+    exported_methods = exported_methods
+    def index(self):
+        return HTML
+    index.exposed = True
+
+    def stuff_js(self):
+        return "text/javascript", js_source([start])
+    stuff_js.exposed = True
+
+class Handler(server.NewHandler):
+    application = App()
+
+if __name__ == '__main__':
+    httpd = server.create_server(handler=Handler, server_address=('', 7010))
+    httpd.serve_forever()

Added: pypy/extradoc/talk/rupy2007/demos/test_serv.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/rupy2007/demos/test_serv.py	Sat Apr 14 18:38:47 2007
@@ -0,0 +1,12 @@
+
+from pypy.translator.js import tester
+from pypy.translator.js.modules import dom
+from serv import HTML, start, exported_methods
+
+def test_js():
+    dom.window = dom.Window(HTML)
+    dom.document = dom.window.document
+    start()
+    tester.schedule_callbacks(exported_methods)
+    print dom.document.getElementById("s").innerHTML
+    assert "Stuff" not in dom.document.getElementById("s").innerHTML

Added: pypy/extradoc/talk/rupy2007/demos/thunk.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/rupy2007/demos/thunk.py	Sat Apr 14 18:38:47 2007
@@ -0,0 +1,6 @@
+from __pypy__ import thunk
+def f():
+    print 'computing...'
+    return 6*7
+
+x = thunk(f)



More information about the Pypy-commit mailing list