[Zope-dev] image objects created on fly are not displayed & solution

Jephte CLAIN minf7@educ.univ-reunion.fr
Thu, 30 Mar 2000 13:48:36 +0400


This is a multi-part message in MIME format.
--------------C5AA8155EBAF1CB6FC95AEC9
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

hello,

any one who use LocalFS (on NT at least) might wonder why images served
are not displayed.
this is because image object created on fly apparently have
self._p_mtime == None (because they are not stored in ZODB I suppose)
all methods who use self._p_mtime test that case, except index_html from
lib/python/OFS/Image.py, who use:

last_mod = int(self._p_mtime)

which raise an exception when self._p_mtime is None

I include a patch which solve that problem, based on code from
bobobase_modification_time

****************************
by the way, is it possible to modify the _p_mtime attribute "by hand"?
It would be cool for the LocalFS to serve objects with _p_mtime taken
from the filesystem.

jim?

BTW, i am not on zope-dev list

regards,
jepthe clain
minf7@educ.univ-reunion.fr
--------------C5AA8155EBAF1CB6FC95AEC9
Content-Type: text/plain; charset=us-ascii;
 name="Image.py.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Image.py.patch"

--- Image.py.orig	Tue Mar 14 12:41:08 2000
+++ Image.py	Thu Mar 30 06:32:05 2000
@@ -179,12 +179,18 @@
         Returns the contents of the file or image.  Also, sets the
         Content-Type HTTP header to the objects content type.
         """
+        try:
+            last_mod = self._p_mtime
+            if last_mod is None:
+                last_mod = int(DateTime())
+        except:
+            last_mod = 0
+            
         # HTTP If-Modified-Since header handling.
         header=REQUEST.get_header('If-Modified-Since', None)
         if header is not None:
             header=string.split(header, ';')[0]
             mod_since=int(DateTime(header).timeTime())
-            last_mod =int(self._p_mtime)
             if last_mod > 0 and last_mod <= mod_since:
                 RESPONSE.setStatus(304)
                 return RESPONSE
@@ -198,7 +204,7 @@
                 c(REQUEST['PARENTS'][1],REQUEST)
             else:
                 c()
-        RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
+        RESPONSE.setHeader('Last-Modified', rfc1123_date(last_mod))
         RESPONSE.setHeader('Content-Type', self.content_type)
         RESPONSE.setHeader('Content-Length', self.size)
 

--------------C5AA8155EBAF1CB6FC95AEC9--