Commit 4345f70c authored by Amos Latteier's avatar Amos Latteier

this version actually works. Still has a ways to go in terms of efficiency.

parent d7521118
......@@ -124,20 +124,45 @@ class zope_handler:
def continue_request(self,sin,request):
"continue handling request now that we have the stdin"
self.request=request
request.data=[]
outpipe=handle(self.module_name,
self.get_environment(request),sin,self.finish)
self.get_environment(request),sin,(self.more,(request,)))
def more(self,request,pipe):
"""packages up the current output from the output pipe.
called repeatedly when there is something in the output pipe"""
# XXX does not stream, probably inefficient.
done=None
while not done:
data=pipe.read()
if data is None:
done=1
elif data=="":
done=1
self.finish(request)
else:
request.data.append(data)
def finish(self,request):
"finishes up the response"
def finish(self):
print "finish called"
self.request.reply_code=200
self.request["Content-type"]="text/html"
self.request.push(outputpipe_producer(outpipe))
self.request.done()
del self.request
# XXX does not stream, probably inefficient to boot
data=string.join(request.data,'')
if string.find(data,"\n\n"):
[headers,html]=string.split(data,"\n\n",1)
headers=string.split(headers,"\n")
for line in headers:
[header, header_value]=string.split(line,": ",1)
if header=="Status":
[code,message]=string.split(header_value," ",1)
request.reply_code=string.atoi(code)
else:
request[header]=header_value
request.push(html)
request.done()
def status (self):
return producers.simple_producer("""
......@@ -177,58 +202,3 @@ class input_collector:
del self.handler
del self.request
h.continue_request(self.data,r)
class outputpipe_producer:
"producer for outputpipe"
def __init__(self,pipe):
self.more=pipe.read
class outputpipe_producer2:
"producer for outputpipe response"
def __init__(self,request,pipe):
self.request=request
self.pipe=pipe
self.data=""
self.latch=None
def ready(self):
print "ready called"
if self.latch is not None:
self.read_headers()
if self.latch is not None and (self.data or self.pipe._buf):
return 1
else:
return 0
def more(self):
print "more called"
if self.latch is not None:
if self.data:
return self.data
else:
return self.pipe.read()
else:
self.read_headers()
return self.more()
def read_headers(self):
print "read headers called"
self.data=self.data + self.pipe.read()
if string.find(self.data,"\n\n"):
print "headers found"
[headers,html]=string.split(self.data,"\n\n",1)
headers=string.split(headers,"\n")
for line in headers:
[header, header_value]=string.split(line,": ",1)
if header=="Status":
[code,message]=string.split(header_value," ",1)
self.request.reply_code=string.atoi(code)
else:
self.request[header]=header_value
self.data=html
self.latch=1
\ No newline at end of file
......@@ -124,20 +124,45 @@ class zope_handler:
def continue_request(self,sin,request):
"continue handling request now that we have the stdin"
self.request=request
request.data=[]
outpipe=handle(self.module_name,
self.get_environment(request),sin,self.finish)
self.get_environment(request),sin,(self.more,(request,)))
def more(self,request,pipe):
"""packages up the current output from the output pipe.
called repeatedly when there is something in the output pipe"""
# XXX does not stream, probably inefficient.
done=None
while not done:
data=pipe.read()
if data is None:
done=1
elif data=="":
done=1
self.finish(request)
else:
request.data.append(data)
def finish(self,request):
"finishes up the response"
def finish(self):
print "finish called"
self.request.reply_code=200
self.request["Content-type"]="text/html"
self.request.push(outputpipe_producer(outpipe))
self.request.done()
del self.request
# XXX does not stream, probably inefficient to boot
data=string.join(request.data,'')
if string.find(data,"\n\n"):
[headers,html]=string.split(data,"\n\n",1)
headers=string.split(headers,"\n")
for line in headers:
[header, header_value]=string.split(line,": ",1)
if header=="Status":
[code,message]=string.split(header_value," ",1)
request.reply_code=string.atoi(code)
else:
request[header]=header_value
request.push(html)
request.done()
def status (self):
return producers.simple_producer("""
......@@ -177,58 +202,3 @@ class input_collector:
del self.handler
del self.request
h.continue_request(self.data,r)
class outputpipe_producer:
"producer for outputpipe"
def __init__(self,pipe):
self.more=pipe.read
class outputpipe_producer2:
"producer for outputpipe response"
def __init__(self,request,pipe):
self.request=request
self.pipe=pipe
self.data=""
self.latch=None
def ready(self):
print "ready called"
if self.latch is not None:
self.read_headers()
if self.latch is not None and (self.data or self.pipe._buf):
return 1
else:
return 0
def more(self):
print "more called"
if self.latch is not None:
if self.data:
return self.data
else:
return self.pipe.read()
else:
self.read_headers()
return self.more()
def read_headers(self):
print "read headers called"
self.data=self.data + self.pipe.read()
if string.find(self.data,"\n\n"):
print "headers found"
[headers,html]=string.split(self.data,"\n\n",1)
headers=string.split(headers,"\n")
for line in headers:
[header, header_value]=string.split(line,": ",1)
if header=="Status":
[code,message]=string.split(header_value," ",1)
self.request.reply_code=string.atoi(code)
else:
self.request[header]=header_value
self.data=html
self.latch=1
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment