[Zope-Checkins] CVS: Zope/lib/python/OFS - Image.py:1.145.2.5.2.2

Chris McDonough chrism at plope.com
Wed Mar 24 02:49:48 EST 2004


Update of /cvs-repository/Zope/lib/python/OFS
In directory cvs.zope.org:/tmp/cvs-serv31218

Modified Files:
      Tag: chrism-publishfile-branch
	Image.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.

Fix a bug in refactoring of range support.


=== Zope/lib/python/OFS/Image.py 1.145.2.5.2.1 => 1.145.2.5.2.2 ===
--- Zope/lib/python/OFS/Image.py:1.145.2.5.2.1	Sun Mar 21 15:40:42 2004
+++ Zope/lib/python/OFS/Image.py	Wed Mar 24 02:49:47 2004
@@ -131,7 +131,8 @@
         return self.__name__
 
     def _if_modified_since_request_handler(self, REQUEST, RESPONSE):
-        # HTTP If-Modified-Since header handling.
+        # HTTP If-Modified-Since header handling: return True if
+        # we can handle this request by returning a 304 response
         header=REQUEST.get_header('If-Modified-Since', None)
         if header is not None:
             header=header.split( ';')[0]
@@ -151,18 +152,20 @@
                 else:
                     last_mod = long(0)
                 if last_mod > 0 and last_mod <= mod_since:
-                    # Set header values since apache caching will return Content-Length
-                    # of 0 in response if size is not set here
-                    RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
+                    # Set header values since apache caching will return
+                    # Content-Length of 0 in response if size is not set here
+                    RESPONSE.setHeader('Last-Modified',
+                                       rfc1123_date(self._p_mtime))
                     RESPONSE.setHeader('Content-Type', self.content_type)
                     RESPONSE.setHeader('Content-Length', self.size)
                     RESPONSE.setHeader('Accept-Ranges', 'bytes')
                     RESPONSE.setStatus(304)
-                    self.ZCacheable_set(fcplaceholder)
+                    self.ZCacheable_set(None)
                     return True
 
     def _range_request_handler(self, REQUEST, RESPONSE):
-        # HTTP Range header handling
+        # HTTP Range header handling: return True if we've served a range
+        # chunk out of our data.
         range = REQUEST.get_header('Range', None)
         request_range = REQUEST.get_header('Request-Range', None)
         if request_range is not None:
@@ -237,6 +240,7 @@
                     data = self.data
                     if type(data) is StringType:
                         RESPONSE.write(data[start:end])
+                        return True
 
                     # Linked Pdata objects. Urgh.
                     pos = 0
@@ -362,15 +366,8 @@
         Content-Type HTTP header to the objects content type.
         """
 
-        # testing crap
-        ##         fname = '/home/chrism/bin/python'
-        ##         f = open(fname, 'rb')
-        ##         size = os.stat(fname)[stat.ST_SIZE]
-        ##         RESPONSE.setHeader('Content-Length', size)
-        ##         RESPONSE.setHeader('Content-Type', self.content_type)
-        ##         return file_producer(f)
-
         if self._if_modified_since_request_handler(REQUEST, RESPONSE):
+            # we were able to handle this by returning a 304
             return ''
 
         if self.precondition and hasattr(self, str(self.precondition)):
@@ -384,6 +381,7 @@
                 c()
 
         if self._range_request_handler(REQUEST, RESPONSE):
+            # we served a chunk of content in response to a range request.
             return ''
 
         RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
@@ -393,13 +391,21 @@
 
         if self.ZCacheable_isCachingEnabled():
             marker = []
-            result = self.ZCacheable_get(default=marker)
-            if result is not marker and result is not fcplaceholder:
-                # RAMCacheManager will return an fcplaceholder while
-                # FileCacheManager will return a file producer
+            result = self.ZCacheable_get(default=None)
+            if result is not None:
+                # We will always get None from RAMCacheManager but we will get
+                # something implementing the IZServerProducer interface
+                # from FileCacheManager.  Returning something to the publisher
+                # that implements the IZServerProducer interface (presumably
+                # wrapped around a stream or a disk file) allows us to send the
+                # content down to the client as fast as possible without the
+                # computational/IO expense of reading from the ZODB
+                # and without the computational/memory expense of reading a
+                # arbitrarily large file into memory from disk and sending it
+                # back as a huge string.
                 return result
             
-        self.ZCacheable_set(fcplaceholder)
+        self.ZCacheable_set(None)
 
         data=self.data
         if type(data) is type(''):
@@ -425,7 +431,7 @@
         if size is None: size=len(data)
         self.size=size
         self.data=data
-        self.ZCacheable_set(fcplaceholder)
+        self.ZCacheable_set(None)
         self.http__refreshEtag()
 
     def manage_edit(self, title, content_type, precondition='',
@@ -852,6 +858,3 @@
 
         return ''.join(r)
 
-class FileCachePlaceholder:
-    pass
-fcplaceholder = FileCachePlaceholder()




More information about the Zope-Checkins mailing list