From fijal at codespeak.net Mon Jan 1 11:51:11 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 11:51:11 +0100 (CET) Subject: [pypy-svn] r36084 - pypy/dist/pypy/doc/js Message-ID: <20070101105111.6C6351007E@code0.codespeak.net> Author: fijal Date: Mon Jan 1 11:51:09 2007 New Revision: 36084 Modified: pypy/dist/pypy/doc/js/webapps_with_pypy.txt Log: * Added important sentence (what is rpython) * Reworded CPython/Python Modified: pypy/dist/pypy/doc/js/webapps_with_pypy.txt ============================================================================== --- pypy/dist/pypy/doc/js/webapps_with_pypy.txt (original) +++ pypy/dist/pypy/doc/js/webapps_with_pypy.txt Mon Jan 1 11:51:09 2007 @@ -26,7 +26,9 @@ JavaScript code. Unlike other libraries that perform similar functionality, PyPy really interprets the code, and produces 'lower level' JavaScript code, so it implements Python core language features like list comprehensions, and -really behaves like Python (it's not Python syntax with JS semantics). +really behaves like Python (it's not Python syntax with JS semantics). +This particulary means that when a program is in RPython, you can run it +on top of Python interpreter with the same results as translated to JS version. However, mostly for demonstration purposes, some other interesting code is available in the PyPy code package that may help developing web apps. The most @@ -52,7 +54,7 @@ A quick overview of the (main) layers of code in the application we're going to write: - * HTTP server implementation - 'normal' (C-)Python code + * HTTP server implementation - 'normal' Python code the web server code, the code that handles dealing with the HTTP API and dispatching to application code is written in 'normal' Python code, and is From fijal at codespeak.net Mon Jan 1 11:55:42 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 11:55:42 +0100 (CET) Subject: [pypy-svn] r36085 - pypy/dist/pypy/doc/js Message-ID: <20070101105542.73B061007E@code0.codespeak.net> Author: fijal Date: Mon Jan 1 11:55:40 2007 New Revision: 36085 Modified: pypy/dist/pypy/doc/js/webapps_with_pypy.txt Log: Added link. Modified: pypy/dist/pypy/doc/js/webapps_with_pypy.txt ============================================================================== --- pypy/dist/pypy/doc/js/webapps_with_pypy.txt (original) +++ pypy/dist/pypy/doc/js/webapps_with_pypy.txt Mon Jan 1 11:55:40 2007 @@ -7,7 +7,7 @@ PyPy is a platform that is very versatile, and provides almost endless possibilities. One of the features that is currently already available is -that of translating RPython (the 'restricted Python' subset) to JavaScript. +that of translating `RPython`_ (the 'restricted Python' subset) to JavaScript. This specific feature can make the life of a developer of web applications that use client-side logic a lot easier, although there are certain hurdles to take. @@ -89,3 +89,4 @@ XXX hands-on guide to writing guestbook or something +.. _`RPython`: ../coding-guide.html#restricted-python \ No newline at end of file From fijal at codespeak.net Mon Jan 1 11:58:26 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 11:58:26 +0100 (CET) Subject: [pypy-svn] r36086 - pypy/dist/pypy/lib/distributed/test Message-ID: <20070101105826.190B21007E@code0.codespeak.net> Author: fijal Date: Mon Jan 1 11:58:24 2007 New Revision: 36086 Added: pypy/dist/pypy/lib/distributed/test/ Log: Added test directory From fijal at codespeak.net Mon Jan 1 11:59:04 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 11:59:04 +0100 (CET) Subject: [pypy-svn] r36087 - in pypy/dist/pypy/lib: distributed/test test2 Message-ID: <20070101105904.D5C7A1007E@code0.codespeak.net> Author: fijal Date: Mon Jan 1 11:59:03 2007 New Revision: 36087 Added: pypy/dist/pypy/lib/distributed/test/test_distributed.py - copied unchanged from r36076, pypy/dist/pypy/lib/test2/test_distributed.py Removed: pypy/dist/pypy/lib/test2/test_distributed.py Log: Moved tests from deprecated directory From fijal at codespeak.net Mon Jan 1 12:51:53 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 12:51:53 +0100 (CET) Subject: [pypy-svn] r36088 - in pypy/dist/pypy/translator/js/modules: . test Message-ID: <20070101115153.825511007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 12:51:51 2007 New Revision: 36088 Removed: pypy/dist/pypy/translator/js/modules/bltns.py pypy/dist/pypy/translator/js/modules/test/test_xmlhttp.py pypy/dist/pypy/translator/js/modules/xmlhttp.py Log: Removed deprecated files. From fijal at codespeak.net Mon Jan 1 14:52:58 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 14:52:58 +0100 (CET) Subject: [pypy-svn] r36091 - pypy/dist/pypy/translator/js/doc Message-ID: <20070101135258.E2ECA1007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 14:52:57 2007 New Revision: 36091 Removed: pypy/dist/pypy/translator/js/doc/ Log: Removed unused dir. From fijal at codespeak.net Mon Jan 1 15:27:58 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 15:27:58 +0100 (CET) Subject: [pypy-svn] r36092 - in pypy/dist/pypy/translator/js/examples: . test Message-ID: <20070101142758.AF94A1007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 15:27:57 2007 New Revision: 36092 Modified: pypy/dist/pypy/translator/js/examples/server.py pypy/dist/pypy/translator/js/examples/test/test_server.py Log: Add a test and not fork by default. Modified: pypy/dist/pypy/translator/js/examples/server.py ============================================================================== --- pypy/dist/pypy/translator/js/examples/server.py (original) +++ pypy/dist/pypy/translator/js/examples/server.py Mon Jan 1 15:27:57 2007 @@ -98,10 +98,10 @@ self.end_headers() self.wfile.write(data) -def start_server(server_address = ('', 8000), handler=TestHandler, start_new=True): +def start_server(server_address = ('', 8000), handler=TestHandler, fork=False): httpd = HTTPServer(server_address, handler) - if start_new: + if fork: import thread thread.start_new_thread(httpd.serve_forever, ()) print "Server started, listening on %s" % (server_address,) Modified: pypy/dist/pypy/translator/js/examples/test/test_server.py ============================================================================== --- pypy/dist/pypy/translator/js/examples/test/test_server.py (original) +++ pypy/dist/pypy/translator/js/examples/test/test_server.py Mon Jan 1 15:27:57 2007 @@ -17,3 +17,7 @@ thread.start_new_thread(httpd.serve_forever, ()) assert URLopener().open("http://127.0.0.1:21210/index").read() == "xxx" +def test_own_startup(): + server.start_server(server_address=('127.0.0.1', 21211), + handler=Handler, fork=True) + assert URLopener().open("http://127.0.0.1:21210/index").read() == "xxx" From fijal at codespeak.net Mon Jan 1 15:44:33 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 15:44:33 +0100 (CET) Subject: [pypy-svn] r36094 - in pypy/dist/pypy/translator/js: . test Message-ID: <20070101144433.0D5501007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 15:44:31 2007 New Revision: 36094 Modified: pypy/dist/pypy/translator/js/main.py pypy/dist/pypy/translator/js/test/test_main.py Log: Added possibility not to specify module (caller module) and a test. Modified: pypy/dist/pypy/translator/js/main.py ============================================================================== --- pypy/dist/pypy/translator/js/main.py (original) +++ pypy/dist/pypy/translator/js/main.py Mon Jan 1 15:44:31 2007 @@ -113,6 +113,15 @@ return retval def rpython2javascript(mod, function_names, jsconfig=None, use_pdb=True): + if isinstance(function_names, str): + function_names = [function_names] + # avoid confusion + if mod is None: + # this means actual module, which is quite hairy to get in python, + # so we cheat + import sys + mod = sys.modules[sys._getframe(1).f_globals['__name__']] + if jsconfig is None: jsconfig = Config(js_optiondescr) if use_pdb: Modified: pypy/dist/pypy/translator/js/test/test_main.py ============================================================================== --- pypy/dist/pypy/translator/js/test/test_main.py (original) +++ pypy/dist/pypy/translator/js/test/test_main.py Mon Jan 1 15:44:31 2007 @@ -21,6 +21,12 @@ def fun(x='3'): return a.method({'a':x})['a'] +def fff(): + pass + def test_bookkeeper_cleanup(): - rpython2javascript(sys.modules[__name__], ["fun"]) - rpython2javascript(sys.modules[__name__], ["fun"]) + assert rpython2javascript(sys.modules[__name__], ["fun"]) + assert rpython2javascript(sys.modules[__name__], ["fun"]) + +def test_module_none(): + assert rpython2javascript(None, "fff") From fijal at codespeak.net Mon Jan 1 15:50:34 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 15:50:34 +0100 (CET) Subject: [pypy-svn] r36095 - pypy/dist/pypy/translator/js/modules Message-ID: <20070101145034.E9BAA1007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 15:50:33 2007 New Revision: 36095 Added: pypy/dist/pypy/translator/js/modules/browser.py (contents, props changed) Modified: pypy/dist/pypy/translator/js/modules/dom.py Log: Moved some stuff (one function for now) from dom to browser. Added: pypy/dist/pypy/translator/js/modules/browser.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/translator/js/modules/browser.py Mon Jan 1 15:50:33 2007 @@ -0,0 +1,9 @@ + +""" +Here are some functions which does not belong to dom, but rather +to browser itself +""" + +def alert(msg): + pass +alert.suggested_primitive = True Modified: pypy/dist/pypy/translator/js/modules/dom.py ============================================================================== --- pypy/dist/pypy/translator/js/modules/dom.py (original) +++ pypy/dist/pypy/translator/js/modules/dom.py Mon Jan 1 15:50:33 2007 @@ -303,9 +303,6 @@ func() #pass -def alert(msg): - pass - # some helper functions (XXX imo these can go, but the code seems to use them # a lot... isn't it possible to just use dom.window and dom.document instead?) From fijal at codespeak.net Mon Jan 1 15:55:51 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 15:55:51 +0100 (CET) Subject: [pypy-svn] r36096 - pypy/dist/pypy/translator/js/modules Message-ID: <20070101145551.57DC01007F@code0.codespeak.net> Author: fijal Date: Mon Jan 1 15:55:50 2007 New Revision: 36096 Modified: pypy/dist/pypy/translator/js/modules/dom.py Log: oops. Modified: pypy/dist/pypy/translator/js/modules/dom.py ============================================================================== --- pypy/dist/pypy/translator/js/modules/dom.py (original) +++ pypy/dist/pypy/translator/js/modules/dom.py Mon Jan 1 15:55:50 2007 @@ -694,7 +694,6 @@ get_window.suggested_primitive = True get_document.suggested_primitive = True setTimeout.suggested_primitive = True -alert.suggested_primitive = True # the following code wraps minidom nodes with Node classes, and makes # sure all methods on the nodes return wrapped nodes From fijal at codespeak.net Mon Jan 1 16:06:35 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Mon, 1 Jan 2007 16:06:35 +0100 (CET) Subject: [pypy-svn] r36097 - pypy/dist/pypy/translator/js/tutorial Message-ID: <20070101150635.DF72E1007A@code0.codespeak.net> Author: fijal Date: Mon Jan 1 16:06:34 2007 New Revision: 36097 Added: pypy/dist/pypy/translator/js/tutorial/ pypy/dist/pypy/translator/js/tutorial/__init__.py (contents, props changed) pypy/dist/pypy/translator/js/tutorial/step1.py (contents, props changed) pypy/dist/pypy/translator/js/tutorial/step2.py (contents, props changed) Log: Added two simple steps how to start, this is intermediate checkin. Added: pypy/dist/pypy/translator/js/tutorial/__init__.py ============================================================================== Added: pypy/dist/pypy/translator/js/tutorial/step1.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/translator/js/tutorial/step1.py Mon Jan 1 16:06:34 2007 @@ -0,0 +1,27 @@ +#!/usr/bin/env python +""" + +This is simple all-in-one self-containing server, +which just shows almost-empty HTML page + +""" + +# here we import server, which is derivative of +# BaseHTTPServer from python standard library +from pypy.translator.js.examples import server + +# We create handler, which will handle all our requests +class Handler(server.TestHandler): + + def index(self): + # provide some html contents + return "

Something

" + # this line is necessary to make server show something, + # otherwise method is considered private-only + index.exposed = True + +if __name__ == '__main__': + # let's start our server, + # this will create running server instance on port 8000 by default, + # which will run until we press Control-C + server.start_server(handler=Handler) Added: pypy/dist/pypy/translator/js/tutorial/step2.py ============================================================================== --- (empty file) +++ pypy/dist/pypy/translator/js/tutorial/step2.py Mon Jan 1 16:06:34 2007 @@ -0,0 +1,52 @@ +#!/usr/bin/env python +""" +In this example, we'll show how to add javascript to our simple +server from previous example +""" + +from pypy.translator.js.examples import server +import sys + +# here we have virtual script "source.js" which we generate +# on-the-fly when requested +HTML = """ + + +