[Zope-Checkins] CVS: Zope/lib/python/ZServer -
HTTPResponse.py:1.43.8.1.4.3 Producers.py:1.9.44.2
Chris McDonough
chrism at plope.com
Sun Mar 28 01:12:40 EST 2004
Update of /cvs-repository/Zope/lib/python/ZServer
In directory cvs.zope.org:/tmp/cvs-serv9701/ZServer
Modified Files:
Tag: chrism-publishfile-branch
HTTPResponse.py Producers.py
Log Message:
Instead of returning a producer directly, return a StreamIterator which is then turned into a producer. This provides better encapsulation, as Zope app code won't depend on ZServer in places where it returns an iterator (instead it will depend only on ZPublisher).
=== Zope/lib/python/ZServer/HTTPResponse.py 1.43.8.1.4.2 => 1.43.8.1.4.3 ===
--- Zope/lib/python/ZServer/HTTPResponse.py:1.43.8.1.4.2 Wed Mar 24 02:49:06 2004
+++ Zope/lib/python/ZServer/HTTPResponse.py Sun Mar 28 01:12:09 2004
@@ -21,13 +21,14 @@
from cStringIO import StringIO
import thread
from ZPublisher.HTTPResponse import HTTPResponse
+from ZPublisher.Iterators import IStreamIterator
from medusa.http_date import build_http_date
from PubCore.ZEvent import Wakeup
from medusa.producers import hooked_producer
from medusa import http_server
import asyncore
from Producers import ShutdownProducer, LoggingProducer, CallbackProducer, \
- file_part_producer, file_close_producer, IZServerProducer
+ file_part_producer, file_close_producer, iterator_producer
from types import LongType
import DebugLogger
@@ -238,10 +239,11 @@
self.stdout.write(self._bodyproducer, 0)
def setBody(self, body, title='', is_error=0, **kw):
- """ Accept either a producer or a string as the body """
- if IZServerProducer.isImplementedBy(body):
+ """ Accept either a stream iterator or a string as the body """
+ if IStreamIterator.isImplementedBy(body):
assert(self.headers.has_key('content-length'))
- self._bodyproducer = body
+ # wrap the iterator up in a producer that medusa can understand
+ self._bodyproducer = iterator_producer(body)
HTTPResponse.setBody(self, '', title, is_error, **kw)
return self
else:
=== Zope/lib/python/ZServer/Producers.py 1.9.44.1 => 1.9.44.2 ===
--- Zope/lib/python/ZServer/Producers.py:1.9.44.1 Wed Mar 24 02:49:06 2004
+++ Zope/lib/python/ZServer/Producers.py Sun Mar 28 01:12:09 2004
@@ -16,27 +16,15 @@
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()
class LoggingProducer:
"logs request"
- __implements__ = (IZServerProducer,)
-
def __init__(self, logger, bytes, method='log'):
self.logger=logger
self.bytes=bytes
@@ -50,8 +38,6 @@
class CallbackProducer:
"Performs a callback in the channel's thread"
- __implements__ = (IZServerProducer,)
-
def __init__(self, callback):
self.callback=callback
@@ -63,8 +49,6 @@
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
@@ -103,35 +87,7 @@
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
@@ -142,3 +98,12 @@
self.file=None
return ''
+class iterator_producer:
+ def __init__(self, iterator):
+ self.iterator = iterator
+
+ def more(self):
+ try:
+ return self.iterator.next()
+ except StopIteration:
+ return ''
More information about the Zope-Checkins
mailing list