Beispiel #1
0
 def assertErrorPage(self, status, message=None, pattern=''):
     """ Compare the response body with a built in error page.
         The function will optionally look for the regexp pattern, 
         within the exception embedded in the error page.
     """
     
     from cherrypy._cputil import getErrorPage
     esc = re.escape
     # This will never contain a traceback:
     page = esc(getErrorPage(status, message=message))
     
     # First, test the response body without checking the traceback.
     # Stick a match-all group (.*) in to grab the traceback.
     page = page.replace(esc('<pre id="traceback"></pre>'),
                         esc('<pre id="traceback">') + '(.*)' + esc('</pre>'))
     m = re.match(page, self.body, re.DOTALL)
     if not m:
         self._handlewebError('Error page does not match\n' + page)
         return
     
     # Now test the pattern against the traceback
     if pattern is None:
         # Special-case None to mean that there should be *no* traceback.
         if m and m.group(1):
             self._handlewebError('Error page contains traceback')
     else:
         if (m is None) or (not re.search(pattern, m.group(1))):
             msg = 'Error page does not contain %s in traceback'
             self._handlewebError(msg % repr(pattern))
Beispiel #2
0
 def set_response(self):
     import cherrypy
     from cherrypy._cputil import getErrorPage, formatExc
     
     tb = formatExc()
     if cherrypy.config.get('server.logTracebacks', True):
         cherrypy.log(tb)
     
     defaultOn = (cherrypy.config.get('server.environment') == 'development')
     if not cherrypy.config.get('server.showTracebacks', defaultOn):
         tb = None
     
     # In all cases, finalize will be called after this method,
     # so don't bother cleaning up response values here.
     cherrypy.response.status = self.status
     cherrypy.response.body = getErrorPage(self.status, traceback=tb,
                                           message=self.message)
     
     if cherrypy.response.headerMap.has_key("Content-Encoding"):
         del cherrypy.response.headerMap['Content-Encoding']