Re: [Zope-dev] bad bare except in PageTemplateFile.py

2002-07-18 Thread Steve Alexander

Shane Hathaway wrote:
 
 os.stat() raises OSError if the file is not found, in which case mtime 
 should be set to 0.

Surely if the file is not found, that's an error because the 
PageTemplateFile is pointing at a source file that doesn't exist.

I cannot think of any reason I'd want not to be informed that the source 
file for a PageTemplateFile isn't there. That's clearly a programming error.

So, I suggest removing the try: except: clause entirely, and letting 
os.stat() raise its error.

Or, am I missing something here?

--
Steve Alexander



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] bad bare except in PageTemplateFile.py

2002-07-18 Thread Steve Alexander

Shane Hathaway wrote:
 
 I vaguely recall having a similar discussion with someone regarding 
 DTMLFile, and we decided it had to ignore missing files, but I don't 
 remember why.

Darn... that'll be just the reason I'm looking for!


 Also, the open() call just below that line will raise an 
 equivalent exception.

For some reason, the code was not getting there when I came across this 
problem. I guess this 'if' expression must have evaluated true.

 if hasattr(self, '_v_program') and mtime == self._v_last_read:
 return

I'm not sure why it would have done so though.

--
Steve Alexander



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] bad bare except in PageTemplateFile.py

2002-07-18 Thread Casey Duncan

My guess would be that it would get an OSError possible IndexError, but I'm 
not sure the logic in just setting the mtime to null and continuing. 
especially since it will likely just try and fail to open the file a few 
lines later...

This could actually be simplified to:

try: 
mtime = os.path.getmtime(self.filename)
except OSError: 
mtime = 0

-Casey

On Wednesday 17 July 2002 07:08 pm, Steve Alexander wrote:
 lib/python/Products/PageTemplateFile.py, line 110, method _cook_check
 
  try:mtime=os.stat(self.filename)[8]
  except: mtime=0
 
 
 I've just spent an hour or so tracking down an awkward bug in some 
 unit-tests. The true error was being hidden by this bare except.
 
 I'd change it, and commit the change, except that I don't know what it 
 is supposed to be catching. Any hints?
 
 Actually, I'd rather just remove the try: except: and let os.stat fail 
 if it is going to fail. Any objections?
 
 (of course there will be... even bare excepts were put there for some 
 reason...)
 
 --
 Steve Alexander




___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] bad bare except in PageTemplateFile.py

2002-07-18 Thread Shane Hathaway

Steve Alexander wrote:
 Shane Hathaway wrote:
 

 os.stat() raises OSError if the file is not found, in which case mtime 
 should be set to 0.
 
 
 Surely if the file is not found, that's an error because the 
 PageTemplateFile is pointing at a source file that doesn't exist.
 
 I cannot think of any reason I'd want not to be informed that the source 
 file for a PageTemplateFile isn't there. That's clearly a programming 
 error.
 
 So, I suggest removing the try: except: clause entirely, and letting 
 os.stat() raise its error.
 
 Or, am I missing something here?

I vaguely recall having a similar discussion with someone regarding 
DTMLFile, and we decided it had to ignore missing files, but I don't 
remember why.  Also, the open() call just below that line will raise an 
equivalent exception.  Use your judgment--mine is clouded. :-)

Shane



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] bad bare except in PageTemplateFile.py

2002-07-18 Thread Shane Hathaway

Steve Alexander wrote:
 lib/python/Products/PageTemplateFile.py, line 110, method _cook_check
 
 try:mtime=os.stat(self.filename)[8]
 except: mtime=0
 
 
 I've just spent an hour or so tracking down an awkward bug in some 
 unit-tests. The true error was being hidden by this bare except.
 
 I'd change it, and commit the change, except that I don't know what it 
 is supposed to be catching. Any hints?

os.stat() raises OSError if the file is not found, in which case mtime 
should be set to 0.  There are several ways to fix this; use your 
judgment. :-)

BTW this little idiom is found all over the place, including CMF.

Shane



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )