Changeset 315
- Timestamp:
- 06/15/05 00:22:47
- Files:
-
- trunk/cherrypy/_cpconfig.py (modified) (3 diffs)
- trunk/cherrypy/_cpdefaults.py (modified) (1 diff)
- trunk/cherrypy/_cphttptools.py (modified) (7 diffs)
- trunk/cherrypy/_cpwsgiserver.py (modified) (1 diff)
- trunk/cherrypy/cpg.py (modified) (1 diff)
- trunk/cherrypy/lib/filter/logdebuginfofilter.py (modified) (2 diffs)
- trunk/cherrypy/lib/filter/nsgmlsfilter.py (modified) (1 diff)
- trunk/cherrypy/lib/filter/sessionfilter/sessionfilter.py (modified) (3 diffs)
- trunk/cherrypy/test/helper.py (modified) (1 diff)
- trunk/cherrypy/test/test.py (modified) (1 diff)
- trunk/cherrypy/test/test_combinedfilters.py (modified) (1 diff)
- trunk/cherrypy/test/test_core.py (modified) (1 diff)
- trunk/cherrypy/test/test_decodingencoding_filter.py (modified) (1 diff)
- trunk/cherrypy/test/test_tutorials.py (modified) (1 diff)
- trunk/cherrypy/tutorial/tutorial.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cpconfig.py
r308 r315 1 2 import ConfigParser 3 1 4 import _cputil, cperror 2 import ConfigParser3 5 from lib import autoreload 4 6 5 7 cpg = None # delayed import 8 def init(): 9 global cpg 10 if not cpg: 11 import cpg 12 reset() 13 14 def 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. 21 configMap = {} 6 22 7 23 defaultGlobal = { … … 33 49 'sessionFilter.new': 'sessionMap', # legacy setting 34 50 } 35 configMap = {"global": defaultGlobal.copy()}36 51 37 52 def update(updateMap=None, file=None): … … 56 71 # Look, ma, no Python function calls! Uber-fast. 57 72 # start path lest you overload the starting search path (needed by getAll) 58 global cpg59 if not cpg:60 import cpg61 62 73 if startPath: 63 74 path = startPath trunk/cherrypy/_cpdefaults.py
r275 r315 63 63 def _cpOnError(): 64 64 """ 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] 70 68 cpg.response.headerMap['Content-Type'] = 'text/plain' 71 69 trunk/cherrypy/_cphttptools.py
r277 r315 31 31 """ 32 32 33 import urllib, sys, time, traceback, types, StringIO,cgi33 import urllib, sys, time, traceback, types, cgi 34 34 import mimetypes, Cookie, urlparse 35 from lib.filter import basefilter 35 36 import 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 40 import StringIO 37 41 38 42 from BaseHTTPServer import BaseHTTPRequestHandler … … 81 85 cpg.response.body = None 82 86 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() 84 88 date = ("%s, %02d %3s %4d %02d:%02d:%02d GMT" % 85 89 (weekdayname[wd], day, monthname[month], year, hh, mm, ss)) … … 152 156 cpg.request.simpleCookie.load(value) 153 157 154 # Set peer_certificate (in SSL mode) so the155 # web app can examine the client certificate156 try:157 cpg.request.peerCertificate = self.request.get_peer_certificate()158 except:159 pass160 158 msg = "%s - %s" % (cpg.request.remoteAddr, self.requestLine[:-2]) 161 159 _cputil.getSpecialAttribute('_cpLogMessage')(msg, "HTTP") … … 272 270 def main(): 273 271 """Obtain and set cpg.response.body.""" 274 path = cpg.request.path275 # Remove leading and trailing slash276 path = path.strip("/")277 # Replace quoted chars (eg %20) from url278 path = urllib.unquote(path)279 280 272 try: 281 273 func, objectPathList, virtualPathList = mapPathToObject() … … 344 336 if (cpg.config.get("server.protocolVersion") != "HTTP/1.1" 345 337 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) 351 339 cpg.response.body = [content] 352 340 cpg.response.headerMap['Content-Length'] = len(content) … … 448 436 449 437 # Try successive objects... (and also keep the remaining object list) 450 objCache = {}451 438 isFirst = True 452 439 isSecond = False 453 isDefault = False454 440 foundIt = False 455 441 virtualPathList = [] … … 469 455 if callable(candidate) and getattr(candidate, 'exposed', False): 470 456 foundIt = True 471 isDefault = True472 457 break 473 458 objectPathList.pop() # Remove "default" trunk/cherrypy/_cpwsgiserver.py
r251 r315 121 121 self.wfile.flush() 122 122 def terminate(self): 123 if not self.sent_headers: 124 self.sent_headers = True 125 self.send_headers() 123 126 self.rfile.close() 124 127 self.wfile.close() trunk/cherrypy/cpg.py
r267 r315 38 38 import _cpserver as server 39 39 import _cpconfig as config 40 config.init() 40 41 41 42 # decorator function for exposing methods trunk/cherrypy/lib/filter/logdebuginfofilter.py
r288 r315 27 27 """ 28 28 29 import time, StringIO, pickle 29 import time 30 31 try: 32 import cPickle as pickle 33 except ImportError: 34 import pickle 35 30 36 from basefilter import BaseFilter 31 37 … … 78 84 # Pickle session data to get its size 79 85 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) 84 87 logList.append("Session data size: %.02fKB" % 85 88 (len(dumpStr) / float(1024))) trunk/cherrypy/lib/filter/nsgmlsfilter.py
r297 r315 27 27 """ 28 28 29 import os, cgi , StringIO, traceback29 import os, cgi 30 30 from basefilter import BaseFilter 31 31 trunk/cherrypy/lib/filter/sessionfilter/sessionfilter.py
r311 r315 3 3 import cherrypy.cpg 4 4 5 import os.path,time, re5 import time, re 6 6 7 7 from sessionerrors import SessionNotFoundError … … 14 14 15 15 sessions = {} 16 17 path = cpg.config.get('sessionFilter.new', returnSection = True )18 paths=os.path.split(path)19 16 20 17 sessionNames = cpg.config.getAll('sessionFilter.new') … … 91 88 cookieName = cpg.config.get('%s.cookieName' % sessionName, None) 92 89 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)) 94 93 cpg.config.update({ 95 94 sessionPath : {'%s.cookieName' % sessionName : cookieName} trunk/cherrypy/test/helper.py
r267 r315 84 84 85 85 # 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 87 96 88 97 cpg.response.status = "%s %s" % (response.status, response.reason) trunk/cherrypy/test/test.py
r311 r315 178 178 # Must run each module in a separate suite, 179 179 # 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() 182 181 cpg.config.update({'global': server_conf.copy()}) 183 182 suite = CPTestLoader.loadTestsFromName(testmod) trunk/cherrypy/test/test_combinedfilters.py
r308 r315 63 63 64 64 helper.request("/", headers=[("Accept-Encoding", "gzip")]) 65 self.assert Equal(zbuf.getvalue()[:3] in cpg.response.body, True)65 self.assert_(zbuf.getvalue()[:3] in cpg.response.body) 66 66 67 67 trunk/cherrypy/test/test_core.py
r308 r315 44 44 type.__init__(name, bases, dct) 45 45 for value in dct.itervalues(): 46 if type(value) == types.FunctionType:46 if isinstance(value, types.FunctionType): 47 47 value.exposed = True 48 48 setattr(cpg.root, name.lower(), cls()) trunk/cherrypy/test/test_decodingencoding_filter.py
r308 r315 51 51 import helper 52 52 53 europoundUtf8 = u'\x80\xa3'.encode('utf-8')53 europoundUtf8 = europoundUnicode.encode('utf-8') 54 54 55 55 class DecodingEncodingFilterTest(unittest.TestCase): trunk/cherrypy/test/test_tutorials.py
r311 r315 42 42 def load_tut_module(tutorialName): 43 43 """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() 46 45 cpg.config.update({'global': server_conf.copy()}) 47 46 trunk/cherrypy/tutorial/tutorial.conf
r308 r315 4 4 server.environment = "production" 5 5 session.storageType= "ram" 6 # server.logToScreen = False

