Esempio n. 1
0
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()
Esempio n. 2
0
#!/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.lib import server


# We create handler, which will handle all our requests
class Handler(server.TestHandler):
    def index(self):
        # provide some html contents
        return "<html><head></head><body><p>Something</p></body></html>"

    # 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.create_server(handler=Handler).serve_forever()
Esempio n. 3
0
from pypy.translator.js.main import rpython2javascript
# here we import rpython -> javascript conversion utility

from pypy.translator.js.modules import dom
# and here we import functions from modules that we want to use

# this is function which will be translated into javascript,
# we can put it in a different module if we like so
def show():
    dom.alert("Alert")

class Handler(server.TestHandler):

    def index(self):
        return HTML
    index.exposed = True

    # here we generate javascript, this will be accessed when
    # asked for source.js
    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"])
    source_js.exposed = True

# server start, same as before
if __name__ == '__main__':
    server.create_server(handler=Handler).serve_forever()
Esempio n. 4
0
                <form action="." method="post"
                      onsubmit="add_message(this); return false">
                  name: <input type="text" name="name" id="name" /><br />
                  message:<br />
                  <textarea name="message" id="message"></textarea><br />
                  <input type="submit" />
                </form>
              </body>
            </html>
        """
        return 'text/html', html

    index.exposed = True

    # the (generated) javascript
    def guestbook_js(self):
        if hasattr(self.server, 'source'):
            source = self.server.source
        else:
            source = guestbook_client()
            self.server.source = source
        return "text/javascript", source

    guestbook_js.exposed = True


if __name__ == '__main__':
    addr = ('', 8008)
    httpd = server.create_server(server_address=addr, handler=Handler)
    httpd.serve_forever()
Esempio n. 5
0
class Root(server.Collection):
    exported_methods = exported_methods
    index = server.FsFile(static_dir.join("console.html"))
    style_css = server.FsFile(
        static_dir.dirpath().dirpath().join("data").join("style.css"))
    MochiKit = server.StaticDir('MochiKit')

    def source_js(self):
        if hasattr(self.server, 'source_console'):
            source = self.server.source_console
        else:
            source = js_source()
            self.server.source_console = source
        return "text/javascript", source

    source_js.exposed = True


class Handler(server.NewHandler):
    application = Root()
    application.some = Root()
    application.other = Root()


if __name__ == '__main__':
    addr = ('', 8007)
    httpd = server.create_server(server_address=addr,
                                 handler=Handler,
                                 server=GreenHTTPServer)
    httpd.serve_forever()
Esempio n. 6
0
        </html>'''
    bnb.exposed = True

    def handle_error(self, exc, e_value, tb):
        import traceback
        tb_formatted = '\n'.join(traceback.format_tb(tb)) + \
                       "%s: %s" % (exc, e_value)
        log_file = open("/tmp/play1_error_log", "a")
        log_file.write(tb_formatted)
        log_file.close()
        print tb_formatted

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)
        httpd = server.create_server(server_address=addr, handler=Handler,
                                     server=GreenHTTPServer)
        httpd.serve_forever()
    except KeyboardInterrupt:
        for pid in pids:
            # eventually os.kill stuff
            os.kill(pid, 15)
            os.waitpid(pid, 0)

Esempio n. 7
0
def test_own_startup():
    httpd = server.create_server(server_address=('127.0.0.1', 21211),
                                 handler=Handler)
    server.start_server_in_new_thread(httpd)
    assert URLopener().open("http://127.0.0.1:21210/index").read() == "xxx"
Esempio n. 8
0
                <div id="messages">
                  <!-- this will be filled from javascript -->
                </div>
                <form action="." method="post"
                      onsubmit="add_message(this); return false">
                  name: <input type="text" name="name" id="name" /><br />
                  message:<br />
                  <textarea name="message" id="message"></textarea><br />
                  <input type="submit" />
                </form>
              </body>
            </html>
        """
        return 'text/html', html
    index.exposed = True

    # the (generated) javascript
    def guestbook_js(self):
        if hasattr(self.server, 'source'):
            source = self.server.source
        else:
            source = guestbook_client()
            self.server.source = source
        return "text/javascript", source
    guestbook_js.exposed = True

if __name__ == '__main__':
    addr = ('', 8008)
    httpd = server.create_server(server_address=addr, handler=Handler)
    httpd.serve_forever()
Esempio n. 9
0
def test_own_startup():
    httpd = server.create_server(server_address=('127.0.0.1', 21211),
                        handler=Handler)
    server.start_server_in_new_thread(httpd)
    assert URLopener().open("http://127.0.0.1:21210/index").read() == "xxx"