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

Changeset 315

Show
Ignore:
Timestamp:
06/15/05 00:22:47
Author:
fumanchu
Message:

Merged some useful updates from /branches/ooconf. Mostly speed tweaks, and removing some dead code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cpconfig.py

    r308 r315  
     1 
     2import ConfigParser 
     3 
    14import _cputil, cperror 
    2 import ConfigParser 
    35from lib import autoreload 
    46 
    57cpg = None # delayed import 
     8def init(): 
     9    global cpg 
     10    if not cpg: 
     11        import cpg 
     12    reset() 
     13 
     14def reset(useDefaults=True): 
     15    configMap.clear() 
     16    if useDefaults: 
     17        configMap["global"] = defaultGlobal.copy() 
     18 
     19# This configMap dict holds the settings metadata for all cpg objects. 
     20# Keys are URL paths, and values are dicts. 
     21configMap = {} 
    622 
    723defaultGlobal = { 
     
    3349    'sessionFilter.new': 'sessionMap', # legacy setting 
    3450    } 
    35 configMap = {"global": defaultGlobal.copy()} 
    3651 
    3752def update(updateMap=None, file=None): 
     
    5671    # Look, ma, no Python function calls! Uber-fast. 
    5772    # start path lest you overload the starting search path (needed by getAll) 
    58     global cpg 
    59     if not cpg: 
    60         import cpg 
    61      
    6273    if startPath: 
    6374        path = startPath 
  • trunk/cherrypy/_cpdefaults.py

    r275 r315  
    6363def _cpOnError(): 
    6464    """ Default _cpOnError method """ 
    65  
    66     import traceback, StringIO 
    67     bodyFile = StringIO.StringIO() 
    68     traceback.print_exc(file = bodyFile) 
    69     cpg.response.body = [bodyFile.getvalue()] 
     65    import sys, traceback 
     66    content = "".join(traceback.format_exception(*sys.exc_info())) 
     67    cpg.response.body = [content] 
    7068    cpg.response.headerMap['Content-Type'] = 'text/plain' 
    7169 
  • trunk/cherrypy/_cphttptools.py

    r277 r315  
    3131""" 
    3232 
    33 import urllib, sys, time, traceback, types, StringIO, cgi 
     33import urllib, sys, time, traceback, types, cgi 
    3434import mimetypes, Cookie, urlparse 
     35from lib.filter import basefilter 
    3536import cpg, _cputil, cperror, _cpdefaults 
    36 from lib.filter import basefilter 
     37 
     38# Can't use cStringIO; doesn't support unicode strings   
     39# See http://www.python.org/sf/216388   
     40import StringIO 
    3741 
    3842from BaseHTTPServer import BaseHTTPRequestHandler 
     
    8185        cpg.response.body = None 
    8286         
    83         year, month, day, hh, mm, ss, wd, y, z = time.gmtime(time.time()
     87        year, month, day, hh, mm, ss, wd, y, z = time.gmtime(
    8488        date = ("%s, %02d %3s %4d %02d:%02d:%02d GMT" % 
    8589                (weekdayname[wd], day, monthname[month], year, hh, mm, ss)) 
     
    152156                cpg.request.simpleCookie.load(value) 
    153157         
    154         # Set peer_certificate (in SSL mode) so the 
    155         # web app can examine the client certificate 
    156         try: 
    157             cpg.request.peerCertificate = self.request.get_peer_certificate() 
    158         except: 
    159             pass 
    160158        msg = "%s - %s" % (cpg.request.remoteAddr, self.requestLine[:-2]) 
    161159        _cputil.getSpecialAttribute('_cpLogMessage')(msg, "HTTP") 
     
    272270def main(): 
    273271    """Obtain and set cpg.response.body.""" 
    274     path = cpg.request.path 
    275     # Remove leading and trailing slash 
    276     path = path.strip("/") 
    277     # Replace quoted chars (eg %20) from url 
    278     path = urllib.unquote(path) 
    279      
    280272    try: 
    281273        func, objectPathList, virtualPathList = mapPathToObject() 
     
    344336    if (cpg.config.get("server.protocolVersion") != "HTTP/1.1" 
    345337        and cpg.response.headerMap.get('Content-Length') == 0): 
    346         buf = StringIO.StringIO() 
    347         for chunk in cpg.response.body: 
    348             buf.write(chunk) 
    349         buf.seek(0) 
    350         content = buf.read() 
     338        content = ''.join(cpg.response.body) 
    351339        cpg.response.body = [content] 
    352340        cpg.response.headerMap['Content-Length'] = len(content) 
     
    448436     
    449437    # Try successive objects... (and also keep the remaining object list) 
    450     objCache = {} 
    451438    isFirst = True 
    452439    isSecond = False 
    453     isDefault = False 
    454440    foundIt = False 
    455441    virtualPathList = [] 
     
    469455            if callable(candidate) and getattr(candidate, 'exposed', False): 
    470456                foundIt = True 
    471                 isDefault = True 
    472457                break 
    473458            objectPathList.pop() # Remove "default" 
  • trunk/cherrypy/_cpwsgiserver.py

    r251 r315  
    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() 
  • trunk/cherrypy/cpg.py

    r267 r315  
    3838import _cpserver as server 
    3939import _cpconfig as config 
     40config.init() 
    4041 
    4142# decorator function for exposing methods 
  • trunk/cherrypy/lib/filter/logdebuginfofilter.py

    r288 r315  
    2727""" 
    2828 
    29 import time, StringIO, pickle 
     29import time 
     30 
     31try: 
     32    import cPickle as pickle 
     33except ImportError: 
     34    import pickle 
     35 
    3036from basefilter import BaseFilter 
    3137 
     
    7884                # Pickle session data to get its size 
    7985                try: 
    80                     f = StringIO.StringIO() 
    81                     pickle.dump(cpg.request.sessionMap, f, 1) 
    82                     dumpStr = f.getvalue() 
    83                     f.close() 
     86                    dumpStr = pickle.dumps(cpg.request.sessionMap, 1) 
    8487                    logList.append("Session data size: %.02fKB" % 
    8588                                   (len(dumpStr) / float(1024))) 
  • trunk/cherrypy/lib/filter/nsgmlsfilter.py

    r297 r315  
    2727""" 
    2828 
    29 import os, cgi, StringIO, traceback 
     29import os, cgi 
    3030from basefilter import BaseFilter 
    3131 
  • trunk/cherrypy/lib/filter/sessionfilter/sessionfilter.py

    r311 r315  
    33import cherrypy.cpg 
    44 
    5 import os.path, time, re 
     5import time, re 
    66 
    77from sessionerrors import SessionNotFoundError  
     
    1414     
    1515    sessions = {} 
    16      
    17     path = cpg.config.get('sessionFilter.new', returnSection = True ) 
    18     paths=os.path.split(path) 
    1916     
    2017    sessionNames = cpg.config.getAll('sessionFilter.new') 
     
    9188            cookieName = cpg.config.get('%s.cookieName' % sessionName, None) 
    9289            if not cookieName: 
    93                 cookieName = cpg.config.get('sessionFilter.cookieName') + '|' + sessionName + '|' + re.sub('/','_', sessionPath) 
     90                cookieName = (cpg.config.get('sessionFilter.cookieName') + 
     91                              '|' + sessionName + 
     92                              '|' + re.sub('/','_', sessionPath)) 
    9493                cpg.config.update({ 
    9594                                    sessionPath : {'%s.cookieName' % sessionName : cookieName} 
  • trunk/cherrypy/test/helper.py

    r267 r315  
    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) 
  • trunk/cherrypy/test/test.py

    r311 r315  
    178178            # Must run each module in a separate suite, 
    179179            # because each module uses/overwrites cpg globals. 
    180             cpg.config.configMap.clear() 
    181             cpg.config.configMap["global"] = cpg.config.defaultGlobal.copy() 
     180            cpg.config.reset() 
    182181            cpg.config.update({'global': server_conf.copy()}) 
    183182            suite = CPTestLoader.loadTestsFromName(testmod) 
  • trunk/cherrypy/test/test_combinedfilters.py

    r308 r315  
    6363         
    6464        helper.request("/", headers=[("Accept-Encoding", "gzip")]) 
    65         self.assertEqual(zbuf.getvalue()[:3] in cpg.response.body, True
     65        self.assert_(zbuf.getvalue()[:3] in cpg.response.body
    6666 
    6767 
  • trunk/cherrypy/test/test_core.py

    r308 r315  
    4444        type.__init__(name, bases, dct) 
    4545        for value in dct.itervalues(): 
    46             if type(value) == types.FunctionType
     46            if isinstance(value, types.FunctionType)
    4747                value.exposed = True 
    4848        setattr(cpg.root, name.lower(), cls()) 
  • trunk/cherrypy/test/test_decodingencoding_filter.py

    r308 r315  
    5151import helper 
    5252 
    53 europoundUtf8 = u'\x80\xa3'.encode('utf-8') 
     53europoundUtf8 = europoundUnicode.encode('utf-8') 
    5454 
    5555class DecodingEncodingFilterTest(unittest.TestCase): 
  • trunk/cherrypy/test/test_tutorials.py

    r311 r315  
    4242def load_tut_module(tutorialName): 
    4343    """Import or reload tutorial module as needed.""" 
    44     cpg.config.configMap.clear() 
    45     cpg.config.configMap["global"] = cpg.config.defaultGlobal.copy() 
     44    cpg.config.reset() 
    4645    cpg.config.update({'global': server_conf.copy()}) 
    4746     
  • trunk/cherrypy/tutorial/tutorial.conf

    r308 r315  
    44server.environment = "production" 
    55session.storageType= "ram" 
     6# server.logToScreen = False 

Hosted by WebFaction

Log in as guest/cpguest to create tickets