Changeset 522
- Timestamp:
- 08/09/05 16:00:58
- Files:
-
- trunk/cherrypy/_cphttptools.py (modified) (9 diffs)
- trunk/cherrypy/_cputil.py (modified) (1 diff)
- trunk/cherrypy/config.py (modified) (3 diffs)
- trunk/cherrypy/lib/covercp.py (modified) (1 diff)
- trunk/cherrypy/lib/profiler.py (modified) (1 diff)
- trunk/cherrypy/test/test.py (modified) (1 diff)
- trunk/cherrypy/test/test_baseurl_filter.py (modified) (1 diff)
- trunk/cherrypy/test/test_cache_filter.py (modified) (1 diff)
- trunk/cherrypy/test/test_combinedfilters.py (modified) (1 diff)
- trunk/cherrypy/test/test_core.py (modified) (3 diffs)
- trunk/cherrypy/test/test_decodingencoding_filter.py (modified) (1 diff)
- trunk/cherrypy/test/test_gzip_filter.py (modified) (1 diff)
- trunk/cherrypy/test/test_logdebuginfo_filter.py (modified) (2 diffs)
- trunk/cherrypy/test/test_objectmapping.py (modified) (1 diff)
- trunk/cherrypy/test/test_tutorials.py (modified) (3 diffs)
- trunk/cherrypy/test/test_virtualhost_filter.py (modified) (1 diff)
- trunk/cherrypy/tutorial/tut07_sessions.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cphttptools.py
r501 r522 33 33 import urllib, os, sys, time, types, cgi, re 34 34 import mimetypes, Cookie 35 from urlparse import urlparse 35 36 36 37 import cherrypy … … 204 205 """ 205 206 206 self.requestLine = requestLine 207 cherrypy.request.method = "" 208 cherrypy.request.requestLine = requestLine.strip() 209 self.parseFirstLine() 210 207 211 self.requestHeaders = headers 208 212 … … 212 216 cherrypy.request.paramList = [] # Only used for Xml-Rpc 213 217 cherrypy.request.headerMap = {} 214 cherrypy.request.requestLine = requestLine215 218 cherrypy.request.simpleCookie = Cookie.SimpleCookie() 216 219 cherrypy.request.rfile = rfile 217 220 cherrypy.request.scheme = scheme 218 cherrypy.request.method = ""219 221 220 222 # Prepare cherrypy.response variables … … 273 275 handleError(sys.exc_info()) 274 276 277 def parseFirstLine(self): 278 # This has to be done very early in the request process, 279 # because request.path is used for config lookups right away. 280 req = cherrypy.request 281 282 # Parse first line 283 req.method, path, req.protocol = req.requestLine.split() 284 req.processRequestBody = req.method in ("POST", "PUT") 285 286 # separate the queryString, or set it to "" if not found 287 if "?" in path: 288 path, req.queryString = path.split("?", 1) 289 else: 290 path, req.queryString = path, "" 291 292 # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2 293 if path == "*": 294 path = "global" 295 elif not path.startswith("/"): 296 # path is an absolute path (including "http://host.domain.tld"); 297 # convert it to a relative path, so configMap lookups work. This 298 # default method assumes all hosts are valid for this server. 299 scheme, location, p, pm, q, f = urlparse(path) 300 path = path[len(scheme + "://" + location):] 301 302 # Save original value (in case it gets modified by filters) 303 req.path = req.originalPath = path 304 275 305 def processRequestHeaders(self): 276 306 req = cherrypy.request 277 278 # Parse first line279 req.method, path, req.protocol = self.requestLine.split()280 req.processRequestBody = req.method in ("POST", "PUT")281 307 282 308 # Compare request and server HTTP versions, in case our server does … … 297 323 cherrypy.request.version = min(request_v, server_v) 298 324 299 # find the queryString, or set it to "" if not found300 if "?" in path:301 req.path, req.queryString = path.split("?", 1)302 else:303 req.path, req.queryString = path, ""304 305 325 # build a paramMap dictionary from queryString 306 326 pm = cgi.parse_qs(req.queryString, keep_blank_values=True) … … 324 344 req.simpleCookie.load(value) 325 345 326 msg = "%s - %s" % (req.remoteAddr, self.requestLine.strip())346 msg = "%s - %s" % (req.remoteAddr, req.requestLine) 327 347 cherrypy.log(msg, "HTTP") 328 348 … … 332 352 333 353 # Save original values (in case they get modified by filters) 334 req.originalPath = req.path335 354 req.originalParamMap = req.paramMap 336 355 req.originalParamList = req.paramList … … 346 365 raise cherrypy.RequestHandled 347 366 req.base = "%s://%s" % (req.scheme, req.headerMap.get('Host', '')) 348 req.browserUrl = req.base + path367 req.browserUrl = req.base + req.path 349 368 350 369 def processRequestBody(self): … … 547 566 cherrypy.response.body = [content] 548 567 cherrypy.response.headerMap['Content-Length'] = len(content) 568 else: 569 del cherrypy.response.headerMap['Content-Length'] 549 570 550 571 # For some statuses, Internet Explorer 5+ shows "friendly error messages" trunk/cherrypy/_cputil.py
r521 r522 248 248 # Avoid pollution of the system path 249 249 for path in filtersRoot: 250 sys.path.remove(path) 250 sys.path.remove(path) 251 251 252 252 trunk/cherrypy/config.py
r483 r522 47 47 'server.socketFile': '', 48 48 'server.socketQueueSize': 5, 49 49 50 50 'server.environment': 'development', 51 51 'server.protocolVersion': 'HTTP/1.0', … … 91 91 path = cherrypy.request.path 92 92 except AttributeError: 93 path = "/" 93 # There's no request.path yet, so use the global settings. 94 path = "global" 94 95 95 96 while True: 96 97 if path == "": 97 98 path = "/" 99 98 100 try: 99 101 result = configMap[path][key] 100 102 except KeyError: 101 if path not in ("/", "global"): 102 i = path.rfind("/") 103 if i < 0: 104 result = defaultValue 105 else: 106 path = path[:i] 107 continue 108 elif path != "global": 103 if path == "global": 104 result = defaultValue 105 elif path == "/": 109 106 path = "global" 110 107 continue 111 108 else: 112 result = defaultValue 109 path = path[:path.rfind("/")] 110 continue 113 111 break 114 112 115 113 if returnSection: 116 if path == 'global':117 return '/'118 114 return path 119 115 else: … … 128 124 129 125 try: 126 results = [('global', configMap['global'][key])] 127 except KeyError: 128 results = [] 129 130 try: 130 131 path = cherrypy.request.path 131 132 except AttributeError: 132 path = "/"133 134 pathList = cherrypy.request.path.split('/')135 136 results = []137 138 try:139 results = [('/', configMap['global'][key])]140 except KeyError:141 pass142 143 if path == '/':144 133 return results 145 134 135 pathList = path.split('/') 136 146 137 for n in xrange(1, len(pathList)): 147 path = '/' .join(pathList[0:n+1])138 path = '/' + '/'.join(pathList[0:n+1]) 148 139 try: 149 140 results.append((path, configMap[path][key])) 150 141 except KeyError: 151 142 pass 152 143 153 144 return results 154 145 155 146 156 147 class CaseSensitiveConfigParser(ConfigParser.ConfigParser): trunk/cherrypy/lib/covercp.py
r493 r522 159 159 import cherrypy 160 160 cherrypy.root = CoverStats() 161 cherrypy.config.update({'global': {'server.socketPort': port, 162 'server.threadPool': 10, 163 'server.environment': "production", 164 'session.storageType': "ram", 165 } 161 cherrypy.config.update({'server.socketPort': port, 162 'server.threadPool': 10, 163 'server.environment': "production", 164 'session.storageType': "ram", 166 165 }) 167 166 cherrypy.server.start() trunk/cherrypy/lib/profiler.py
r405 r522 140 140 import cherrypy 141 141 cherrypy.root = Profiler(path) 142 cherrypy.config.update({'global': {'server.socketPort': port, 143 'server.threadPool': 10, 144 'server.environment': "production", 145 'session.storageType': "ram", 146 } 142 cherrypy.config.update({'server.socketPort': port, 143 'server.threadPool': 10, 144 'server.environment': "production", 145 'session.storageType': "ram", 147 146 }) 148 147 cherrypy.server.start() trunk/cherrypy/test/test.py
r495 r522 244 244 245 245 if conf is None: 246 conf = {'global': {'server.socketHost': '127.0.0.1', 247 'server.socketPort': 8000, 248 'server.threadPool': 10, 249 'server.logToScreen': False, 250 'server.environment': "production", 251 } 246 conf = {'server.socketHost': '127.0.0.1', 247 'server.socketPort': 8000, 248 'server.threadPool': 10, 249 'server.logToScreen': False, 250 'server.environment': "production", 252 251 } 253 252 elif isinstance(conf, basestring): trunk/cherrypy/test/test_baseurl_filter.py
r474 r522 38 38 cherrypy.root = Root() 39 39 cherrypy.config.update({ 40 'global': {41 40 'server.environment': 'production', 42 41 'server.logToScreen': False, 43 42 'baseUrlFilter.on': True, 44 43 'baseUrlFilter.baseUrl': 'http://www.mydomain.com' 45 }46 44 }) 47 45 trunk/cherrypy/test/test_cache_filter.py
r474 r522 43 43 cherrypy.root = Root() 44 44 cherrypy.config.update({ 45 'global': {46 45 'server.logToScreen': False, 47 46 'server.environment': 'production', 48 47 'cacheFilter.on': True, 49 }50 48 }) 51 49 trunk/cherrypy/test/test_combinedfilters.py
r474 r522 41 41 cherrypy.root = Root() 42 42 cherrypy.config.update({ 43 'global': {44 43 'server.logToScreen': False, 45 44 'server.environment': 'production', 46 45 'gzipFilter.on': True, 47 46 'encodingFilter.on': True, 48 }49 47 }) 50 48 trunk/cherrypy/test/test_core.py
r509 r522 219 219 220 220 cherrypy.config.update({ 221 'global': { 222 'server.logToScreen': False, 223 'server.environment': 'production', 221 'global': {'server.logToScreen': False, 222 'server.environment': 'production', 223 }, 224 '/': { 224 225 'foo': 'this', 225 226 'bar': 'that', … … 235 236 }) 236 237 238 # Shortcut syntax--should get put in the "global" bucket 239 cherrypy.config.update({'luxuryyacht': 'throatwobblermangrove'}) 240 237 241 import helper 238 242 import os … … 241 245 242 246 def testConfig(self): 247 self.assertEqual(cherrypy.config.configMap["global"]["luxuryyacht"], 248 'throatwobblermangrove') 249 243 250 tests = [ 244 251 ('/', 'nex', None ), trunk/cherrypy/test/test_decodingencoding_filter.py
r474 r522 38 38 cherrypy.root = Root() 39 39 cherrypy.config.update({ 40 'global': {41 40 'server.logToScreen': False, 42 41 'server.environment': 'production', 43 42 'encodingFilter.on': True, 44 43 'decodingFilter.on': True 45 }46 44 }) 47 45 trunk/cherrypy/test/test_gzip_filter.py
r482 r522 44 44 cherrypy.root = Root() 45 45 cherrypy.config.update({ 46 'global': {47 46 'server.logToScreen': False, 48 47 'server.environment': 'production', 49 48 'gzipFilter.on': True, 50 }51 49 }) 52 50 trunk/cherrypy/test/test_logdebuginfo_filter.py
r474 r522 36 36 cherrypy.root = Root() 37 37 cherrypy.config.update({ 38 'global': {39 38 'session.storageType': 'ram', 40 39 'session.timeout': 60, … … 46 45 'server.environment': 'production', 47 46 'logDebugInfoFilter.on': True, 48 }49 47 }) 50 48 trunk/cherrypy/test/test_objectmapping.py
r495 r522 94 94 cherrypy.root.dir1.dir2.dir3.dir4 = Dir4() 95 95 cherrypy.config.update({ 96 'global': {97 96 'server.logToScreen': False, 98 97 'server.environment': "production", 99 }100 98 }) 101 99 trunk/cherrypy/test/test_tutorials.py
r495 r522 39 39 """Import or reload tutorial module as needed.""" 40 40 cherrypy.config.reset() 41 cherrypy.config.update({' global': {'server.socketHost': self.HOST,42 'server.socketPort': self.PORT,43 'server.threadPool': 10,44 'server.logToScreen': False,45 'server.environment': "production",46 }})41 cherrypy.config.update({'server.socketHost': self.HOST, 42 'server.socketPort': self.PORT, 43 'server.threadPool': 10, 44 'server.logToScreen': False, 45 'server.environment': "production", 46 }) 47 47 48 48 target = "cherrypy.tutorial." + tutorialName … … 125 125 def test07Sessions(self): 126 126 self.load_tut_module("tut07_sessions") 127 cherrypy.config.update({" global": {"sessionFilter.on": True}})127 cherrypy.config.update({"sessionFilter.on": True}) 128 128 129 129 self.getPage('/') … … 139 139 def test08AdvancedSessions(self): 140 140 self.load_tut_module("tut08_advanced_sessions") 141 cherrypy.config.update({" global": {"sessionFilter.on": True}})141 cherrypy.config.update({"sessionFilter.on": True}) 142 142 143 143 self.getPage('/') trunk/cherrypy/test/test_virtualhost_filter.py
r474 r522 36 36 cherrypy.root = Root() 37 37 cherrypy.config.update({ 38 'global': {39 38 'server.logToScreen': False, 40 39 'server.environment': 'production', 41 40 'virtualHostFilter.on': True, 42 41 'virtualHostFilter.prefix': '/index2', 43 },44 42 }) 45 43 trunk/cherrypy/tutorial/tut07_sessions.py
r444 r522 29 29 30 30 cherrypy.root = HitCounter() 31 cherrypy.config.update({' global': {'sessionFilter.on': True}})31 cherrypy.config.update({'sessionFilter.on': True}) 32 32 33 33 if __name__ == '__main__':

