Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 618

Show
Ignore:
Timestamp:
09/08/05 22:56:08
Author:
mikerobi
Message:

implimented most of the changes required by ticket:288

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mikerobi-experimental/cherrypy/_cpcgifs.py

    r615 r618  
    11import cgi 
    22import cherrypy 
    3  
    4 try: 
    5     from threading import local 
    6 except ImportError: 
    7     from cherrypy._cpthreadinglocal import local 
    83 
    94class LocalInt: 
     
    2419        return str(self.__local.value) 
    2520 
    26 cgi.maxlen = LocalInt(0) 
    27  
    2821class FieldStorage(cgi.FieldStorage): 
    2922    def __init__(self, *args, **kwds): 
    30         maxlen = cherrypy.config.get('server.maxRequestSize') 
    31         cgi.maxlen.setValue(maxlen) 
    3223        try: 
    3324            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 
    3630 
    3731    def read_lines_to_eof(self): 
  • branches/mikerobi-experimental/cherrypy/_cperror.py

    r615 r618  
    176176    """Exception raised when the client has made an error in its request.""" 
    177177     
    178     def __init__(self, status=400, message=_missing): 
     178    def __init__(self, status=500, body=None): 
    179179        self.status = status = int(status) 
    180180        if status < 400 or status > 599: 
     
    184184        import cherrypy 
    185185        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         
    191188    def getArgs(self): 
    192         return (self.status, self.message
     189        return (self.status, self.body
    193190 
    194191 
  • branches/mikerobi-experimental/cherrypy/_cphttptools.py

    r615 r618  
    420420        # _cpOnError and _cpOnHTTPError will probably change cherrypy.response.body. 
    421421        # 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')() 
    426423         
    427424        finalize() 
     
    461458            if not extrabody: 
    462459                extrabody = '' 
    463             status, _body = httperrors.getErrorPage(500, extrabody) 
     460            status, _body = cherrypy._cputil.getErrorPage(500, extrabody) 
    464461            headers = [('Content-Length', str(len(_body))), ('Content-Type', 'text/html')] 
    465462            return (status, headers, _body) 
  • branches/mikerobi-experimental/cherrypy/_cputil.py

    r615 r618  
    153153from cherrypy.lib import httperrors 
    154154 
    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'] 
     155def _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 
     186import BaseHTTPServer 
     187_HTTPResponses = BaseHTTPServer.BaseHTTPRequestHandler.responses 
     188 
     189def 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 
    165201 
    166202def formatExc(exc=None): 
     
    172208def _cpOnError(): 
    173209    """ 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 
    174226    developmentMode = cherrypy.config.get('server.environment') == 'development' 
    175227    httpErrors      = cherrypy.config.get('server.httpErrors') 
     
    191243        response.headerMap['Content-Type'] = 'text/plain' 
    192244    else: 
     245        # why did i put this there? 
     246 
    193247        # 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" 
    195250        response.body = "Unrecoverable error in the server" 
    196251        response.headerMap['Content-Type'] = 'text/plain' 
  • branches/mikerobi-experimental/cherrypy/server.py

    r615 r618  
    9393        and cherrypy.config.get('session.storageType') == 'file'): 
    9494        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') 
    9599     
    96100    # Call the functions from cherrypy.server.onStartServerList 

Hosted by WebFaction

Log in as guest/cpguest to create tickets