Re: Request subclassing
Matt Patterson <[email protected]>
| Newsgroups | gmane.comp.web.quixote.user |
|---|---|
| Message-ID | <[email protected]> |
On 10 Nov 2005, at 11:43, David Binger wrote: > If the Publisher is be the authority request instance construction, > maybe > it also be the caller of the request constructor. > > def process(self, stdin, env): > request = HTTPRequest(stdin, env) > return self.process_request(request) > > Wouldn't this simplify the responsibilities of the driver scripts? > (And you could override process to get your customized requests.) Here's a patch implementing that, with changes to the bundled driver scripts. Matt -- Matt Patterson | Design & Code <matt at emdash co uk> | http://www.emdash.co.uk/ <matt at reprocessed org> | http://www.reprocessed.org/ _______________________________________________ Quixote-users mailing list [email protected] http://mail.mems-exchange.org/mailman/listinfo/quixote-users
quixote-publisher-process.patch
(application/octet-stream, 5.4 KB)
diff -ur Quixote-2.3/publish.py Quixote-2.3-process/publish.py
--- Quixote-2.3/publish.py 2005-09-22 15:18:03.000000000 +0100
+++ Quixote-2.3-process/publish.py 2005-11-10 14:36:23.000000000 +0000
@@ -263,6 +263,19 @@
"""
return output
+ def process(self, stdin, env):
+ """(stdin : stream, env : dict) -> HTTPResponse
+
+ Process a single request, given a stream, stdin, containing the
+ incoming request and a dictionary, env, containing the web server's
+ environment.
+
+ An HTTPRequest object is created and the process_request() method is
+ called and passed the request object.
+ """
+ request = HTTPRequest(stdin, env)
+ return self.process_request(request)
+
def process_request(self, request):
"""(request : HTTPRequest) -> HTTPResponse
diff -ur Quixote-2.3/server/cgi_server.py Quixote-2.3-process/server/cgi_server.py
--- Quixote-2.3/server/cgi_server.py 2004-11-10 22:37:39.000000000 +0000
+++ Quixote-2.3-process/server/cgi_server.py 2005-11-10 14:40:43.000000000 +0000
@@ -14,8 +14,7 @@
msvcrt.setmode(sys.__stdin__.fileno(), os.O_BINARY)
msvcrt.setmode(sys.__stdout__.fileno(), os.O_BINARY)
publisher = create_publisher()
- request = HTTPRequest(sys.__stdin__, os.environ)
- response = publisher.process_request(request)
+ response = publisher.process(sys.__stdin__, os.environ)
try:
response.write(sys.__stdout__)
except IOError, err:
diff -ur Quixote-2.3/server/fastcgi_server.py Quixote-2.3-process/server/fastcgi_server.py
--- Quixote-2.3/server/fastcgi_server.py 2004-10-28 23:52:11.000000000 +0100
+++ Quixote-2.3-process/server/fastcgi_server.py 2005-11-10 14:40:28.000000000 +0000
@@ -14,8 +14,7 @@
publisher = create_publisher()
while _fcgi.isFCGI():
f = _fcgi.FCGI()
- request = HTTPRequest(f.inp, f.env)
- response = publisher.process_request(request)
+ response = publisher.process(f.inp, f.env)
try:
response.write(f.out)
except IOError, err:
diff -ur Quixote-2.3/server/medusa_server.py Quixote-2.3-process/server/medusa_server.py
--- Quixote-2.3/server/medusa_server.py 2004-11-11 21:13:42.000000000 +0000
+++ Quixote-2.3-process/server/medusa_server.py 2005-11-10 14:40:09.000000000 +0000
@@ -86,8 +86,7 @@
environ[envname] = header
stdin = StringIO(data)
- qrequest = HTTPRequest(stdin, environ)
- qresponse = self.publisher.process_request(qrequest)
+ qresponse = self.publisher.process(stdin, environ)
# Copy headers from Quixote's HTTP response
for name, value in qresponse.generate_headers():
diff -ur Quixote-2.3/server/mod_python_handler.py Quixote-2.3-process/server/mod_python_handler.py
--- Quixote-2.3/server/mod_python_handler.py 2005-01-19 14:26:25.000000000 +0000
+++ Quixote-2.3-process/server/mod_python_handler.py 2005-11-10 14:38:37.000000000 +0000
@@ -82,8 +82,8 @@
def run(publisher, req):
from quixote.http_request import HTTPRequest
- request = HTTPRequest(apache.CGIStdin(req), apache.build_cgi_env(req))
- response = publisher.process_request(request)
+ response = publisher.process(apache.CGIStdin(req),
+ apache.build_cgi_env(req))
try:
response.write(apache.CGIStdout(req))
except IOError, err:
diff -ur Quixote-2.3/server/scgi_server.py Quixote-2.3-process/server/scgi_server.py
--- Quixote-2.3/server/scgi_server.py 2005-08-10 21:33:41.000000000 +0100
+++ Quixote-2.3-process/server/scgi_server.py 2005-11-10 14:36:38.000000000 +0000
@@ -28,8 +28,7 @@
env['SCRIPT_NAME'] = prefix
env['PATH_INFO'] = path[len(prefix):] + env.get('PATH_INFO', '')
- request = HTTPRequest(input, env)
- response = self.publisher.process_request(request)
+ response = self.publisher.process(input, env)
try:
response.write(output)
input.close()
diff -ur Quixote-2.3/server/simple_server.py Quixote-2.3-process/server/simple_server.py
--- Quixote-2.3/server/simple_server.py 2005-09-06 17:58:49.000000000 +0100
+++ Quixote-2.3-process/server/simple_server.py 2005-11-10 14:37:25.000000000 +0000
@@ -53,8 +53,7 @@
return env
def process(self, env, include_body=True):
- request = HTTPRequest(self.rfile, env)
- response = get_publisher().process_request(request)
+ response = get_publisher().process(self.rfile, env)
try:
self.send_response(response.get_status_code(),
response.get_reason_phrase())
diff -ur Quixote-2.3/server/twisted_server.py Quixote-2.3-process/server/twisted_server.py
--- Quixote-2.3/server/twisted_server.py 2004-12-08 20:46:16.000000000 +0000
+++ Quixote-2.3-process/server/twisted_server.py 2005-11-10 14:41:22.000000000 +0000
@@ -30,8 +30,8 @@
# this seek is important, it doesn't work without it (it doesn't
# matter for GETs, but POSTs will not work properly without it.)
self.content.seek(0, 0)
- qxrequest = HTTPRequest(self.content, environ)
- qxresponse = self.channel.factory.publisher.process_request(qxrequest)
+ qxresponse = self.channel.factory.publisher.process(self.content,
+ environ)
self.setResponseCode(qxresponse.status_code)
for name, value in qxresponse.generate_headers():
if name != 'Set-Cookie':