[Zope-Checkins] CVS: Zope/lib/python/ZPublisher -
	Iterators.py:1.1.2.1
    Chris McDonough 
    chrism at plope.com
       
    Sun Mar 28 01:12:13 EST 2004
    
    
  
Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv9701/ZPublisher
Added Files:
      Tag: chrism-publishfile-branch
	Iterators.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).
=== Added File Zope/lib/python/ZPublisher/Iterators.py ===
from Interface import Interface
class IStreamIterator(Interface):
    def next(self):
        """
        Return a sequence of bytes out of the bytestream, or raise
        StopIeration if we've reached the end of the bytestream.
        """
class filestream_iterator(file):
    """
    a file subclass which implements an iterator that returns a
    fixed-sized sequence of bytes.
    """
    __implements__ = (IStreamIterator,)
    def __init__(self, name, mode='r', bufsize=-1, streamsize=1<<16):
        file.__init__(self, name, mode, bufsize)
        self.streamsize = streamsize
    def next(self):
        data = self.read(self.streamsize)
        if not data:
            raise StopIteration
        return data
    
    
    
    
More information about the Zope-Checkins
mailing list