| 1 |
|
| 2 |
import time |
| 3 |
from .NameMapper import NotFound |
| 4 |
|
| 5 |
|
| 6 |
class Error(Exception): |
| 7 |
pass |
| 8 |
|
| 9 |
|
| 10 |
class ErrorCatcher: |
| 11 |
_exceptionsToCatch = (NotFound,) |
| 12 |
|
| 13 |
def __init__(self, templateObj): |
| 14 |
pass |
| 15 |
|
| 16 |
def exceptions(self): |
| 17 |
return self._exceptionsToCatch |
| 18 |
|
| 19 |
def warn(self, exc_val, code, rawCode, lineCol): |
| 20 |
return rawCode |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
Echo = ErrorCatcher |
| 25 |
|
| 26 |
|
| 27 |
class BigEcho(ErrorCatcher): |
| 28 |
def warn(self, exc_val, code, rawCode, lineCol): |
| 29 |
return "="*15 + "<" + rawCode + " could not be found>" + "="*15 |
| 30 |
|
| 31 |
|
| 32 |
class KeyError(ErrorCatcher): |
| 33 |
def warn(self, exc_val, code, rawCode, lineCol): |
| 34 |
raise KeyError( |
| 35 |
"no '%s' in this Template Object's Search List" % rawCode) |
| 36 |
|
| 37 |
|
| 38 |
class ListErrors(ErrorCatcher): |
| 39 |
"""Accumulate a list of errors.""" |
| 40 |
_timeFormat = "%c" |
| 41 |
|
| 42 |
def __init__(self, templateObj): |
| 43 |
ErrorCatcher.__init__(self, templateObj) |
| 44 |
self._errors = [] |
| 45 |
|
| 46 |
def warn(self, exc_val, code, rawCode, lineCol): |
| 47 |
dict = locals().copy() |
| 48 |
del dict['self'] |
| 49 |
dict['time'] = time.strftime(self._timeFormat, |
| 50 |
time.localtime(time.time())) |
| 51 |
self._errors.append(dict) |
| 52 |
return rawCode |
| 53 |
|
| 54 |
def listErrors(self): |
| 55 |
"""Return the list of errors.""" |
| 56 |
return self._errors |