Changeset 618
- Timestamp:
- 09/08/05 22:56:08
- Files:
-
- branches/mikerobi-experimental/cherrypy/_cpcgifs.py (modified) (2 diffs)
- branches/mikerobi-experimental/cherrypy/_cperror.py (modified) (2 diffs)
- branches/mikerobi-experimental/cherrypy/_cphttptools.py (modified) (2 diffs)
- branches/mikerobi-experimental/cherrypy/_cputil.py (modified) (3 diffs)
- branches/mikerobi-experimental/cherrypy/lib/httperrors.py (deleted)
- branches/mikerobi-experimental/cherrypy/server.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/mikerobi-experimental/cherrypy/_cpcgifs.py
r615 r618 1 1 import cgi 2 2 import cherrypy 3 4 try:5 from threading import local6 except ImportError:7 from cherrypy._cpthreadinglocal import local8 3 9 4 class LocalInt: … … 24 19 return str(self.__local.value) 25 20 26 cgi.maxlen = LocalInt(0)27 28 21 class FieldStorage(cgi.FieldStorage): 29 22 def __init__(self, *args, **kwds): 30 maxlen = cherrypy.config.get('server.maxRequestSize')31 cgi.maxlen.setValue(maxlen)32 23 try: 33 24 cgi.FieldStorage.__init__(self, *args, **kwds) 34 except ValueError: 35 raise cherrypy.HTTPStatusError(status=413) 25 except ValueError, ex: 26 if str(ex) == 'Maximum content length exceeded': 27 raise cherrypy.HTTPStatusError(status=413) 28 else: 29 raise ex 36 30 37 31 def read_lines_to_eof(self): branches/mikerobi-experimental/cherrypy/_cperror.py
r615 r618 176 176 """Exception raised when the client has made an error in its request.""" 177 177 178 def __init__(self, status= 400, message=_missing):178 def __init__(self, status=500, body=None): 179 179 self.status = status = int(status) 180 180 if status < 400 or status > 599: … … 184 184 import cherrypy 185 185 cherrypy.response.status = status 186 if message is not _missing: 187 cherrypy.response.body=message 188 189 self.message = message 190 186 self.body = body 187 191 188 def getArgs(self): 192 return (self.status, self. message)189 return (self.status, self.body) 193 190 194 191 branches/mikerobi-experimental/cherrypy/_cphttptools.py
r615 r618 420 420 # _cpOnError and _cpOnHTTPError will probably change cherrypy.response.body. 421 421 # They may also change the headerMap, etc. 422 if sys.exc_info()[0] is cherrypy.HTTPStatusError: 423 _cputil.getSpecialAttribute('_cpOnHTTPError')() 424 else: 425 _cputil.getSpecialAttribute('_cpOnError')() 422 _cputil.getSpecialAttribute('_cpOnError')() 426 423 427 424 finalize() … … 461 458 if not extrabody: 462 459 extrabody = '' 463 status, _body = httperrors.getErrorPage(500, extrabody)460 status, _body = cherrypy._cputil.getErrorPage(500, extrabody) 464 461 headers = [('Content-Length', str(len(_body))), ('Content-Type', 'text/html')] 465 462 return (status, headers, _body) branches/mikerobi-experimental/cherrypy/_cputil.py
r615 r618 153 153 from cherrypy.lib import httperrors 154 154 155 def _cpOnHTTPError(): 156 """ Default _cpOnHTTPError method """ 157 status, customMessage = sys.exc_info()[1].getArgs() 158 159 # get the error mage 160 page = httperrors.getErrorPage(status, customMessage = customMessage) 161 cherrypy.response.status, cherrypy.response.body = page 162 163 if cherrypy.response.headerMap.has_key('Content-Encoding'): 164 del cherrypy.response.headerMap['Content-Encoding'] 155 def _HTTPErrorTemplate(errorString, message, traceback, version): 156 subTuple = (errorString, errorString, message, traceback, cherrypy.__version__) 157 158 return '''<?xml version="1.0" encoding="UTF-8"?> 159 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 160 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 161 <html> 162 <head> 163 <title>%s</title> 164 <style type="text/css"> 165 .poweredBy { 166 margin-top: 20px; 167 border-top: 2px solid black; 168 } 169 170 #traceback { 171 color: red; 172 } 173 </style> 174 </head> 175 <body> 176 <h2>%s</h2> 177 <p>%s</p> 178 <pre id="traceback">%s</pre> 179 <div class="poweredBy"> 180 <span>Powered by <a href="http://www.cherrypy.org">Cherrypy %s</a></span> 181 </div> 182 </body> 183 </html> 184 ''' % subTuple 185 186 import BaseHTTPServer 187 _HTTPResponses = BaseHTTPServer.BaseHTTPRequestHandler.responses 188 189 def getErrorPage(status, traceback = None): 190 statusString, message = _HTTPResponses[status] 191 statusString = '%d %s' % (status, statusString) 192 193 if traceback == None: 194 # get the traceback from formatExc 195 defaultOn = (cherrypy.config.get('server.environment') == 'development') 196 if cherrypy.config.get('server.showTracebacks', defaultOn): 197 traceback = cherrypy._cputil.formatExc() 198 page = _errorTemplate(statusString, message, traceback, cherrypy.__version__) 199 200 return statusString, page 165 201 166 202 def formatExc(exc=None): … … 172 208 def _cpOnError(): 173 209 """ Default _cpOnError method """ 210 211 if sys.exc_info()[0] is cherrypy.HTTPStatusError: 212 status, body = sys.exc_info()[1].getArgs() 213 214 # get the error mage 215 if not body: 216 status, body = httperrors.getErrorPage(status) 217 218 response = cherrypy.response 219 response.status, cherrypy.response.body = status, body 220 221 if response.headerMap.has_key('Content-Encoding'): 222 del response.headerMap['Content-Encoding'] 223 224 return 225 174 226 developmentMode = cherrypy.config.get('server.environment') == 'development' 175 227 httpErrors = cherrypy.config.get('server.httpErrors') … … 191 243 response.headerMap['Content-Type'] = 'text/plain' 192 244 else: 245 # why did i put this there? 246 193 247 # If it is production mode but http errors are disabled then 194 # Display a simple, generic error message 248 # Return generic internal error 249 response.status = "500 Internal Error" 195 250 response.body = "Unrecoverable error in the server" 196 251 response.headerMap['Content-Type'] = 'text/plain' branches/mikerobi-experimental/cherrypy/server.py
r615 r618 93 93 and cherrypy.config.get('session.storageType') == 'file'): 94 94 cherrypy._sessionFileLock = threading.RLock() 95 96 # set cgi.maxlen which will limit the size of POST request bodies 97 import cgi 98 cgi.maxlen = cherrypy.config.get('server.maxRequestSize') 95 99 96 100 # Call the functions from cherrypy.server.onStartServerList

