[Zope-Checkins] CVS: Zope/lib/python/ZServer -
HTTPResponse.py:1.43.8.1.4.2 Producers.py:1.9.44.1
Chris McDonough
chrism at plope.com
Wed Mar 24 02:49:37 EST 2004
Update of /cvs-repository/Zope/lib/python/ZServer
In directory cvs.zope.org:/tmp/cvs-serv30859
Modified Files:
Tag: chrism-publishfile-branch
HTTPResponse.py Producers.py
Log Message:
Don't use a setBodyProducer API... keep the publisher the way it is.
Use an interface to denote that something is a producer.
Don't use an fcplaceholder marker class.
=== Zope/lib/python/ZServer/HTTPResponse.py 1.43.8.1.4.1 => 1.43.8.1.4.2 ===
--- Zope/lib/python/ZServer/HTTPResponse.py:1.43.8.1.4.1 Sun Mar 21 14:38:52 2004
+++ Zope/lib/python/ZServer/HTTPResponse.py Wed Mar 24 02:49:06 2004
@@ -27,7 +27,7 @@
from medusa import http_server
import asyncore
from Producers import ShutdownProducer, LoggingProducer, CallbackProducer, \
- file_part_producer, file_close_producer
+ file_part_producer, file_close_producer, IZServerProducer
from types import LongType
import DebugLogger
@@ -237,11 +237,15 @@
if self._bodyproducer:
self.stdout.write(self._bodyproducer, 0)
- def setBodyProducer(self, producer):
- assert(self.headers.has_key('content-length'))
- assert(hasattr(producer, 'more'))
- self._bodyproducer = producer
- return self
+ def setBody(self, body, title='', is_error=0, **kw):
+ """ Accept either a producer or a string as the body """
+ if IZServerProducer.isImplementedBy(body):
+ assert(self.headers.has_key('content-length'))
+ self._bodyproducer = body
+ HTTPResponse.setBody(self, '', title, is_error, **kw)
+ return self
+ else:
+ HTTPResponse.setBody(self, body, title, is_error, **kw)
class ChannelPipe:
"""Experimental pipe from ZPublisher to a ZServer Channel.
=== Zope/lib/python/ZServer/Producers.py 1.9 => 1.9.44.1 ===
--- Zope/lib/python/ZServer/Producers.py:1.9 Tue Mar 18 16:15:14 2003
+++ Zope/lib/python/ZServer/Producers.py Wed Mar 24 02:49:06 2004
@@ -16,9 +16,18 @@
import asyncore
import sys
+from Interface import Interface
+
+class IZServerProducer(Interface):
+ def more(self):
+ """
+ Return as much data as necessary/desired from a stream of bytes.
+ """
+
class ShutdownProducer:
"shuts down medusa"
+ __implements__ = (IZServerProducer,)
def more(self):
asyncore.close_all()
@@ -26,6 +35,7 @@
class LoggingProducer:
"logs request"
+ __implements__ = (IZServerProducer,)
def __init__(self, logger, bytes, method='log'):
self.logger=logger
@@ -40,6 +50,7 @@
class CallbackProducer:
"Performs a callback in the channel's thread"
+ __implements__ = (IZServerProducer,)
def __init__(self, callback):
self.callback=callback
@@ -52,6 +63,7 @@
class file_part_producer:
"producer wrapper for part of a file[-like] objects"
+ __implements__ = (IZServerProducer,)
# match http_channel's outgoing buffer size
out_buffer_size = 1<<16
@@ -92,7 +104,34 @@
return data
+class file_producer:
+ "producer wrapper for file[-like] objects"
+ __implements__ = (IZServerProducer,)
+
+ # match http_channel's outgoing buffer size
+ out_buffer_size = 1<<16
+
+ def __init__ (self, file):
+ self.done = 0
+ self.file = file
+
+ def more (self):
+ if self.done:
+ return ''
+ else:
+ data = self.file.read (self.out_buffer_size)
+ if not data:
+ self.file.close()
+ del self.file
+ self.done = 1
+ return ''
+ else:
+ return data
+
+
class file_close_producer:
+ __implements__ = (IZServerProducer,)
+
def __init__(self, file):
self.file=file
@@ -102,3 +141,4 @@
file.close()
self.file=None
return ''
+
More information about the Zope-Checkins
mailing list