Changeset 306
- Timestamp:
- 06/14/05 02:31:52
- Files:
-
- branches/ooconf/cherrypy/_cpconfig.py (modified) (5 diffs)
- branches/ooconf/cherrypy/_cphttptools.py (modified) (9 diffs)
- branches/ooconf/cherrypy/cpg.py (modified) (1 diff)
- branches/ooconf/cherrypy/lib/filter/basefilter.py (deleted)
- branches/ooconf/cherrypy/lib/filter/baseurlfilter.py (modified) (1 diff)
- branches/ooconf/cherrypy/lib/filter/cachefilter.py (modified) (2 diffs)
- branches/ooconf/cherrypy/lib/filter/decodingfilter.py (modified) (1 diff)
- branches/ooconf/cherrypy/lib/filter/encodingfilter.py (modified) (1 diff)
- branches/ooconf/cherrypy/lib/filter/gzipfilter.py (modified) (1 diff)
- branches/ooconf/cherrypy/lib/filter/logdebuginfofilter.py (modified) (1 diff)
- branches/ooconf/cherrypy/lib/filter/nsgmlsfilter.py (modified) (1 diff)
- branches/ooconf/cherrypy/lib/filter/sessionauthenticatefilter.py (modified) (2 diffs)
- branches/ooconf/cherrypy/lib/filter/sessionfilter/sessionfilter.py (modified) (2 diffs)
- branches/ooconf/cherrypy/lib/filter/tidyfilter.py (modified) (1 diff)
- branches/ooconf/cherrypy/lib/filter/virtualhostfilter.py (modified) (2 diffs)
- branches/ooconf/cherrypy/lib/filter/xmlrpcfilter.py (modified) (1 diff)
- branches/ooconf/cherrypy/test/test.py (modified) (1 diff)
- branches/ooconf/cherrypy/test/test_core.py (modified) (1 diff)
- branches/ooconf/cherrypy/test/test_tutorials.py (modified) (1 diff)
- branches/ooconf/cherrypy/tutorial/tutorial.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/ooconf/cherrypy/_cpconfig.py
r305 r306 2 2 import ConfigParser 3 3 4 cpg = None # delayed import5 4 import _cputil, cperror 6 5 from lib import autoreload 7 6 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 _settings.clear() 16 _settings[cpg] = defaultGlobal.copy() 17 18 # This _settings dict holds the settings metadata for all cpg objects. 19 # Keys are objects in the cpg.root tree, and values are dicts. 20 _settings = {} 8 21 9 22 defaultGlobal = { … … 36 49 } 37 50 38 # This settings dict holds the settings metadata for all cpg objects.39 # Keys are objects in the cpg.root tree, and values are dicts.40 settings = {}41 42 51 43 52 def update(updateMap=None, file=None): … … 50 59 51 60 def _update(updateMap): 52 global cpg53 if not cpg:54 import cpg55 61 import _cphttptools 56 62 57 63 for section, valueMap in updateMap.iteritems(): 58 64 if section == 'global': 59 if cpg not in settings: 60 settings[cpg] = defaultGlobal.copy() 61 bucket = settings[cpg] 65 bucket = _settings[cpg] 62 66 else: 63 67 try: … … 73 77 objectTrail.pop() 74 78 obj = objectTrail[-1] 75 bucket = settings.setdefault(obj, {})79 bucket = _settings.setdefault(obj, {}) 76 80 bucket.update(valueMap) 77 81 78 if cpg.config.get('server.environment') == 'development': 82 env = valueMap.get('server.environment') 83 if env == 'development': 79 84 # In "dev" environment, log everything by default 80 bucket["logDebugInfoFilter.on"] = True 85 bucket.setdefault("logDebugInfoFilter.on", True) 86 else: 87 bucket.setdefault("logDebugInfoFilter.on", False) 81 88 82 89 83 90 def get(key, defaultValue=None): 84 global cpg 85 if not cpg: 86 import cpg 91 # This incantation seems to be fastest. 92 s = getattr(getattr(cpg, "request", None), "settings", None) 87 93 88 try: 89 s = cpg.request.settings 90 except AttributeError: 94 if s is None: 91 95 # Config is being retrieved outside of a request. 92 96 # Return config for cpg ("global"). 93 if cpg not in settings: 94 settings[cpg] = defaultGlobal.copy() 95 s = settings[cpg] 97 s = _settings[cpg] 96 98 return s.get(key, defaultValue) 97 99 98 100 def collapsedSettings(objectTrail): 99 101 """Collapse all 'settings' in objectTrail into a single dict.""" 100 if cpg not in settings: 101 settings[cpg] = defaultGlobal.copy() 102 result = settings[cpg].copy() 102 result = _settings[cpg].copy() 103 103 for obj in objectTrail: 104 s = settings.setdefault(obj, {})104 s = _settings.setdefault(obj, {}) 105 105 if s: 106 106 result.update(s) … … 139 139 configParser.read(configFile) 140 140 141 # Load INI file into c pg.configMap141 # Load INI file into configMap 142 142 configMap = {} 143 143 for section in configParser.sections(): branches/ooconf/cherrypy/_cphttptools.py
r305 r306 34 34 import mimetypes, Cookie, urlparse 35 35 import cpg, _cputil, cperror, _cpdefaults 36 from lib.filter import basefilter37 36 38 37 from BaseHTTPServer import BaseHTTPRequestHandler … … 65 64 66 65 # Prepare cpg.request variables 67 cpg.request.remoteAddr = clientAddress 68 cpg.request.remoteHost = remoteHost 69 cpg.request.paramList = [] # Only used for Xml-Rpc 70 cpg.request.filenameMap = {} 71 cpg.request.fileTypeMap = {} 72 cpg.request.headerMap = {} 73 cpg.request.requestLine = requestLine 74 cpg.request.simpleCookie = Cookie.SimpleCookie() 75 cpg.request.isStatic = False 76 cpg.request.rfile = self.rfile 66 req = cpg.request 67 req.remoteAddr = clientAddress 68 req.remoteHost = remoteHost 69 req.paramList = [] # Only used for Xml-Rpc 70 req.filenameMap = {} 71 req.fileTypeMap = {} 72 req.headerMap = {} 73 req.requestLine = requestLine 74 req.simpleCookie = Cookie.SimpleCookie() 75 req.isStatic = False 76 req.rfile = self.rfile 77 77 78 78 # Prepare cpg.response variables 79 cpg.response.status = None 80 cpg.response.headers = None 81 cpg.response.body = None 79 resp = cpg.response 80 resp.status = None 81 resp.headers = None 82 resp.body = None 82 83 83 84 year, month, day, hh, mm, ss, wd, y, z = time.gmtime(time.time()) 84 85 date = ("%s, %02d %3s %4d %02d:%02d:%02d GMT" % 85 86 (weekdayname[wd], day, monthname[month], year, hh, mm, ss)) 86 cpg.response.headerMap = {87 resp.headerMap = { 87 88 "Content-Type": "text/html", 88 89 "Server": "CherryPy/" + cpg.__version__, … … 91 92 "Content-Length": 0 92 93 } 93 cpg.response.simpleCookie = Cookie.SimpleCookie()94 resp.simpleCookie = Cookie.SimpleCookie() 94 95 95 96 self.run() … … 104 105 main, virtualPathList = self.findMain() 105 106 106 # Look these up again, because objectTrailis now set107 collectFilters( )107 # Look up again, since cpg.request.settings is now set 108 collectFilters(True) 108 109 109 110 applyFilters('beforeRequestBody') … … 170 171 cpg.request.browserUrl = cpg.request.base + path 171 172 172 # Change objectPath in filters to change173 # the object that will get rendered174 cpg.request.objectPath = None175 176 173 # Save original values (in case they get modified by filters) 177 174 cpg.request.originalPath = cpg.request.path … … 180 177 181 178 def findMain(self): 182 path = cpg.request.path183 # Remove leading and trailing slash184 path = path.strip("/")185 # Replace quoted chars (eg %20) from url186 path = urllib.unquote(path)187 188 179 try: 189 path = cpg.request. objectPath or cpg.request.path180 path = cpg.request.path 190 181 objectTrail, vpath, isIndex = mapPathToObject(path) 191 182 … … 250 241 251 242 252 def collectFilters(): 243 def collectFilters(use_request_settings=False): 244 # This method gets called a *lot* so heavy optimization is needed. 245 if use_request_settings: 246 get = cpg.request.settings.get 247 else: 248 get = cpg.config._settings[cpg].get 249 253 250 result = [] 254 251 for f in _cpdefaults._cpDefaultInputFilterList: 255 252 name = f.__class__.__name__ 256 253 name = name[0].lower() + name[1:] 257 if cpg.config.get(name + ".on", False):254 if get(name + ".on", False): 258 255 result.append(f) 259 256 cpg.request.defInputFilters = result … … 265 262 name = f.__class__.__name__ 266 263 name = name[0].lower() + name[1:] 267 if cpg.config.get(name + ".on", False):264 if get(name + ".on", False): 268 265 result.append(f) 269 266 cpg.request.defOutputFilters = result … … 453 450 # Also, a method has to have ".exposed = True" in order to be exposed 454 451 455 originalPath = path456 452 # Remove leading and trailing slash 457 453 path = path.strip("/") branches/ooconf/cherrypy/cpg.py
r267 r306 38 38 import _cpserver as server 39 39 import _cpconfig as config 40 config.init() 40 41 41 42 # decorator function for exposing methods branches/ooconf/cherrypy/lib/filter/baseurlfilter.py
r305 r306 27 27 """ 28 28 29 from basefilter import BaseFilter30 29 31 class BaseUrlFilter (BaseFilter):30 class BaseUrlFilter: 32 31 """Filter that changes the base URL. 33 32 branches/ooconf/cherrypy/lib/filter/cachefilter.py
r305 r306 31 31 import time 32 32 33 import basefilter34 33 35 34 def defaultCacheKey(): … … 105 104 106 105 107 class CacheFilter (basefilter.BaseFilter):106 class CacheFilter: 108 107 """If the page is already stored in the cache, serves the contents. 109 108 If the page is not in the cache, caches the output. branches/ooconf/cherrypy/lib/filter/decodingfilter.py
r305 r306 27 27 """ 28 28 29 from basefilter import BaseFilter30 29 31 class DecodingFilter (BaseFilter):30 class DecodingFilter: 32 31 """Automatically decodes request parameters (except uploads).""" 33 32 branches/ooconf/cherrypy/lib/filter/encodingfilter.py
r305 r306 27 27 """ 28 28 29 from basefilter import BaseFilter30 29 31 class EncodingFilter (BaseFilter):30 class EncodingFilter: 32 31 """Filter that automatically encodes the response.""" 33 32 branches/ooconf/cherrypy/lib/filter/gzipfilter.py
r305 r306 30 30 import struct 31 31 import time 32 from basefilter import BaseFilter33 32 34 class GzipFilter (BaseFilter):33 class GzipFilter: 35 34 """Filter that gzips the response.""" 36 35 branches/ooconf/cherrypy/lib/filter/logdebuginfofilter.py
r305 r306 28 28 29 29 import time, StringIO, pickle 30 from basefilter import BaseFilter31 30 32 class LogDebugInfoFilter (BaseFilter):31 class LogDebugInfoFilter: 33 32 """Filter that adds debug information to the page""" 34 33 branches/ooconf/cherrypy/lib/filter/nsgmlsfilter.py
r305 r306 27 27 """ 28 28 29 import os, cgi, StringIO, traceback 30 from basefilter import BaseFilter 29 import os, cgi 31 30 32 class NsgmlsFilter (BaseFilter):31 class NsgmlsFilter: 33 32 """Filter that runs the response through Nsgmls. 34 33 """ branches/ooconf/cherrypy/lib/filter/sessionauthenticatefilter.py
r299 r306 27 27 """ 28 28 29 from basefilter import BaseFilter30 29 31 30 def loginScreen(fromPage, login = '', errorMsg = ''): … … 43 42 44 43 45 class SessionAuthenticateFilter (BaseFilter):44 class SessionAuthenticateFilter: 46 45 """ 47 46 Filter that adds debug information to the page branches/ooconf/cherrypy/lib/filter/sessionfilter/sessionfilter.py
r305 r306 1 1 2 from cherrypy.lib.filter.basefilter import BaseFilter3 2 import cherrypy.cpg 4 3 … … 60 59 return sessions 61 60 62 class SessionFilter (BaseFilter):61 class SessionFilter: 63 62 """ 64 63 Input filter - get the sessionId (or generate a new one) and load up the session data branches/ooconf/cherrypy/lib/filter/tidyfilter.py
r305 r306 28 28 29 29 import os, cgi, StringIO, traceback 30 from basefilter import BaseFilter31 30 32 class TidyFilter (BaseFilter):31 class TidyFilter: 33 32 """Filter that runs the response through Tidy. 34 33 branches/ooconf/cherrypy/lib/filter/virtualhostfilter.py
r305 r306 27 27 """ 28 28 29 import basefilter30 29 31 class VirtualHostFilter (basefilter.BaseFilter):30 class VirtualHostFilter: 32 31 """Filter that changes the ObjectPath based on the Host. 33 32 … … 39 38 # We have to dynamically import cpg because Python can't handle 40 39 # circular module imports :-( 41 global cpg , _cphttptools42 from cherrypy import cpg , _cphttptools40 global cpg 41 from cherrypy import cpg 43 42 44 43 prefix = cpg.config.get('virtualHostFilter.prefix', '/') 45 # Store the original path in an attr which app code can see 46 p = cpg.request.originalPath = cpg.request.path 47 cpg.request.path = prefix + p 44 cpg.request.path = prefix + cpg.request.path 48 45 branches/ooconf/cherrypy/lib/filter/xmlrpcfilter.py
r305 r306 103 103 ###################################################################### 104 104 105 from basefilter import BaseFilter106 105 import xmlrpclib 107 106 108 class XmlRpcFilter (BaseFilter):107 class XmlRpcFilter: 109 108 """Converts XMLRPC to CherryPy2 object system and vice-versa. 110 109 branches/ooconf/cherrypy/test/test.py
r304 r306 178 178 # Must run each module in a separate suite, 179 179 # because each module uses/overwrites cpg globals. 180 cpg.config. settings.clear()180 cpg.config.reset(False) 181 181 cpg.config.update({'global': server_conf.copy()}) 182 182 suite = CPTestLoader.loadTestsFromName(testmod) branches/ooconf/cherrypy/test/test_core.py
r304 r306 163 163 helper.request("/foo/bar") 164 164 self.assertEqual(cpg.response.body, "that2this4") 165 ## 166 ## def testRepeatedRequests(self): 167 ## def _mini(): 168 ## for trial in xrange(100): 169 ## helper.request("/") 170 ## from cherrypy.lib import profiler 171 ## p = profiler.Profiler() 172 ## p.run(_mini) 165 173 166 174 def testStatus(self): branches/ooconf/cherrypy/test/test_tutorials.py
r304 r306 42 42 def load_tut_module(tutorialName): 43 43 """Import or reload tutorial module as needed.""" 44 cpg.config. settings.clear()44 cpg.config.reset(False) 45 45 cpg.config.update({'global': server_conf.copy()}) 46 46 branches/ooconf/cherrypy/tutorial/tutorial.conf
r242 r306 1 [ /]1 [global] 2 2 server.socketPort = 8080 3 3 server.threadPool = 10 4 4 server.environment = "production" 5 5 session.storageType= "ram" 6 # server.logToScreen = False

