[pypy-svn] r38613 - in pypy/dist/pypy/translator/js/lib: . test

fijal at codespeak.net fijal at codespeak.net
Mon Feb 12 18:42:24 CET 2007


Author: fijal
Date: Mon Feb 12 18:42:23 2007
New Revision: 38613

Modified:
   pypy/dist/pypy/translator/js/lib/server.py
   pypy/dist/pypy/translator/js/lib/test/test_server.py
Log:
Fix that allows to have file telling on which port server is running


Modified: pypy/dist/pypy/translator/js/lib/server.py
==============================================================================
--- pypy/dist/pypy/translator/js/lib/server.py	(original)
+++ pypy/dist/pypy/translator/js/lib/server.py	Mon Feb 12 18:42:23 2007
@@ -32,7 +32,7 @@
 from pypy.translator.js.main import rpython2javascript
 from pypy.translator.js import commproxy
 
-commproxy.USE_MOCHIKIT = True
+commproxy.USE_MOCHIKIT = False
 
 class ExportedMethods(BasicExternal):
     _render_xmlhttp = True
@@ -118,7 +118,7 @@
         return open(self.path).read()
 
 def start_server(server_address = ('', 8000), handler=TestHandler, fork=False,
-                 timeout=None, server=HTTPServer):
+                 timeout=None, server=HTTPServer, port_file=None):
     patch_handler(handler)
     httpd = server(server_address, handler)
     if timeout:
@@ -133,17 +133,16 @@
         thread.start_new_thread(f, (httpd,))
     httpd.last_activity = time.time()
 
+    print "Server started, listening on %s:%s" %\
+          (httpd.server_address[0],httpd.server_port)
+    if port_file:
+        # this is strange hack to allow exchange of port information
+        py.path.local(port_file).write(str(httpd.server_port))
     if fork:
         import thread
         thread.start_new_thread(httpd.serve_forever, ())
-        print "Server started, listening on %s:%s" %\
-             (httpd.server_address[0],httpd.server_port)
-        sys.stdout.flush()
         return httpd
     else:
-        print "Server started, listening on %s:%s" %\
-             (httpd.server_address[0],httpd.server_port)
-        sys.stdout.flush()
         httpd.serve_forever()
 
 Handler = TestHandler

Modified: pypy/dist/pypy/translator/js/lib/test/test_server.py
==============================================================================
--- pypy/dist/pypy/translator/js/lib/test/test_server.py	(original)
+++ pypy/dist/pypy/translator/js/lib/test/test_server.py	Mon Feb 12 18:42:23 2007
@@ -53,3 +53,10 @@
     assert URLopener().open("http://127.0.0.1:21213/index").read() == \
            "<html></html>"
     
+def test_port_file():
+    tmpdir = py.test.ensuretemp("port_file")
+    server.start_server(('127.0.0.1', 21214), port_file=tmpdir.join("f"),
+                        fork=True)
+    assert tmpdir.join("f").read() == "21214"
+
+    



More information about the Pypy-commit mailing list