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

Changeset 309

Show
Ignore:
Timestamp:
06/14/05 12:45:20
Author:
fumanchu
Message:

1. Fixed bug in wsgi server, where headers would not be written if .write was never called (which happened with zero-length bodies).
2. Changed StringIO to "".join where possible.
3. test/helper.py now handles BadStatusLine? errors better.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/ooconf/cherrypy/_cpdefaults.py

    r307 r309  
    3333 
    3434import time, thread, os 
    35 try: 
    36     import cStringIO as StringIO 
    37 except ImportError: 
    38     import StringIO 
    3935import cPickle as pickle 
    4036import cpg 
     
    6763def _cpOnError(): 
    6864    """ Default _cpOnError method """ 
    69  
    70     import traceback 
    71     bodyFile = StringIO.StringIO() 
    72     traceback.print_exc(file = bodyFile) 
    73     cpg.response.body = [bodyFile.getvalue()] 
     65    import sys, traceback 
     66    content = "".join(traceback.format_exception(*sys.exc_info())) 
     67    cpg.response.body = [content] 
    7468    cpg.response.headerMap['Content-Type'] = 'text/plain' 
    7569 
  • branches/ooconf/cherrypy/_cphttptools.py

    r307 r309  
    3535import cpg, _cputil, cperror, _cpdefaults 
    3636 
    37 try: 
    38     import cStringIO as StringIO 
    39 except ImportError: 
    40     import StringIO 
     37# Can't use cStringIO; doesn't support unicode strings 
     38# See http://www.python.org/sf/216388 
     39import StringIO 
    4140 
    4241from BaseHTTPServer import BaseHTTPRequestHandler 
     
    395394def finalize(): 
    396395    """Transform headerMap + cookies into cpg.response.headers.""" 
    397      
    398396    checkStatus() 
    399397     
    400398    if (cpg.config.get("server.protocolVersion") != "HTTP/1.1" 
    401399        and cpg.response.headerMap.get('Content-Length') == 0): 
    402         buf = StringIO.StringIO() 
    403         for chunk in cpg.response.body: 
    404             buf.write(chunk) 
    405         buf.seek(0) 
    406         content = buf.read() 
    407         cpg.response.body = [content] 
     400        cpg.response.body = content = ''.join(cpg.response.body) 
    408401        cpg.response.headerMap['Content-Length'] = len(content) 
    409402     
  • branches/ooconf/cherrypy/_cpwsgiserver.py

    r251 r309  
    121121        self.wfile.flush() 
    122122    def terminate(self): 
     123        if not self.sent_headers: 
     124            self.sent_headers = True 
     125            self.send_headers() 
    123126        self.rfile.close() 
    124127        self.wfile.close() 
  • branches/ooconf/cherrypy/lib/filter/logdebuginfofilter.py

    r307 r309  
    2727""" 
    2828 
    29 import time, pickle 
     29import time 
    3030 
    3131try: 
    32     import cStringIO as StringIO 
     32    import cPickle as pickle 
    3333except ImportError: 
    34     import StringIO 
     34    import pickle 
     35 
    3536 
    3637 
     
    7273                # Pickle session data to get its size 
    7374                try: 
    74                     f = StringIO.StringIO() 
    75                     pickle.dump(cpg.request.sessionMap, f, 1) 
    76                     dumpStr = f.getvalue() 
    77                     f.close() 
     75                    dumpStr = pickle.dumps(cpg.request.sessionMap, 1) 
    7876                    logList.append("Session data size: %.02fKB" % 
    7977                                   (len(dumpStr) / float(1024))) 
  • branches/ooconf/cherrypy/lib/filter/tidyfilter.py

    r307 r309  
    2828 
    2929import os, cgi, traceback 
    30  
    31 try: 
    32     import cStringIO as StringIO 
    33 except ImportError: 
    34     import StringIO 
     30import StringIO 
    3531 
    3632 
  • branches/ooconf/cherrypy/test/helper.py

    r267 r309  
    8484             
    8585            # Handle response 
    86             response = conn.getresponse() 
     86            try: 
     87                response = conn.getresponse() 
     88            except httplib.BadStatusLine: 
     89                # Improper response from server. 
     90                print 
     91                print "Server did not return a response." 
     92                print "status>", repr(cpg.response.status) 
     93                print "headers>", repr(cpg.response.headers) 
     94                print "body>", repr(cpg.response.body) 
     95                raise 
    8796             
    8897            cpg.response.status = "%s %s" % (response.status, response.reason) 
  • branches/ooconf/cherrypy/test/test.py

    r306 r309  
    166166                   } 
    167167     
    168     for name, server in [("Serverless", None), 
     168    for name, server in [ 
     169                         ("Serverless", None), 
    169170                         ("Native HTTP Server", "cherrypy._cphttpserver.embedded_server"), 
    170171                         ("Native WSGI Server", "cherrypy._cpwsgi.WSGIServer"), 

Hosted by WebFaction

Log in as guest/cpguest to create tickets