Changeset 884
- Timestamp:
- 12/27/05 18:20:54
- Files:
-
- trunk/cherrypy/_cphttpserver.py (modified) (2 diffs)
- trunk/cherrypy/_cphttptools.py (modified) (1 diff)
- trunk/cherrypy/_cpwsgi.py (modified) (3 diffs)
- trunk/cherrypy/test/helper.py (modified) (2 diffs)
- trunk/cherrypy/test/test.py (modified) (1 diff)
- trunk/cherrypy/test/test_core.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cphttpserver.py
r873 r884 6 6 import socket 7 7 import SocketServer 8 import sys 8 9 import threading 9 10 import time … … 90 91 tb = _cputil.formatExc() 91 92 cherrypy.log(tb) 92 if not cherrypy.config.get("server.show_tracebacks", False): 93 tb = "" 94 s, h, b = _cputil.bareError(tb) 93 if cherrypy.config.get("server.throw_errors", False): 94 msg = "THROWN ERROR: %s" % sys.exc_info()[0].__name__ 95 s = "500 Internal Server Error" 96 h = [('Content-Type', 'text/plain'), 97 ('Content-Length', str(len(msg)))] 98 b = [msg] 99 else: 100 if not cherrypy.config.get("server.show_tracebacks", False): 101 tb = "" 102 s, h, b = _cputil.bareError(tb) 95 103 96 104 try: trunk/cherrypy/_cphttptools.py
r879 r884 115 115 raise 116 116 except: 117 if cherrypy.config.get("server.throw_errors", False): 118 raise 117 119 cherrypy.response.handleError(sys.exc_info()) 118 120 trunk/cherrypy/_cpwsgi.py
r856 r884 78 78 raise 79 79 except: 80 if cherrypy.config.get("server.throw_errors", False): 81 raise 80 82 tb = _cputil.formatExc() 81 83 cherrypy.log(tb) … … 170 172 RequestHandlerClass = CPHTTPRequest 171 173 172 def __init__(self ):174 def __init__(self, app=wsgiApp): 173 175 conf = cherrypy.config.get 174 176 … … 180 182 181 183 s = _cpwsgiserver.CherryPyWSGIServer 182 s.__init__(self, bind_addr, wsgiApp,184 s.__init__(self, bind_addr, app, 183 185 conf("server.thread_pool"), 184 186 conf("server.socket_host"), trunk/cherrypy/test/helper.py
r877 r884 29 29 30 30 import cherrypy 31 from cherrypy import _cpwsgi 31 32 import webtest 32 33 … … 56 57 ##vroot = "/vpath" 57 58 test_vrf = VirtualRootFilter(vroot) 59 60 61 def error_middleware(environ, start_response): 62 started = [False] 63 def start(s, h, exc=None): 64 started[0] = True 65 start_response(s, h, exc) 66 67 try: 68 for chunk in _cpwsgi.wsgiApp(environ, start): 69 yield chunk 70 except (KeyboardInterrupt, SystemExit): 71 raise 72 except Exception, x: 73 # We should only reach this point if server.throw_errors is True. 74 if not started[0]: 75 start_response("500 Server Error", []) 76 yield "THROWN ERROR: %s" % x.__class__.__name__ 77 78 79 class TestWSGI(_cpwsgi.WSGIServer): 80 """Wrapper for WSGI server so we can test thrown errors.""" 81 82 def __init__(self): 83 _cpwsgi.WSGIServer.__init__(self, error_middleware) 58 84 59 85 trunk/cherrypy/test/test.py
r883 r884 26 26 "cherrypy._cphttpserver.embedded_server"), 27 27 'wsgi': (2, "Native WSGI Server", 28 "cherrypy. _cpwsgi.WSGIServer"),28 "cherrypy.test.helper.TestWSGI"), 29 29 } 30 30 default_server = "wsgi" trunk/cherrypy/test/test_core.py
r879 r884 192 192 def log_unhandled(self): 193 193 raise ValueError() 194 195 def rethrow(self): 196 """Test that an error raised here will be thrown out to the server.""" 197 raise ValueError() 194 198 195 199 … … 392 396 'server.log_tracebacks': False, 393 397 'server.log_unhandled_tracebacks': True, 398 }, 399 '/error/rethrow': { 400 'server.throw_errors': True, 394 401 }, 395 402 '/cpfilterlist/errinstream': { … … 691 698 "[Errno 2] No such file or directory: 'nonexistent.html'") 692 699 self.assertInBody(msg) 700 701 # Test server.throw_errors (ticket #186). 702 httpcls = cherrypy.server.httpserverclass 703 if httpcls: 704 self.getPage("/error/rethrow") 705 self.assertBody("THROWN ERROR: ValueError") 706 else: 707 self.assertRaises(ValueError, self.getPage, "/error/rethrow") 693 708 694 709 def testRanges(self):

