Commits

Martin von Löwis committed 151a120

Parse port number out of URL.

Comments (0)

Files changed (1)

openid2rp/testapp.py

 # can pass it as command line argument
 def test_server():
     import socket, sys
+    port = 8000
     if len(sys.argv) > 1:
+        import urlparse
         base_url = sys.argv[1]
+        netloc = urlparse.urlparse(base_url).netloc
+        if ':' in netloc:
+            host, port = netloc.split(':')
+            port = int(port)
     else:
         base_url = "http://" + socket.getfqdn() + ":8000/"
     print "Listening on", base_url
     Handler.base_url = base_url
-    httpd = HTTPServer(('', 8000), Handler)
+    httpd = HTTPServer(('', port), Handler)
     httpd.serve_forever()
 
 if __name__ == '__main__':