image objects created on fly are not displayed & solution
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 --- 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)
1) The _p_mtime == None bug in Image.py is fixed in CVS. 2) I have fixed LocalFS to set _p_mtime correctly from the modification time of the local file. This fix will be in the next release. 3) It is not possible to modify _p_mtime directly, but it is computed from _p_serial which is writable. The code I use is basically: import os, stat, time from ZODB.TimeStamp import TimeStamp def set_mtime(ob, path): t = os.stat(path)[stat.ST_MTIME] ts = apply(TimeStamp, time.gmtime(t)[:6]) ob._p_serial = repr(ts) Hope this helps. -jfarr ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hi! I'm a signature virus. Copy me into your .sig to join the fun! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ----- Original Message ----- From: Jephte CLAIN <minf7@educ.univ-reunion.fr> To: <zope-dev@zope.org>; <minf7@educ.univ-reunion.fr> Sent: Thursday, March 30, 2000 1:48 AM Subject: [Zope-dev] image objects created on fly are not displayed & solution
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
participants (2)
-
Jephte CLAIN -
Jonothan Farr