Changeset 1311
- Timestamp:
- 09/02/06 02:25:29
- Files:
-
- trunk/cherrypy/__init__.py (modified) (1 diff)
- trunk/cherrypy/_cpconfig.py (modified) (2 diffs)
- trunk/cherrypy/_cprequest.py (modified) (3 diffs)
- trunk/cherrypy/_cptools.py (modified) (3 diffs)
- trunk/cherrypy/_cptree.py (modified) (5 diffs)
- trunk/cherrypy/test/test_core.py (modified) (1 diff)
- trunk/cherrypy/test/test_etags.py (modified) (1 diff)
- trunk/cherrypy/test/test_static.py (modified) (1 diff)
- trunk/cherrypy/test/test_tools.py (modified) (1 diff)
- trunk/cherrypy/test/test_wsgi_ns.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/__init__.py
r1309 r1311 22 22 server = _cpserver.Server() 23 23 24 def quickstart(root, script_name="", conf =None):24 def quickstart(root, script_name="", config=None): 25 25 """Mount the given app, start the engine and builtin server, then block.""" 26 tree.mount(root, script_name, conf )26 tree.mount(root, script_name, config) 27 27 server.quickstart() 28 28 engine.start() trunk/cherrypy/_cpconfig.py
r1299 r1311 15 15 16 16 Application: entries which apply to each mounted application are stored 17 on the Application object itself, as 'app.conf '. This is a two-level17 on the Application object itself, as 'app.config'. This is a two-level 18 18 dict where each key is a path, or "relative URL" (for example, "/" or 19 19 "/path/to/my/page"), and each value is a config dict. Usually, this 20 data is provided in the call to cherrypy.tree.mount(root(), conf =conf),20 data is provided in the call to cherrypy.tree.mount(root(), config=conf), 21 21 although you may also use app.merge(conf). 22 22 … … 136 136 dict.update(self, self.defaults) 137 137 138 def update(self, conf ):138 def update(self, config): 139 139 """Update self from a dict, file or filename.""" 140 if isinstance(conf , basestring):140 if isinstance(config, basestring): 141 141 # Filename 142 if conf not in cherrypy.engine.reload_files:143 cherrypy.engine.reload_files.append(conf )144 conf = _Parser().dict_from_file(conf)145 elif hasattr(conf , 'read'):142 if config not in cherrypy.engine.reload_files: 143 cherrypy.engine.reload_files.append(config) 144 config = _Parser().dict_from_file(config) 145 elif hasattr(config, 'read'): 146 146 # Open file object 147 conf = _Parser().dict_from_file(conf)147 config = _Parser().dict_from_file(config) 148 148 else: 149 conf = conf.copy()150 151 if isinstance(conf .get("global", None), dict):152 conf = conf["global"]153 154 if 'environment' in conf :155 env = environments[conf ['environment']]149 config = config.copy() 150 151 if isinstance(config.get("global", None), dict): 152 config = config["global"] 153 154 if 'environment' in config: 155 env = environments[config['environment']] 156 156 for k in env: 157 if k not in conf :158 conf [k] = env[k]159 160 if 'tools.staticdir.dir' in conf :161 conf ['tools.staticdir.section'] = "global"157 if k not in config: 158 config[k] = env[k] 159 160 if 'tools.staticdir.dir' in config: 161 config['tools.staticdir.section'] = "global" 162 162 163 163 # Must use this idiom in order to hit our custom __setitem__. 164 for k, v in conf .iteritems():164 for k, v in config.iteritems(): 165 165 self[k] = v 166 166 trunk/cherrypy/_cprequest.py
r1303 r1311 150 150 if hasattr(root, "_cp_config"): 151 151 nodeconf.update(root._cp_config) 152 if "/" in app.conf :153 nodeconf.update(app.conf ["/"])152 if "/" in app.config: 153 nodeconf.update(app.config["/"]) 154 154 object_trail = [('root', root, nodeconf, curpath)] 155 155 … … 167 167 nodeconf.update(node._cp_config) 168 168 169 # Mix in values from app.conf for this path.169 # Mix in values from app.config for this path. 170 170 curpath = "/".join((curpath, name)) 171 if curpath in app.conf :172 nodeconf.update(app.conf [curpath])171 if curpath in app.config: 172 nodeconf.update(app.config[curpath]) 173 173 174 174 object_trail.append((objname, node, nodeconf, curpath)) … … 558 558 dispatch = self.dispatch 559 559 # First, see if there is a custom dispatch at this URI. Custom 560 # dispatchers can only be specified in app.conf , not in _cp_config560 # dispatchers can only be specified in app.config, not in _cp_config 561 561 # (since custom dispatchers may not even have an app.root). 562 562 trail = path 563 563 while trail: 564 nodeconf = self.app.conf .get(trail, {})564 nodeconf = self.app.config.get(trail, {}) 565 565 d = nodeconf.get("request.dispatch") 566 566 if d: trunk/cherrypy/_cptools.py
r1298 r1311 167 167 168 168 def _setup(self): 169 """Hook this tool into cherrypy.request using the given conf.169 """Hook this tool into cherrypy.request. 170 170 171 171 The standard CherryPy request object will automatically call this … … 216 216 217 217 def _setup(self): 218 """Hook this tool into cherrypy.request using the given conf."""218 """Hook this tool into cherrypy.request.""" 219 219 request = cherrypy.request 220 220 # Guard against running this method twice. … … 272 272 273 273 def _setup(self): 274 """Hook caching into cherrypy.request using the given conf."""274 """Hook caching into cherrypy.request.""" 275 275 conf = self._merged_args() 276 276 cherrypy.request.hooks.attach('before_main', self._wrapper, **conf) trunk/cherrypy/_cptree.py
r1309 r1311 21 21 explicitly set to None, then CherryPy will attempt to provide 22 22 it each time from request.wsgi_environ['SCRIPT_NAME']. 23 conf : a dict of {path: pathconf} pairs, where 'pathconf' is itself23 config: a dict of {path: pathconf} pairs, where 'pathconf' is itself 24 24 a dict of {key: value} pairs. 25 25 """ … … 31 31 self.namespaces = {"log": lambda k, v: setattr(self.log, k, v), 32 32 } 33 self.conf = {}33 self.config = {} 34 34 35 35 def _get_script_name(self): … … 43 43 script_name = property(fget=_get_script_name, fset=_set_script_name) 44 44 45 def merge(self, conf ):45 def merge(self, config): 46 46 """Merge the given config into self.config.""" 47 _cpconfig.merge(self.conf , conf)47 _cpconfig.merge(self.config, config) 48 48 49 49 # Handle namespaces specified in config. 50 rootconf = self.conf .get("/", {})50 rootconf = self.config.get("/", {}) 51 51 for k, v in rootconf.iteritems(): 52 52 atoms = k.split(".", 1) … … 206 206 self.apps = {} 207 207 208 def mount(self, root, script_name="", conf =None):209 """Mount a new app from a root object, script_name, and conf ."""208 def mount(self, root, script_name="", config=None): 209 """Mount a new app from a root object, script_name, and config.""" 210 210 # Next line both 1) strips trailing slash and 2) maps "/" -> "". 211 211 script_name = script_name.rstrip("/") … … 224 224 root.favicon_ico = tools.staticfile.handler(favicon) 225 225 226 if conf :227 app.merge(conf )226 if config: 227 app.merge(config) 228 228 229 229 self.apps[script_name] = app trunk/cherrypy/test/test_core.py
r1302 r1311 378 378 '/method': {'request.methods_with_bodies': ("POST", "PUT", "PROPFIND")}, 379 379 } 380 cherrypy.tree.mount(root, conf =appconf)380 cherrypy.tree.mount(root, config=appconf) 381 381 382 382 trunk/cherrypy/test/test_etags.py
r1275 r1311 17 17 conf = {'/': {'tools.etags.on': True, 18 18 'tools.etags.autotags': True}} 19 cherrypy.tree.mount(Root(), conf =conf)19 cherrypy.tree.mount(Root(), config=conf) 20 20 cherrypy.config.update({'environment': 'test_suite'}) 21 21 trunk/cherrypy/test/test_static.py
r1275 r1311 49 49 } 50 50 51 cherrypy.tree.mount(root, conf =conf)51 cherrypy.tree.mount(root, config=conf) 52 52 cherrypy.config.update({'environment': 'test_suite'}) 53 53 trunk/cherrypy/test/test_tools.py
r1280 r1311 177 177 }, 178 178 } 179 cherrypy.tree.mount(root, conf =conf)179 cherrypy.tree.mount(root, config=conf) 180 180 181 181 trunk/cherrypy/test/test_wsgi_ns.py
r1310 r1311 42 42 p = cherrypy.wsgi.pipeline(app, [('changecase', ChangeCase)]) 43 43 p.config['changecase'] = {'to': 'upper'} 44 cherrypy.tree.mount(app, conf ={'/': root_conf})44 cherrypy.tree.mount(app, config={'/': root_conf}) 45 45 46 46 # If we do not supply any middleware in code, pipeline is much cleaner: 47 47 # app = cherrypy.Application(Root()) 48 48 # cherrypy.wsgi.pipeline(app) 49 # cherrypy.tree.mount(app, conf ={'/': root_conf})49 # cherrypy.tree.mount(app, config={'/': root_conf}) 50 50 51 51

