def getHtmlMessage(self): from muntjac.terminal.gwt.server.abstract_application_servlet \ import AbstractApplicationServlet sb = StringIO() message = self.message if message is not None: sb.write('<h2>') sb.write(AbstractApplicationServlet.safeEscapeForHtml(message)) sb.write('</h2>') # Paint the exception if self._cause is not None: sb.write('<h3>Exception</h3>') buff = StringIO() exc_type, _, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, self._cause, exc_traceback, file=buff) sb.write('<pre>') pre = buff.getvalue() sb.write(AbstractApplicationServlet.safeEscapeForHtml(pre)) buff.close() sb.write('</pre>') result = sb.getvalue() sb.close() return result
def paint(self, target): target.startTag('error') # Error level if self._level >= IErrorMessage.SYSTEMERROR: target.addAttribute('level', 'system') elif self._level >= IErrorMessage.CRITICAL: target.addAttribute('level', 'critical') elif self._level >= IErrorMessage.ERROR: target.addAttribute('level', 'error') elif self._level >= IErrorMessage.WARNING: target.addAttribute('level', 'warning') else: target.addAttribute('level', 'info') # Paint the message if self._mode == self.CONTENT_TEXT: escaped = AbstractApplicationServlet.safeEscapeForHtml(self._msg) target.addText(escaped) elif self._mode == self.CONTENT_UIDL: target.addUIDL( "<pre>" + AbstractApplicationServlet.safeEscapeForHtml(self._msg) + "</pre>") elif self._mode == self.CONTENT_PREFORMATTED: target.startTag('pre') target.addText(self._msg) target.endTag('pre') target.endTag('error')
def paint(self, target): target.startTag('error') # Error level if self._level >= IErrorMessage.SYSTEMERROR: target.addAttribute('level', 'system') elif self._level >= IErrorMessage.CRITICAL: target.addAttribute('level', 'critical') elif self._level >= IErrorMessage.ERROR: target.addAttribute('level', 'error') elif self._level >= IErrorMessage.WARNING: target.addAttribute('level', 'warning') else: target.addAttribute('level', 'info') # Paint the message if self._mode == self.CONTENT_TEXT: escaped = AbstractApplicationServlet.safeEscapeForHtml(self._msg) target.addText(escaped) elif self._mode == self.CONTENT_UIDL: target.addUIDL("<pre>" + AbstractApplicationServlet.safeEscapeForHtml(self._msg) + "</pre>") elif self._mode == self.CONTENT_PREFORMATTED: target.startTag('pre') target.addText(self._msg) target.endTag('pre') target.endTag('error')
def getHtmlMessage(self): """Returns the message of the error in HTML. Note that this API may change in future versions. """ return AbstractApplicationServlet.safeEscapeForHtml(self.message)