def run_bnb(): from pypy.translator.js.examples.bnb.bnb import BnbRoot from pypy.translator.js.lib import server addr = ('', 7070) httpd = server.create_server(handler=BnbRoot, server_address=addr) httpd.source = rpython2javascript(sys.modules[__name__], ['bnb']) httpd.serve_forever()
def test_build(): py.test.skip('Børken') global TRANSLATING TRANSLATING = True for var in globals(): if var.startswith('code_'): # just build it #def f(): assert rpython2javascript(sys.modules[__name__], [var], use_pdb=False) TRANSLATING = False
def run_jssource(self): js_name = py.path.local(__file__).dirpath("webdata").join("source.js") web_name = py.path.local(__file__).dirpath().join("webjs.py") if IMPORTED_PYPY and web_name.mtime() > js_name.mtime(): from py.__.test.rsession import webjs javascript_source = rpython2javascript(webjs, FUNCTION_LIST, use_pdb=False) open(str(js_name), "w").write(javascript_source) self.serve_data("text/javascript", javascript_source) else: js_source = open(str(js_name), "r").read() self.serve_data("text/javascript", js_source)
def js_source(functions, use_pdb=True): mod = new.module('_js_src') function_names = [] for func in functions: name = func.__name__ if hasattr(mod, name): raise ValueError("exported function name %r is duplicated" % (name,)) mod.__dict__[name] = func function_names.append(name) sys.modules['_js_src'] = mod try: return rpython2javascript(mod, function_names, use_pdb=use_pdb) finally: del sys.modules['_js_src']
def test_console_2_build(): from pypy.translator.js.examples.console import console, client assert rpython2javascript(client, console.FUNCTION_LIST, use_pdb=True)
def test_overmind_build(): from pypy.translator.js.examples import overmind, over_client assert rpython2javascript(over_client, overmind.FUNCTION_LIST, use_pdb=False)
def source_js(self): # this returns content-type (if not text/html) # and generated javascript code # None as argument means current module, while "show" is the # name of function to be exported (under same name) return "text/javascript", rpython2javascript(None, ["show"])
ping_handler.ping("PING", callback) def callback(data): mochikit.logDebug("Got response: " + data["response"]) log = dom.document.getElementById("log") mochikit.logDebug("got log element") try: s = "<p>" + data["response"] + "</p>" except KeyError: mochikit.logDebug("Can't find data") s = "<p>" + "Error" + "</p>" mochikit.logDebug("Adding: " + s) log.innerHTML += s mochikit.logDebug("added message") def doping_onclick(event): mochikit.logDebug("calling pinger") jsping() def ping_init(): mochikit.createLoggingPane(True) button = dom.document.getElementById("doping") button.onclick = doping_onclick mochikit.logDebug("Ping button setup") if __name__ == "__main__": # circular import from pypy.translator.js.examples.djangoping import client from pypy.translator.js.main import rpython2javascript print rpython2javascript(client, ["ping_init"])
def test_module_none(): assert rpython2javascript(None, "fff")
def test_bookkeeper_cleanup(): assert rpython2javascript(sys.modules[__name__], ["fun"]) assert rpython2javascript(sys.modules[__name__], ["fun"])
mochikit.logDebug("Got response: " + data["response"]) log = dom.document.getElementById("log") mochikit.logDebug("got log element") try: s = "<p>" + data["response"] + "</p>" except KeyError: mochikit.logDebug("Can't find data") s = "<p>" + "Error" + "</p>" mochikit.logDebug("Adding: " + s) log.innerHTML += s mochikit.logDebug("added message") def doping_onclick(event): mochikit.logDebug("calling pinger") jsping() def ping_init(): mochikit.createLoggingPane(True) button = dom.document.getElementById("doping") button.onclick = doping_onclick mochikit.logDebug("Ping button setup") if __name__ == "__main__": # circular import from pypy.translator.js.examples.djangoping import client from pypy.translator.js.main import rpython2javascript print rpython2javascript(client, ["ping_init"])
def source_js(self): return "text/javascript", rpython2javascript(None, ["addrow", "delrow"])
def test_build(): from pypy.translator.js.examples.djangoping import client assert rpython2javascript(client, ['ping_init'], use_pdb=False)
def ping_js(request): js_src = rpython2javascript(client, ["ping_init"]) response = HttpResponse(mimetype="text/javascript") response.write(js_src) return response
def guestbook_client(): """ compile the rpython guestbook_client code to js """ import guestbook_client return rpython2javascript(guestbook_client, FUNCTION_LIST)
def js_source(): import client return rpython2javascript(client, FUNCTION_LIST)
def test_bnb_build(): from pypy.translator.js.examples.bnb import start_bnb assert rpython2javascript(start_bnb, ['bnb'], use_pdb=False)
def test_guestbook_build(): from pypy.translator.js.examples import guestbook, guestbook_client assert rpython2javascript(guestbook_client, guestbook.FUNCTION_LIST, use_pdb=False)
def test_js_generate(): from py.__.test.report import webjs from py.__.test.report.web import FUNCTION_LIST, IMPORTED_PYPY source = rpython2javascript(webjs, FUNCTION_LIST, use_pdb=False) assert source
def test_console_build(): from pypy.translator.js.examples import pythonconsole httpd = pythonconsole.Server(('', 0), pythonconsole.RequestHandler) pythonconsole.httpd = httpd # XXX obscure hack assert rpython2javascript(pythonconsole, ['setup_page'], use_pdb=False)
def test_js_generate(): from py.__.test.rsession import webjs from py.__.test.rsession.web import FUNCTION_LIST, IMPORTED_PYPY source = rpython2javascript(webjs, FUNCTION_LIST) assert source
def js_source(function_list): import over_client return rpython2javascript(over_client, FUNCTION_LIST)