[Zope-Checkins] SVN: Zope/trunk/ - forward-port DTMLMethod/filestream_iterator fix from 2.7

Jens Vagelpohl jens at dataflake.org
Mon Jan 10 09:16:41 EST 2005


Log message for revision 28774:
  - forward-port DTMLMethod/filestream_iterator fix from 2.7
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/OFS/DTMLMethod.py
  U   Zope/trunk/lib/python/ZPublisher/Iterators.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2005-01-10 13:41:42 UTC (rev 28773)
+++ Zope/trunk/doc/CHANGES.txt	2005-01-10 14:16:41 UTC (rev 28774)
@@ -51,6 +51,9 @@
 
     Bugs fixed
 
+      - DTML Methods were not interoperable with the new filestream_iterator
+        and caches based on it (FileCacheManager).
+
       - Collector #1655: fixed severe memory leak in TemporaryStorage
 
       - Collector #1407: fixed XML escaping problem introduced in 2.7.4 b1

Modified: Zope/trunk/lib/python/OFS/DTMLMethod.py
===================================================================
--- Zope/trunk/lib/python/OFS/DTMLMethod.py	2005-01-10 13:41:42 UTC (rev 28773)
+++ Zope/trunk/lib/python/OFS/DTMLMethod.py	2005-01-10 14:16:41 UTC (rev 28774)
@@ -32,6 +32,7 @@
 from Cache import Cacheable
 from zExceptions import Forbidden
 from zExceptions.TracebackSupplement import PathTracebackSupplement
+from ZPublisher.Iterators import IStreamIterator
 
 _marker = []  # Create a new marker object.
 
@@ -102,6 +103,19 @@
         if not self._cache_namespace_keys:
             data = self.ZCacheable_get(default=_marker)
             if data is not _marker:
+                if ( IStreamIterator.isImplementedBy(data) and
+                     RESPONSE is not None ):
+                    # This is a stream iterator and we need to set some
+                    # headers now before giving it to medusa
+                    if RESPONSE.headers.get('content-length', None) is None:
+                        RESPONSE.setHeader('content-length', len(data))
+
+                    if ( RESPONSE.headers.get('content-type', None) is None and
+                         RESPONSE.headers.get('Content-type', None) is None ):
+                        ct = ( self.__dict__.get('content_type') or
+                               self.default_content_type )
+                        RESPONSE.setHeader('content-type', ct)
+
                 # Return cached results.
                 return data
 

Modified: Zope/trunk/lib/python/ZPublisher/Iterators.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/Iterators.py	2005-01-10 13:41:42 UTC (rev 28773)
+++ Zope/trunk/lib/python/ZPublisher/Iterators.py	2005-01-10 14:16:41 UTC (rev 28774)
@@ -20,6 +20,13 @@
         StopIeration if we've reached the end of the bytestream.
         """
 
+    def __len__(self):
+        """
+        Return an integer representing the length of the object
+        in bytes.
+        """
+
+
 class filestream_iterator(file):
     """
     a file subclass which implements an iterator that returns a
@@ -37,5 +44,11 @@
         if not data:
             raise StopIteration
         return data
+
+    def __len__(self):
+        cur_pos = self.tell()
+        self.seek(0, 2)
+        size = self.tell()
+        self.seek(cur_pos, 0)
     
-    
+        return size



More information about the Zope-Checkins mailing list