From ef95578db4100235b34a54a10466bbf375e7609b Mon Sep 17 00:00:00 2001 From: alobbs Date: Tue, 12 Dec 2006 09:44:58 +0000 Subject: [PATCH] git-svn-id: svn://cherokee-project.com/cherokee-pyscgi@517 5dc97367-97f1-0310-9951-d761b3857238 --- ChangeLog | 11 +++++++++++ pyscgi/pyscgi.py | 14 +++++++++++++- tests/test1_env.py | 4 ++-- tests/test2_post.py | 4 ++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 87c2d2a..7998486 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-12-12 Alvaro Lopez Ortega + + * tests/test1_env.py, tests/test2_post.py: Updated for using + ServerFactory. + + * pyscgi/pyscgi.py: Added new SCGIServerFork class implementing a + forking server. So far I had only a Thread based one. + + * pyscgi/pyscgi.py (ServerFactory): Added a new factory function + to instance servers. + 2006-12-10 Alvaro Lopez Ortega * pyscgi/pyscgi.py, tests/test1_env.py, tests/test2_post.py: First diff --git a/pyscgi/pyscgi.py b/pyscgi/pyscgi.py index c264804..6ebec6c 100644 --- a/pyscgi/pyscgi.py +++ b/pyscgi/pyscgi.py @@ -103,4 +103,16 @@ def handle_request (self): class SCGIServer(SocketServer.ThreadingTCPServer): def __init__(self, handler_class=SCGIHandler, host="", port=4000): self.allow_reuse_address = True - SocketServer.TCPServer.__init__ (self, (host, port), handler_class) + SocketServer.ThreadingTCPServer.__init__ (self, (host, port), handler_class) + +class SCGIServerFork (SocketServer.ForkingTCPServer): + def __init__(self, handler_class=SCGIHandler, host="", port=4000): + self.allow_reuse_address = True + SocketServer.ForkingTCPServer.__init__ (self, (host, port), handler_class) + + +def ServerFactory (threading=False, *args, **kargs): + if threading: + return SCGIServer(*args, **kargs) + else: + return SCGIServerFork(*args, **kargs) diff --git a/tests/test1_env.py b/tests/test1_env.py index 38abcec..8431af7 100755 --- a/tests/test1_env.py +++ b/tests/test1_env.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from pyscgi import SCGIHandler, SCGIServer +from pyscgi import ServerFactory, SCGIHandler DEFAULT_PORT = 4000 @@ -20,7 +20,7 @@ def handle_request (self): self.print_env() def main(): - srv = SCGIServer(handler_class=MyHandler, port=DEFAULT_PORT) + srv = ServerFactory(handler_class=MyHandler, port=DEFAULT_PORT) srv.serve_forever() if __name__ == "__main__": diff --git a/tests/test2_post.py b/tests/test2_post.py index ea1a06b..310c6a0 100755 --- a/tests/test2_post.py +++ b/tests/test2_post.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from pyscgi import SCGIHandler, SCGIServer +from pyscgi import SCGIHandler, ServerFactory DEFAULT_PORT = 4000 POST_EXAMPLE = """ @@ -36,7 +36,7 @@ def handle_request (self): self.output.write(POST_EXAMPLE) def main(): - srv = SCGIServer(handler_class=MyHandler, port=DEFAULT_PORT) + srv = ServerFactory(handler_class=MyHandler, port=DEFAULT_PORT) srv.serve_forever() if __name__ == "__main__":