Using FS mtime to reload non recursive cache.
[pyTivo.git] / Cheetah / ErrorCatchers.py
blobd33b979cf5c242e8e81336617fbf37a7f2735588
1 #!/usr/bin/env python
2 # $Id: ErrorCatchers.py,v 1.7 2005/01/03 19:59:07 tavis_rudd Exp $
3 """ErrorCatcher class for Cheetah Templates
5 Meta-Data
6 ================================================================================
7 Author: Tavis Rudd <tavis@damnsimple.com>
8 Version: $Revision: 1.7 $
9 Start Date: 2001/08/01
10 Last Revision Date: $Date: 2005/01/03 19:59:07 $
11 """
12 __author__ = "Tavis Rudd <tavis@damnsimple.com>"
13 __revision__ = "$Revision: 1.7 $"[11:-2]
15 import time
16 from Cheetah.NameMapper import NotFound
18 class Error(Exception):
19 pass
21 class ErrorCatcher:
22 _exceptionsToCatch = (NotFound,)
24 def __init__(self, templateObj):
25 pass
27 def exceptions(self):
28 return self._exceptionsToCatch
30 def warn(self, exc_val, code, rawCode, lineCol):
31 return rawCode
32 ## make an alias
33 Echo = ErrorCatcher
35 class BigEcho(ErrorCatcher):
36 def warn(self, exc_val, code, rawCode, lineCol):
37 return "="*15 + "&lt;" + rawCode + " could not be found&gt;" + "="*15
39 class KeyError(ErrorCatcher):
40 def warn(self, exc_val, code, rawCode, lineCol):
41 raise KeyError("no '%s' in this Template Object's Search List" % rawCode)
43 class ListErrors(ErrorCatcher):
44 """Accumulate a list of errors."""
45 _timeFormat = "%c"
47 def __init__(self, templateObj):
48 ErrorCatcher.__init__(self, templateObj)
49 self._errors = []
51 def warn(self, exc_val, code, rawCode, lineCol):
52 dict = locals().copy()
53 del dict['self']
54 dict['time'] = time.strftime(self._timeFormat,
55 time.localtime(time.time()))
56 self._errors.append(dict)
57 return rawCode
59 def listErrors(self):
60 """Return the list of errors."""
61 return self._errors