diff options
Diffstat (limited to 'pagehandler.py')
-rwxr-xr-x | pagehandler.py | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/pagehandler.py b/pagehandler.py index 3933fce..995f95c 100755 --- a/pagehandler.py +++ b/pagehandler.py @@ -37,6 +37,13 @@ usage: %s [-hp] -p: enable profiling """%(os.path.basename(sys.argv[0])) + def cmdline_resp(status, headers): + print "STATUS:",status + print "HEADERS START" + for h,v in headers: + print "%s: %s"%(h,v) + print + opts,args = getopt.getopt(sys.argv[1:], "hp") profiling = False for o,v in opts: @@ -46,16 +53,25 @@ usage: %s [-hp] if o == "-p": profiling = True - print "pagehandler test server running..." - server = ss.WSGIServer( ('',8080), ss.WSGIRequestHandler) - server.set_app(application) - while True: - try: - if not profiling: - server.handle_request() - else: - profile.run("server.handle_request()", "profile.out") - p = pstats.Stats("profile.out") - p.strip_dirs().sort_stats('time').print_stats(20) - except IOError, e: - print "adsf: ",e + if not args: + print "pagehandler test server running..." + server = ss.WSGIServer( ('',8080), ss.WSGIRequestHandler) + server.set_app(application) + while True: + try: + if not profiling: + server.handle_request() + else: + profile.run("server.handle_request()", "profile.out") + p = pstats.Stats("profile.out") + p.strip_dirs().sort_stats('time').print_stats(20) + except IOError, e: + print "adsf: ",e + else: + os.environ['PATH_INFO'] = args[0] + if not profiling: + application(os.environ, cmdline_resp) + else: + profile.run("application(os.environ, cmdline_resp)", "profile.out") + p = pstats.Stats("profile.out") + p.strip_dirs().sort_stats('time').print_stats(20) |