"Fossies" - the Fresh Open Source Software Archive

Member "cheetah3-3.2.6.post2/Cheetah/ErrorCatchers.py" (20 Apr 2021, 1368 Bytes) of package /linux/www/cheetah3-3.2.6.post2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "ErrorCatchers.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3-3.1.0_vs_3-3.2.0.

    1 
    2 import time
    3 from Cheetah.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 # make an alias
   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  # noqa: E226,E501 missing whitespace around operator
   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