diff options
39 files changed, 405 insertions, 451 deletions
diff --git a/cherrypy/__init__.py b/cherrypy/__init__.py index c55db360..ac630bb5 100644 --- a/cherrypy/__init__.py +++ b/cherrypy/__init__.py @@ -149,7 +149,7 @@ def log(msg='', context='', severity=_logging.DEBUG, traceback=False): if traceback: from cherrypy import _cperror msg += _cperror.format_exc() - logfunc = config.get('log_function', _log_message) + logfunc = config.get('log.error.function', _log_message) logfunc(msg, context, severity) diff --git a/cherrypy/_cpengine.py b/cherrypy/_cpengine.py index 3f0536c6..764199c7 100644 --- a/cherrypy/_cpengine.py +++ b/cherrypy/_cpengine.py @@ -68,16 +68,12 @@ class Engine(object): conf = cherrypy.config.get - # Output config options to log - if conf("log_config", True): - cherrypy.config.log_config() - for func in self.on_start_engine_list: func() self.state = STARTED - freq = float(cherrypy.config.get('deadlock_poll_freq', 60)) + freq = float(conf('deadlock.poll_freq', 60)) if freq > 0: self.monitor_thread = threading.Timer(freq, self.monitor) self.monitor_thread.start() @@ -222,7 +218,7 @@ class Engine(object): if self.state == STARTED: for req, resp in self.servings: resp.check_timeout() - freq = float(cherrypy.config.get('deadlock_poll_freq', 60)) + freq = float(cherrypy.config.get('deadlock.poll_freq', 60)) self.monitor_thread = threading.Timer(freq, self.monitor) self.monitor_thread.start() diff --git a/cherrypy/_cperror.py b/cherrypy/_cperror.py index f3cfeab1..c3418434 100644 --- a/cherrypy/_cperror.py +++ b/cherrypy/_cperror.py @@ -177,7 +177,7 @@ class HTTPError(Exception): # so don't bother cleaning up response values here. response.status = self.status tb = None - if cherrypy.config.get('show_tracebacks', False): + if cherrypy.request.show_tracebacks: tb = format_exc() content = get_error_page(self.status, traceback=tb, message=self.message) diff --git a/cherrypy/_cpmodpy.py b/cherrypy/_cpmodpy.py index d5338a6e..1573ade9 100644 --- a/cherrypy/_cpmodpy.py +++ b/cherrypy/_cpmodpy.py @@ -18,7 +18,7 @@ def setup(req): func = getattr(mod, fname) func() - cherrypy.config.update({'global' : {'log_to_screen' : False}}) + cherrypy.config.update({'log.screen': False}) if cherrypy.engine.state == cherrypy._cpengine.STOPPED: cherrypy.engine.start(blocking=False) diff --git a/cherrypy/_cprequest.py b/cherrypy/_cprequest.py index 06a88227..2356a269 100644 --- a/cherrypy/_cprequest.py +++ b/cherrypy/_cprequest.py @@ -77,6 +77,180 @@ class HookMap(object): raise +class PageHandler(object): + """Callable which sets response.body.""" + + def __init__(self, callable, *args, **kwargs): + self.callable = callable + self.args = args + self.kwargs = kwargs + + def __call__(self): + cherrypy.response.body = self.callable(*self.args, **self.kwargs) + + +class LateParamPageHandler(PageHandler): + """When passing cherrypy.request.params to the page handler, we don't + want to capture that dict too early; we want to give tools like the + decoding tool a chance to modify the params dict in-between the lookup + of the handler and the actual calling of the handler. This subclass + takes that into account, and allows request.params to be 'bound late' + (it's more complicated than that, but that's the effect). + """ + + def _get_kwargs(self): + kwargs = cherrypy.request.params.copy() + if self._kwargs: + kwargs.update(self._kwargs) + return kwargs + + def _set_kwargs(self, kwargs): + self._kwargs = kwargs + + kwargs = property(_get_kwargs, _set_kwargs, + doc='page handler kwargs (with ' + 'cherrypy.request.params copied in)') + + +class Dispatcher(object): + + def __call__(self, path_info): + """Set handler and config for the current request.""" + request = cherrypy.request + func, vpath = self.find_handler(path_info) + + if func: + # Decode any leftover %2F in the virtual_path atoms. + vpath = [x.replace("%2F", "/") for x in vpath] + request.handler = LateParamPageHandler(func, *vpath) + else: + request.handler = cherrypy.NotFound() + + def find_handler(self, path): + """Find the appropriate page handler for the given path.""" + request = cherrypy.request + app = request.app + root = app.root + + # Get config for the root object/path. + curpath = "" + nodeconf = {} + if hasattr(root, "_cp_config"): + nodeconf.update(root._cp_config) + if "/" in app.conf: + nodeconf.update(app.conf["/"]) + object_trail = [('root', root, nodeconf, curpath)] + + node = root + names = [x for x in path.strip('/').split('/') if x] + ['index'] + for name in names: + # map to legal Python identifiers (replace '.' with '_') + objname = name.replace('.', '_') + + nodeconf = {} + node = getattr(node, objname, None) + if node is not None: + # Get _cp_config attached to this node. + if hasattr(node, "_cp_config"): + nodeconf.update(node._cp_config) + + # Mix in values from app.conf for this path. + curpath = "/".join((curpath, name)) + if curpath in app.conf: + nodeconf.update(app.conf[curpath]) + + object_trail.append((objname, node, nodeconf, curpath)) + + def set_conf(): + """Set cherrypy.request.config.""" + base = cherrypy.config.globalconf.copy() + # Note that we merge the config from each node + # even if that node was None. + for name, obj, conf, curpath in object_trail: + base.update(conf) + if 'tools.staticdir.dir' in conf: + base['tools.staticdir.section'] = curpath + return base + + # Try successive objects (reverse order) + for i in xrange(len(object_trail) - 1, -1, -1): + + name, candidate, nodeconf, curpath = object_trail[i] + if candidate is None: + continue + + # Try a "default" method on the current leaf. + if hasattr(candidate, "default"): + defhandler = candidate.default + if getattr(defhandler, 'exposed', False): + # Insert any extra _cp_config from the default handler. + conf = getattr(defhandler, "_cp_config", {}) + object_trail.insert(i+1, ("default", defhandler, conf, curpath)) + request.config = set_conf() + return defhandler, names[i:-1] + + # Uncomment the next line to restrict positional params to "default". + # if i < len(object_trail) - 2: continue + + # Try the current leaf. + if getattr(candidate, 'exposed', False): + request.config = set_conf() + if i == len(object_trail) - 1: + # We found the extra ".index". Check if the original path + # had a trailing slash (otherwise, do a redirect). + if path[-1:] != '/': + atoms = request.browser_url.split("?", 1) + new_url = atoms.pop(0) + '/' + if atoms: + new_url += "?" + atoms[0] + raise cherrypy.HTTPRedirect(new_url) + return candidate, names[i:-1] + + # We didn't find anything + request.config = set_conf() + return None, [] + + +class MethodDispatcher(Dispatcher): + """Additional dispatch based on cherrypy.request.method.upper(). + + Methods named GET, POST, etc will be called on an exposed class. + The method names must be all caps; the appropriate Allow header + will be output showing all capitalized method names as allowable + HTTP verbs. + + Note that the containing class must be exposed, not the methods. + """ + + def __call__(self, path_info): + """Set handler and config for the current request.""" + request = cherrypy.request + resource, vpath = self.find_handler(path_info) + + # Decode any leftover %2F in the virtual_path atoms. + vpath = [x.replace("%2F", "/") for x in vpath] + + if resource: + # Set Allow header + avail = [m for m in dir(resource) if m.isupper()] + if "GET" in avail and "HEAD" not in avail: + avail.append("HEAD") + avail.sort() + cherrypy.response.headers['Allow'] = ", ".join(avail) + + # Find the subhandler + meth = cherrypy.request.method.upper() + func = getattr(resource, meth, None) + if func is None and meth == "HEAD": + func = getattr(resource, "GET", None) + if func: + request.handler = LateParamPageHandler(func, *vpath) + else: + request.handler = cherrypy.HTTPError(405) + else: + request.handler = cherrypy.NotFound() + + class Request(object): """An HTTP request.""" @@ -104,21 +278,29 @@ class Request(object): methods_with_bodies = ("POST", "PUT") body = None body_read = False + max_body_size = 100 * 1024 * 1024 # Dispatch attributes + dispatch = Dispatcher() script_name = "" path_info = "/" app = None handler = None toolmap = {} config = None - error_response = cherrypy.HTTPError(500).set_response + recursive_redirect = False + hookpoints = ['on_start_resource', 'before_request_body', 'before_main', 'before_finalize', 'on_end_resource', 'on_end_request', 'before_error_response', 'after_error_response'] hooks = HookMap(hookpoints) + error_response = cherrypy.HTTPError(500).set_response + show_tracebacks = True + throw_errors = False + + def __init__(self, local_host, remote_host, scheme="http", server_protocol="HTTP/1.1"): """Populate a new Request object. @@ -218,8 +400,7 @@ class Request(object): break except cherrypy.InternalRedirect, ir: pi = ir.path - if (pi in self.redirections and - not cherrypy.config.get("recursive_redirect")): + if pi in self.redirections and not self.recursive_redirect: raise RuntimeError("InternalRedirect visited the " "same URL twice: %s" % repr(pi)) self.redirections.append(pi) @@ -228,7 +409,7 @@ class Request(object): except cherrypy.TimeoutError: raise except: - if cherrypy.config.get("throw_errors", False): + if self.throw_errors: raise self.handle_error(sys.exc_info()) @@ -236,7 +417,7 @@ class Request(object): # HEAD requests MUST NOT return a message-body in the response. cherrypy.response.body = [] - log_access = cherrypy.config.get("log_access", cherrypy.log_access) + log_access = cherrypy.config.get("log.access.function", cherrypy.log_access) if log_access: log_access() @@ -264,8 +445,7 @@ class Request(object): if self.process_request_body: # Prepare the SizeCheckWrapper for the request body - mbs = int(self.config.get('server.max_request_body_size', - 100 * 1024 * 1024)) + mbs = self.max_body_size if mbs > 0: self.rfile = http.SizeCheckWrapper(self.rfile, mbs) @@ -323,14 +503,14 @@ class Request(object): def get_resource(self, path): """Find and call a dispatcher (which sets self.handler and .config).""" - dispatch = default_dispatch + dispatch = self.dispatch # First, see if there is a custom dispatch at this URI. Custom # dispatchers can only be specified in app.conf, not in _cp_config # (since custom dispatchers may not even have an app.root). trail = path while trail: nodeconf = self.app.conf.get(trail, {}) - d = nodeconf.get("dispatch") + d = nodeconf.get("request.dispatch") if d: dispatch = d break @@ -347,7 +527,7 @@ class Request(object): dispatch(path) def tool_up(self): - """Populate self.toolmap and set up each tool.""" + """Process self.config, populate self.toolmap and set up each tool.""" # Get all 'tools.*' config entries as a {toolname: {k: v}} dict. self.toolmap = tm = {} reqconf = self.config @@ -365,6 +545,12 @@ class Request(object): if isinstance(v, basestring): v = cherrypy.lib.attributes(v) self.hooks.attach(hookpoint, v) + elif namespace == "request": + # Override properties of this request object. + setattr(self, atoms[1], reqconf[k]) + elif namespace == "response": + # Override properties of the current response object. + setattr(cherrypy.response, atoms[1], reqconf[k]) # Run tool._setup(conf) for each tool in the new toolmap. tools = cherrypy.tools @@ -431,7 +617,7 @@ class Request(object): pass # Failure in error handler or finalize. Bypass them. - if cherrypy.config.get('show_tracebacks', False): + if self.show_tracebacks: dbltrace = ("\n===First Error===\n\n%s" "\n\n===Second Error===\n\n%s\n\n") body = dbltrace % (format_exc(exc), format_exc()) @@ -441,198 +627,6 @@ class Request(object): response.status, response.header_list, response.body = r -class PageHandler(object): - """Callable which sets response.body.""" - - def __init__(self, callable, *args, **kwargs): - self.callable = callable - self.args = args - self.kwargs = kwargs - - def __call__(self): - cherrypy.response.body = self.callable(*self.args, **self.kwargs) - - -class LateParamPageHandler(PageHandler): - """When passing cherrypy.request.params to the page handler, we don't - want to capture that dict too early; we want to give tools like the - decoding tool a chance to modify the params dict in-between the lookup - of the handler and the actual calling of the handler. This subclass - takes that into account, and allows request.params to be 'bound late' - (it's more complicated than that, but that's the effect). - """ - - def _get_kwargs(self): - kwargs = cherrypy.request.params.copy() - if self._kwargs: - kwargs.update(self._kwargs) - return kwargs - - def _set_kwargs(self, kwargs): - self._kwargs = kwargs - - kwargs = property(_get_kwargs, _set_kwargs, - doc='page handler kwargs (with ' - 'cherrypy.request.params copied in)') - - -class Dispatcher(object): - - def __call__(self, path_info): - """Set handler and config for the current request.""" - request = cherrypy.request - func, vpath = self.find_handler(path_info) - - if func: - # Decode any leftover %2F in the virtual_path atoms. - vpath = [x.replace("%2F", "/") for x in vpath] - request.handler = LateParamPageHandler(func, *vpath) - else: - request.handler = cherrypy.NotFound() - - def find_handler(self, path): - """Find the appropriate page handler for the given path.""" - request = cherrypy.request - app = request.app - root = app.root - - # Get config for the root object/path. - environments = cherrypy.config.environments - curpath = "" - nodeconf = {} - if hasattr(root, "_cp_config"): - nodeconf.update(root._cp_config) - if 'environment' in nodeconf: - env = environments[nodeconf['environment']] - for k in env: - if k not in nodeconf: - nodeconf[k] = env[k] - if "/" in app.conf: - nodeconf.update(app.conf["/"]) - object_trail = [('root', root, nodeconf, curpath)] - - node = root - names = [x for x in path.strip('/').split('/') if x] + ['index'] - for name in names: - # map to legal Python identifiers (replace '.' with '_') - objname = name.replace('.', '_') - - nodeconf = {} - node = getattr(node, objname, None) - if node is not None: - # Get _cp_config attached to this node. - if hasattr(node, "_cp_config"): - nodeconf.update(node._cp_config) - - # Resolve "environment" entries. This must be done node-by-node - # so that a child's "environment" can override concrete settings - # of a parent. However, concrete settings in this node will - # override "environment" settings in the same node. - if 'environment' in nodeconf: - env = environments[nodeconf['environment']] - for k in env: - if k not in nodeconf: - nodeconf[k] = env[k] - - # Mix in values from app.conf for this path. - curpath = "/".join((curpath, name)) - if curpath in app.conf: - nodeconf.update(app.conf[curpath]) - - object_trail.append((objname, node, nodeconf, curpath)) - - def set_conf(): - """Set cherrypy.request.config.""" - base = cherrypy.config.globalconf.copy() - # Note that we merge the config from each node - # even if that node was None. - for name, obj, conf, curpath in object_trail: - base.update(conf) - if 'tools.staticdir.dir' in conf: - base['tools.staticdir.section'] = curpath - return base - - # Try successive objects (reverse order) - for i in xrange(len(object_trail) - 1, -1, -1): - - name, candidate, nodeconf, curpath = object_trail[i] - if candidate is None: - continue - - # Try a "default" method on the current leaf. - if hasattr(candidate, "default"): - defhandler = candidate.default - if getattr(defhandler, 'exposed', False): - # Insert any extra _cp_config from the default handler. - conf = getattr(defhandler, "_cp_config", {}) - object_trail.insert(i+1, ("default", defhandler, conf, curpath)) - request.config = set_conf() - return defhandler, names[i:-1] - - # Uncomment the next line to restrict positional params to "default". - # if i < len(object_trail) - 2: continue - - # Try the current leaf. - if getattr(candidate, 'exposed', False): - request.config = set_conf() - if i == len(object_trail) - 1: - # We found the extra ".index". Check if the original path - # had a trailing slash (otherwise, do a redirect). - if path[-1:] != '/': - atoms = request.browser_url.split("?", 1) - new_url = atoms.pop(0) + '/' - if atoms: - new_url += "?" + atoms[0] - raise cherrypy.HTTPRedirect(new_url) - return candidate, names[i:-1] - - # We didn't find anything - request.config = set_conf() - return None, [] - -default_dispatch = Dispatcher() - - -class MethodDispatcher(Dispatcher): - """Additional dispatch based on cherrypy.request.method.upper(). - - Methods named GET, POST, etc will be called on an exposed class. - The method names must be all caps; the appropriate Allow header - will be output showing all capitalized method names as allowable - HTTP verbs. - - Note that the containing class must be exposed, not the methods. - """ - - def __call__(self, path_info): - """Set handler and config for the current request.""" - request = cherrypy.request - resource, vpath = self.find_handler(path_info) - - # Decode any leftover %2F in the virtual_path atoms. - vpath = [x.replace("%2F", "/") for x in vpath] - - if resource: - # Set Allow header - avail = [m for m in dir(resource) if m.isupper()] - if "GET" in avail and "HEAD" not in avail: - avail.append("HEAD") - avail.sort() - cherrypy.response.headers['Allow'] = ", ".join(avail) - - # Find the subhandler - meth = cherrypy.request.method.upper() - func = getattr(resource, meth, None) - if func is None and meth == "HEAD": - func = getattr(resource, "GET", None) - if func: - request.handler = LateParamPageHandler(func, *vpath) - else: - request.handler = cherrypy.HTTPError(405) - else: - request.handler = cherrypy.NotFound() - - def file_generator(input, chunkSize=65536): """Yield the given input (a file object) in chunks (default 64k).""" chunk = input.read(chunkSize) @@ -691,6 +685,7 @@ class Response(object): body = Body() time = None timed_out = False + stream = False def __init__(self): self.status = None @@ -725,14 +720,8 @@ class Response(object): self.status = "%s %s" % (code, reason) - stream = cherrypy.config.get("stream_response", False) - # OPTIONS requests MUST include a Content-Length of 0 if no body. - # Just punt and figure Content-Length for all OPTIONS requests. - if cherrypy.request.method == "OPTIONS": - stream = False - headers = self.headers - if stream: + if self.stream: headers.pop('Content-Length', None) else: # Responses which are not streamed should have a Content-Length, @@ -757,7 +746,7 @@ class Response(object): This purposefully sets a flag, rather than raising an error, so that a monitor thread can interrupt the Response thread. """ - timeout = float(cherrypy.config.get('deadlock_timeout', 300)) + timeout = float(cherrypy.config.get('deadlock.timeout', 300)) if time.time() > self.time + timeout: self.timed_out = True diff --git a/cherrypy/_cptools.py b/cherrypy/_cptools.py index ebb68117..f6e17271 100644 --- a/cherrypy/_cptools.py +++ b/cherrypy/_cptools.py @@ -234,7 +234,7 @@ class WSGIAppTool(MainTool): wsgi_app - any wsgi application callable env_update - a dictionary with arbitrary keys and values to be - merged with the WSGI environment dictionary. + merged with the WSGI environ dictionary. Example: diff --git a/cherrypy/_cptree.py b/cherrypy/_cptree.py index ea17f966..ac719b57 100644 --- a/cherrypy/_cptree.py +++ b/cherrypy/_cptree.py @@ -49,7 +49,7 @@ class Application(object): # Create log handlers as specified in config. rootconf = self.conf.get("/", {}) - config._configure_builtin_logging(rootconf, self.access_log, "log_access_file") + config._configure_builtin_logging(rootconf, self.access_log, "log.access.file") config._configure_builtin_logging(rootconf, self.error_log) def guess_abs_path(self): diff --git a/cherrypy/_cpwsgi.py b/cherrypy/_cpwsgi.py index c94a1737..cbb4f677 100644 --- a/cherrypy/_cpwsgi.py +++ b/cherrypy/_cpwsgi.py @@ -67,11 +67,11 @@ def _wsgi_callable(environ, start_response, app): request = None raise ex except: - if cherrypy.config.get("throw_errors", False): + if request and request.throw_errors: raise tb = format_exc() cherrypy.log(tb) - if not cherrypy.config.get("show_tracebacks", False): + if request and not request.show_tracebacks: tb = "" s, h, b = bare_error(tb) exc = sys.exc_info() @@ -135,8 +135,7 @@ class CPHTTPRequest(_cpwsgiserver.HTTPRequest): """Decode the 'chunked' transfer coding.""" if isinstance(self.rfile, http.SizeCheckWrapper): self.rfile = self.rfile.rfile - mbs = int(cherrypy.config.get('server.max_request_body_size', - 100 * 1024 * 1024)) + mbs = int(cherrypy.config.get('request.max_body_size', 100 * 1024 * 1024)) if mbs > 0: self.rfile = http.SizeCheckWrapper(self.rfile, mbs) try: diff --git a/cherrypy/config.py b/cherrypy/config.py index 7d36ac4d..01eb21a8 100644 --- a/cherrypy/config.py +++ b/cherrypy/config.py @@ -1,36 +1,109 @@ -"""Configuration system for CherryPy.""" +"""Configuration system for CherryPy. + +Configuration in CherryPy is implemented via dictionaries. Keys are strings +which name the mapped value, which may be of any type. + + +Architecture +------------ + +CherryPy Requests are part of an Application, which runs in a global context, +and configuration data may apply to any of those three scopes: + + Global: configuration entries which apply everywhere are stored in + cherrypy.config.globalconf. Use the top-level function 'config.update' + to modify it. + + Application: entries which apply to each mounted application are stored + on the Application object itself, as 'app.conf'. This is a two-level + dict where each key is a path, or "relative URL" (for example, "/" or + "/path/to/my/page"), and each value is a config dict. Usually, this + data is provided in the call to cherrypy.tree.mount(root(), conf=conf), + although you may also use app.merge(conf). + + Request: each Request object possesses a single 'Request.config' dict. + Early in the request process, this dict is populated by merging global + config entries, Application entries (whose path equals or is a parent + of Request.path_info), and any config acquired while looking up the + page handler (see next). + + +Usage +----- + +Configuration data may be supplied as a Python dictionary, as a filename, +or as an open file object. When you supply a filename or file, CherryPy +uses Python's builtin ConfigParser; you declare Application config by +writing each path as a section header: + + [/path/to/my/page] + request.stream = True + +To declare global configuration entries, place them in a [global] section. + +You may also declare config entries directly on the classes and methods +(page handlers) that make up your CherryPy application via the '_cp_config' +attribute. For example: + + class Demo: + _cp_config = {'tools.gzip.on': True} + + def index(self): + raise cherrypy.InternalRedirect("/cuba") + index.exposed = True + index._cp_config = {'request.recursive_redirect': True} + + +Namespaces +---------- + +Configuration keys are separated into namespaces by the first "." in the key. +Current namespaces: + + autoreload: Controls the autoreload mechanism in cherrypy.engine. + These can only be declared in the global config. + deadlock: Controls the deadlock monitoring system in cherrypy.engine. + These can only be declared in the global config. + hooks: Declares additional request-processing functions. + log: Configures the logging for each application. + request: Adds attributes to each Request during the tool_up phase. + response: Adds attributes to each Response during the tool_up phase. + server: Controls the default HTTP server via cherrypy.server. + These can only be declared in the global config. + tools: Runs and configures additional request-processing packages. + +The only key that does not exist in a namespace is the "environment" entry. +This special entry 'imports' other config entries from a template stored in +cherrypy.config.environments[environment]. It only applies to globalconf, +and only when you use "update" to modify globalconf. +""" import ConfigParser import logging as _logging _logfmt = _logging.Formatter("%(message)s") import os as _os +_localdir = _os.path.dirname(__file__) import cherrypy environments = { - "development": { - 'autoreload.on': True, - 'log_file_not_found': True, - 'show_tracebacks': True, - 'log_request_headers': True, - }, "staging": { 'autoreload.on': False, - 'log_file_not_found': False, - 'show_tracebacks': False, - 'log_request_headers': False, + 'tools.log_headers.on': False, + 'request.show_tracebacks': False, }, "production": { 'autoreload.on': False, - 'log_file_not_found': False, - 'show_tracebacks': False, - 'log_request_headers': False, + 'tools.log_headers.on': False, + 'request.show_tracebacks': False, + 'log.screen': False, }, - "embedded": { + "test_suite": { 'autoreload.on': False, - 'log_to_screen': False, - 'server.class': None, + 'tools.log_headers.on': False, + 'request.show_tracebacks': True, + 'log.screen': False, }, } @@ -39,23 +112,17 @@ def merge(base, other): if isinstance(other, basestring): if other not in cherrypy.engine.reload_files: cherrypy.engine.reload_files.append(other) - other = Parser().dict_from_file(other) + other = _Parser().dict_from_file(other) elif hasattr(other, 'read'): - other = Parser().dict_from_file(other) + other = _Parser().dict_from_file(other) # Load other into base for section, value_map in other.iteritems(): - # Resolve "environment" entries - if 'environment' in value_map: - env = environments[value_map['environment']] - for k in env: - if k not in value_map: - value_map[k] = env[k] - del value_map['environment'] - base.setdefault(section, {}).update(value_map) + default_conf = { + # Server config 'server.socket_port': 8080, 'server.socket_host': '', 'server.socket_file': '', @@ -64,13 +131,30 @@ default_conf = { 'server.protocol_version': 'HTTP/1.1', 'server.reverse_dns': False, 'server.thread_pool': 10, - 'log_to_screen': True, - 'log_file': _os.path.join(_os.getcwd(), _os.path.dirname(__file__), - "error.log"), + 'server.max_request_header_size': 500 * 1024, + 'server.instance': None, + + # Log config + 'log.to_screen': True, +## 'log.error.function': cherrypy._log_message, + 'log.error.file': _os.path.join(_os.getcwd(), _localdir, "error.log"), + # Using an access file makes CP about 10% slower. +## 'log.access.function': cherrypy.log_access, +## 'log.access.file': _os.path.join(_os.getcwd(), _localdir, "access.log"), + + # Process management + 'autoreload.on': True, + 'autoreload.frequency': 1, + 'deadlock.timeout': 300, + 'deadlock.poll_freq': 60, + + 'error_page.404': '', + 'tools.log_tracebacks.on': True, - 'environment': "development", + 'tools.log_headers.on': True, } + globalconf = default_conf.copy() def reset(): @@ -82,9 +166,9 @@ def update(conf): if isinstance(conf, basestring): if conf not in cherrypy.engine.reload_files: cherrypy.engine.reload_files.append(conf) - conf = Parser().dict_from_file(conf) + conf = _Parser().dict_from_file(conf) elif hasattr(conf, 'read'): - conf = Parser().dict_from_file(conf) + conf = _Parser().dict_from_file(conf) if isinstance(conf.get("global", None), dict): conf = conf["global"] @@ -101,7 +185,7 @@ def update(conf): globalconf.update(conf) _configure_builtin_logging(globalconf, cherrypy._error_log) - _configure_builtin_logging(globalconf, cherrypy._access_log, "log_access_file") + _configure_builtin_logging(globalconf, cherrypy._access_log, "log.access.file") def _add_builtin_screen_handler(log): import sys @@ -118,13 +202,13 @@ def _add_builtin_file_handler(log, fname): h._cpbuiltin = "file" log.addHandler(h) -def _configure_builtin_logging(conf, log, filekey="log_file"): +def _configure_builtin_logging(conf, log, filekey="log.error.file"): """Create/destroy builtin log handlers as needed from conf.""" existing = dict([(getattr(x, "_cpbuiltin", None), x) for x in log.handlers]) h = existing.get("screen") - screen = conf.get('log_to_screen') + screen = conf.get('log.screen') if screen: if not h: _add_builtin_screen_handler(log) @@ -169,7 +253,7 @@ def wrap(**kwargs): return wrapper -class Parser(ConfigParser.ConfigParser): +class _Parser(ConfigParser.ConfigParser): """Sub-class of ConfigParser that keeps the case of options and that raises an exception if the file cannot be read. """ @@ -226,8 +310,8 @@ def log_config(): server_vars = [ 'environment', - 'log_to_screen', - 'log_file', + 'log.screen', + 'log.error.file', 'server.protocol_version', 'server.socket_host', 'server.socket_port', diff --git a/cherrypy/lib/encoding.py b/cherrypy/lib/encoding.py index 989c8460..2a6a8846 100644 --- a/cherrypy/lib/encoding.py +++ b/cherrypy/lib/encoding.py @@ -88,8 +88,7 @@ def find_acceptable_charset(encoding=None, default_encoding='utf-8', errors='str attempted_charsets = [] - stream = cherrypy.config.get("stream_response", False) - if stream: + if cherrypy.response.stream: encoder = encode_stream else: response.collapse_body() diff --git a/cherrypy/lib/static.py b/cherrypy/lib/static.py index fe61df15..83d9c272 100644 --- a/cherrypy/lib/static.py +++ b/cherrypy/lib/static.py @@ -38,8 +38,6 @@ def serve_file(path, content_type=None, disposition=None, name=None): try: stat = os.stat(path) except OSError: - if cherrypy.config.get('log_file_not_found', False): - cherrypy.log(" NOT FOUND file: %s" % path, "DEBUG") raise cherrypy.NotFound() if os.path.isdir(path): diff --git a/cherrypy/lib/wsgiapp.py b/cherrypy/lib/wsgiapp.py index 4003d7ac..9743fd43 100644 --- a/cherrypy/lib/wsgiapp.py +++ b/cherrypy/lib/wsgiapp.py @@ -17,7 +17,7 @@ def make_environ(): for hosting WSGI apps in non-WSGI environments (yikes!) """ - # create and populate the wsgi environment + # create and populate the wsgi environ environ = dict() environ["wsgi.version"] = (1,0) environ["wsgi.url_scheme"] = cherrypy.request.scheme diff --git a/cherrypy/test/__init__.py b/cherrypy/test/__init__.py index 49f2e1ea..eef14d44 100644 --- a/cherrypy/test/__init__.py +++ b/cherrypy/test/__init__.py @@ -3,16 +3,3 @@ Run test.py to exercise all tests. """ -# Ideas for future tests: -# - test if tabs and whitespaces are handled correctly in source file (option -W) -# - test if absolute pathnames work fine on windows -# - test sessions -# - test threading server -# - test forking server -# - test process pooling server -# - test SSL -# - test compilator errors -# - test abstract classes -# - test hidden classes -# ... - diff --git a/cherrypy/test/benchmark.py b/cherrypy/test/benchmark.py index f3a839c0..a8186651 100644 --- a/cherrypy/test/benchmark.py +++ b/cherrypy/test/benchmark.py @@ -60,13 +60,12 @@ class Root: cherrypy.config.update({ - 'log_to_screen': False, -## 'log_file': os.path.join(curdir, "bench.log"), + 'log.error.file': '', 'environment': 'production', 'server.socket_host': 'localhost', 'server.socket_port': 8080, 'server.max_request_header_size': 0, - 'server.max_request_body_size': 0, + 'request.max_body_size': 0, }) appconf = { diff --git a/cherrypy/test/modpy.py b/cherrypy/test/modpy.py index 2d9f5ef1..6fa8a7d0 100644 --- a/cherrypy/test/modpy.py +++ b/cherrypy/test/modpy.py @@ -110,7 +110,7 @@ def wsgisetup(req): import cherrypy cherrypy.config.update({ - "log_file": os.path.join(curdir, "test.log"), + "log.error.file": os.path.join(curdir, "test.log"), "environment": "production", }) cherrypy.engine.start(blocking=False) diff --git a/cherrypy/test/test.py b/cherrypy/test/test.py index 7044567f..54225cbd 100644 --- a/cherrypy/test/test.py +++ b/cherrypy/test/test.py @@ -43,9 +43,7 @@ class TestHarness(object): baseconf = {'server.socket_host': '127.0.0.1', 'server.socket_port': self.port, 'server.thread_pool': 10, - 'log_to_screen': False, - 'environment': "production", - 'show_tracebacks': True, + 'environment': "test_suite", } baseconf.update(conf or {}) diff --git a/cherrypy/test/test_caching.py b/cherrypy/test/test_caching.py index 44533423..54665914 100644 --- a/cherrypy/test/test_caching.py +++ b/cherrypy/test/test_caching.py @@ -58,11 +58,7 @@ def setup_server(): cherrypy.tree.mount(Root()) cherrypy.tree.mount(UnCached(), "/expires") - cherrypy.config.update({ - 'log_to_screen': False, - 'environment': 'production', - 'show_tracebacks': True, - }) + cherrypy.config.update({'environment': 'test_suite'}) from cherrypy.test import helper diff --git a/cherrypy/test/test_config.py b/cherrypy/test/test_config.py index 03e59ce6..b7fe3cc7 100644 --- a/cherrypy/test/test_config.py +++ b/cherrypy/test/test_config.py @@ -34,28 +34,17 @@ def setup_server(): bar.exposed = True bar._cp_config = {'foo': 'this3', 'bax': 'this4'} - class Env: + class Another: def index(self, key): return str(cherrypy.config.get(key, "None")) index.exposed = True - prod = index - embed = index root = Root() root.foo = Foo() cherrypy.tree.mount(root) - - cherrypy.config.update({'log_to_screen': False, - 'environment': 'production', - 'show_tracebacks': True, - }) - - _env_conf = {'/': {'environment': 'development'}, - '/prod': {'environment': 'production'}, - '/embed': {'environment': 'embedded'}, - } - cherrypy.tree.mount(Env(), "/env", _env_conf) + cherrypy.tree.mount(Another(), "/another") + cherrypy.config.update({'environment': 'test_suite'}) # Shortcut syntax--should get put in the "global" bucket cherrypy.config.update({'luxuryyacht': 'throatwobblermangrove'}) @@ -78,23 +67,12 @@ class ConfigTests(helper.CPWebCase): ('/foo/', 'bax', 'None'), ('/foo/bar', 'baz', 'that2'), ('/foo/nex', 'baz', 'that2'), - # If 'foo' == 'this', then the mount point '/env' leaks into '/'. - ('/env/prod','foo', 'None'), + # If 'foo' == 'this', then the mount point '/another' leaks into '/'. + ('/another/','foo', 'None'), ] for path, key, expected in tests: self.getPage(path + "?key=" + key) self.assertBody(expected) - - def testEnvironments(self): - for key, val in cherrypy.config.environments['development'].iteritems(): - self.getPage("/env/?key=" + key) - self.assertBody(str(val)) - for key, val in cherrypy.config.environments['production'].iteritems(): - self.getPage("/env/prod/?key=" + key) - self.assertBody(str(val)) - for key, val in cherrypy.config.environments['embedded'].iteritems(): - self.getPage("/env/embed/?key=" + key) - self.assertBody(str(val)) if __name__ == '__main__': diff --git a/cherrypy/test/test_conn.py b/cherrypy/test/test_conn.py index 47c95566..75120324 100644 --- a/cherrypy/test/test_conn.py +++ b/cherrypy/test/test_conn.py @@ -28,7 +28,7 @@ def setup_server(): for x in xrange(10): yield str(x) stream.exposed = True - stream._cp_config = {'stream_response': True} + stream._cp_config = {'response.stream': True} def upload(self): return ("thanks for '%s' (%s)" % @@ -38,10 +38,8 @@ def setup_server(): cherrypy.tree.mount(Root()) cherrypy.config.update({ - 'log_to_screen': False, - 'server.max_request_body_size': 100, - 'show_tracebacks': True, - 'environment': 'production', + 'request.max_body_size': 100, + 'environment': 'test_suite', }) @@ -222,7 +220,7 @@ class ConnectionTests(helper.CPWebCase): self.assertStatus('200 OK') self.assertBody("thanks for 'xx\r\nxxxxyyyyy' (application/x-json)") - # Try a chunked request that exceeds max_request_body_size. + # Try a chunked request that exceeds request.max_body_size. # Note that the delimiters and trailer are included. body = "5f\r\n" + ("x" * 95) + "\r\n0\r\n\r\n" conn.putrequest("POST", "/upload", skip_host=True) diff --git a/cherrypy/test/test_core.py b/cherrypy/test/test_core.py index 81acf3f2..ff11bfed 100644 --- a/cherrypy/test/test_core.py +++ b/cherrypy/test/test_core.py @@ -219,23 +219,23 @@ def setup_server(): raise ValueError() # We support Python 2.3, but the @-deco syntax would look like this: - # @cherrypy.config.wrap(stream_response=True) + # @cherrypy.config.wrap(**{"response.stream": True}) def page_streamed(self): yield "word up" raise ValueError() yield "very oops" - page_streamed = cherrypy.config.wrap(stream_response=True)(page_streamed) - assert(page_streamed._cp_config == {'stream_response': True}) + page_streamed = cherrypy.config.wrap(**{"response.stream": True})(page_streamed) + assert(page_streamed._cp_config == {'response.stream': True}) def cause_err_in_finalize(self): # Since status must start with an int, this should error. cherrypy.response.status = "ZOO OK" - cause_err_in_finalize._cp_config = {'show_tracebacks': False} + cause_err_in_finalize._cp_config = {'request.show_tracebacks': False} def rethrow(self): """Test that an error raised here will be thrown out to the server.""" raise ValueError() - rethrow._cp_config = {'throw_errors': True} + rethrow._cp_config = {'request.throw_errors': True} class Ranges(Test): @@ -370,19 +370,14 @@ def setup_server(): return u'Wrong login/password' cherrypy.config.update({ - 'log_to_screen': False, - 'log_file': log_file, - 'environment': 'production', - 'show_tracebacks': True, - 'server.max_request_body_size': 200, + 'log.error.file': log_file, + 'environment': 'test_suite', + 'request.max_body_size': 200, 'server.max_request_header_size': 500, }) - - def expand_methods(): - cherrypy.request.methods_with_bodies = ("POST", "PUT", "PROPFIND") appconf = { - '/': {'log_access_file': log_access_file}, - '/method': {'hooks.on_start_resource': expand_methods}, + '/': {'log.access.file': log_access_file}, + '/method': {'request.methods_with_bodies': ("POST", "PUT", "PROPFIND")}, } cherrypy.tree.mount(root, conf=appconf) @@ -643,10 +638,10 @@ class CoreRequestHandlingTest(helper.CPWebCase): "In addition, the custom error page failed:\n<br />" "[Errno 2] No such file or directory: 'nonexistent.html'") self.assertInBody(msg) -## -## # Test throw_errors (ticket #186). -## self.getPage("/error/rethrow") -## self.assertBody("THROWN ERROR: ValueError") + + # Test throw_errors (ticket #186). + self.getPage("/error/rethrow") + self.assertInBody("raise ValueError()") def testRanges(self): self.getPage("/ranges/get_ranges", [('Range', 'bytes=3-6')]) diff --git a/cherrypy/test/test_decodingencoding.py b/cherrypy/test/test_decodingencoding.py index ab783cae..9e5fdacc 100644 --- a/cherrypy/test/test_decodingencoding.py +++ b/cherrypy/test/test_decodingencoding.py @@ -21,8 +21,7 @@ def setup_server(): cherrypy.tree.mount(Root()) cherrypy.config.update({ - 'log_to_screen': False, - 'environment': 'production', + 'environment': 'test_suite', 'tools.encode.on': True, 'tools.decode.on': True, }) diff --git a/cherrypy/test/test_etags.py b/cherrypy/test/test_etags.py index 6c40e611..da191719 100644 --- a/cherrypy/test/test_etags.py +++ b/cherrypy/test/test_etags.py @@ -14,19 +14,10 @@ def setup_server(): raise cherrypy.HTTPError(412) fail.exposed = True - conf = { - '/': { - 'tools.etags.on': True, - 'tools.etags.autotags': True, - }, - } + conf = {'/': {'tools.etags.on': True, + 'tools.etags.autotags': True}} cherrypy.tree.mount(Root(), conf=conf) - - cherrypy.config.update({ - 'log_to_screen': False, - 'environment': 'production', - 'show_tracebacks': True, - }) + cherrypy.config.update({'environment': 'test_suite'}) from cherrypy.test import helper diff --git a/cherrypy/test/test_gzip.py b/cherrypy/test/test_gzip.py index 17b50c59..aac8db91 100644 --- a/cherrypy/test/test_gzip.py +++ b/cherrypy/test/test_gzip.py @@ -23,16 +23,11 @@ def setup_server(): raise IndexError() yield "Here be dragons" noshow_stream.exposed = True - noshow_stream._cp_config = {'stream_response': True} + noshow_stream._cp_config = {'response.stream': True} cherrypy.tree.mount(Root()) - cherrypy.config.update({ - 'global': {'log_to_screen': False, - 'environment': 'production', - 'show_tracebacks': True, - 'tools.gzip.on': True, - }, - }) + cherrypy.config.update({'environment': 'test_suite', + 'tools.gzip.on': True}) from cherrypy.test import helper diff --git a/cherrypy/test/test_http.py b/cherrypy/test/test_http.py index ab45fa07..91a7d7a4 100644 --- a/cherrypy/test/test_http.py +++ b/cherrypy/test/test_http.py @@ -35,13 +35,7 @@ def setup_server(): len(gc.get_referrers(data))) gc_stats.exposed = True cherrypy.tree.mount(Root()) - - cherrypy.config.update({ - 'global': {'log_to_screen': False, - 'environment': 'production', - 'show_tracebacks': True, - }, - }) + cherrypy.config.update({'environment': 'test_suite'}) from cherrypy.test import helper diff --git a/cherrypy/test/test_objectmapping.py b/cherrypy/test/test_objectmapping.py index 1540a4fe..33ad1468 100644 --- a/cherrypy/test/test_objectmapping.py +++ b/cherrypy/test/test_objectmapping.py @@ -126,14 +126,11 @@ def setup_server(): for url in script_names: d = cherrypy._cprequest.MethodDispatcher() conf = {'/': {'user': (url or "/").split("/")[-2]}, - '/bymethod': {'dispatch': d}, + '/bymethod': {'request.dispatch': d}, } cherrypy.tree.mount(Root(), url, conf) - cherrypy.config.update({ - 'log_to_screen': False, - 'environment': "production", - }) + cherrypy.config.update({'environment': "test_suite"}) class Isolated: diff --git a/cherrypy/test/test_proxy.py b/cherrypy/test/test_proxy.py index 90668ca8..731cc047 100644 --- a/cherrypy/test/test_proxy.py +++ b/cherrypy/test/test_proxy.py @@ -21,11 +21,10 @@ def setup_server(): cherrypy.tree.mount(Root()) cherrypy.config.update({ - 'environment': 'production', - 'log_to_screen': False, - 'tools.proxy.on': True, - 'tools.proxy.base': 'http://www.mydomain.com', - }) + 'environment': 'test_suite', + 'tools.proxy.on': True, + 'tools.proxy.base': 'http://www.mydomain.com', + }) from cherrypy.test import helper diff --git a/cherrypy/test/test_response_headers.py b/cherrypy/test/test_response_headers.py index 44cd1528..f3346447 100644 --- a/cherrypy/test/test_response_headers.py +++ b/cherrypy/test/test_response_headers.py @@ -23,10 +23,7 @@ def setup_server(): } cherrypy.tree.mount(Root()) - cherrypy.config.update({ - 'log_to_screen': False, - 'environment': 'production', - }) + cherrypy.config.update({'environment': 'test_suite'}) from cherrypy.test import helper diff --git a/cherrypy/test/test_session.py b/cherrypy/test/test_session.py index e8695df2..1943f9d0 100755 --- a/cherrypy/test/test_session.py +++ b/cherrypy/test/test_session.py @@ -45,10 +45,7 @@ def setup_server(): index.exposed = True cherrypy.tree.mount(Root()) - cherrypy.config.update({ - 'log_to_screen': False, - 'environment': 'production', - }) + cherrypy.config.update({'environment': 'test_suite'}) from cherrypy.test import helper diff --git a/cherrypy/test/test_sessionauthenticate.py b/cherrypy/test/test_sessionauthenticate.py index c53fb59f..ed269d28 100644 --- a/cherrypy/test/test_sessionauthenticate.py +++ b/cherrypy/test/test_sessionauthenticate.py @@ -22,10 +22,7 @@ def setup_server(): index.exposed = True cherrypy.tree.mount(Test()) - cherrypy.config.update({ - 'log_to_screen': False, - 'environment': 'production', - }) + cherrypy.config.update({'environment': 'test_suite'}) from cherrypy.test import helper diff --git a/cherrypy/test/test_states.py b/cherrypy/test/test_states.py index 1ff13e9d..dfb530a6 100644 --- a/cherrypy/test/test_states.py +++ b/cherrypy/test/test_states.py @@ -34,14 +34,13 @@ class Root: def block_implicit(self): raise cherrypy.InternalRedirect("/block_implicit") block_implicit.exposed = True - block_implicit._cp_config = {'recursive_redirect': True} + block_implicit._cp_config = {'request.recursive_redirect': True} cherrypy.tree.mount(Root()) cherrypy.config.update({ - 'log_to_screen': False, - 'environment': 'production', - 'deadlock_poll_freq': 1, - 'deadlock_timeout': 2, + 'environment': 'test_suite', + 'deadlock.poll_freq': 1, + 'deadlock.timeout': 2, }) class Dependency: @@ -298,10 +297,7 @@ def run_all(host, port): conf = {'server.socket_host': host, 'server.socket_port': port, 'server.thread_pool': 10, - 'log_to_screen': False, - 'log_config': False, - 'environment': "production", - 'show_tracebacks': True, + 'environment': "test_suite", } def _run(server): print @@ -315,10 +311,7 @@ def run_localhosts(port): conf = {'server.socket_host': host, 'server.socket_port': port, 'server.thread_pool': 10, - 'log_to_screen': False, - 'log_config': False, - 'environment': "production", - 'show_tracebacks': True, + 'environment': "test_suite", } def _run(server): print diff --git a/cherrypy/test/test_states_demo.py b/cherrypy/test/test_states_demo.py index 55c046fe..d2eceb7f 100644 --- a/cherrypy/test/test_states_demo.py +++ b/cherrypy/test/test_states_demo.py @@ -23,8 +23,7 @@ class Root: if __name__ == '__main__': cherrypy.config.update({"server.socket_host": sys.argv[1], "server.socket_port": int(sys.argv[2]), - "log_to_screen": False, - "environment": "development", + "log.screen": False, }) cherrypy.quickstart(Root()) -
\ No newline at end of file +
\ No newline at end of file diff --git a/cherrypy/test/test_static.py b/cherrypy/test/test_static.py index 3f3c0433..16b10781 100644 --- a/cherrypy/test/test_static.py +++ b/cherrypy/test/test_static.py @@ -44,16 +44,12 @@ def setup_server(): }, '/error': { 'tools.staticdir.on': True, - 'show_tracebacks': True, + 'request.show_tracebacks': True, }, } cherrypy.tree.mount(root, conf=conf) - - cherrypy.config.update({ - 'log_to_screen': False, - 'environment': 'production', - }) + cherrypy.config.update({'environment': 'test_suite'}) from cherrypy.test import helper diff --git a/cherrypy/test/test_tools.py b/cherrypy/test/test_tools.py index d9877aed..fdbf5159 100644 --- a/cherrypy/test/test_tools.py +++ b/cherrypy/test/test_tools.py @@ -149,10 +149,7 @@ def setup_server(): return "success!" - cherrypy.config.update({'log_to_screen': False, - 'environment': 'production', - 'show_tracebacks': True, - }) + cherrypy.config.update({'environment': 'test_suite'}) conf = { # METHOD THREE: @@ -162,10 +159,10 @@ def setup_server(): 'tools.numerify.map': {"pie": "3.14159"}, }, '/demo/restricted': { - 'show_tracebacks': False, + 'request.show_tracebacks': False, }, '/demo/errinstream': { - 'stream_response': True, + 'response.stream': True, }, '/demo/err_in_onstart': { # Because this isn't a dict, on_start_resource will error. diff --git a/cherrypy/test/test_tutorials.py b/cherrypy/test/test_tutorials.py index 853d98e0..a15e43a1 100644 --- a/cherrypy/test/test_tutorials.py +++ b/cherrypy/test/test_tutorials.py @@ -36,7 +36,7 @@ def setup_server(): sessions.exposed = True def traceback_setting(): - return repr(cherrypy.config.get('show_tracebacks')) + return repr(cherrypy.config.get('request.show_tracebacks')) traceback_setting.exposed = True class Dummy: @@ -205,9 +205,7 @@ if __name__ == "__main__": conf = {'server.socket_host': '127.0.0.1', 'server.socket_port': 8080, 'server.thread_pool': 10, - 'log_to_screen': False, - 'environment': "production", - 'show_tracebacks': True, + 'environment': "test_suite", } cherrypy.config.update(conf) setup_server() diff --git a/cherrypy/test/test_virtualhost.py b/cherrypy/test/test_virtualhost.py index a69a9c9f..0d51c90b 100644 --- a/cherrypy/test/test_virtualhost.py +++ b/cherrypy/test/test_virtualhost.py @@ -37,13 +37,12 @@ def setup_server(): cherrypy.tree.mount(root) cherrypy.config.update({ - 'log_to_screen': False, - 'environment': 'production', - 'tools.virtual_host.on': True, - 'tools.virtual_host.www.mydom2.com': '/mydom2', - 'tools.virtual_host.www.mydom3.com': '/mydom3', - 'tools.virtual_host.www.mydom4.com': '/dom4', - }) + 'environment': 'test_suite', + 'tools.virtual_host.on': True, + 'tools.virtual_host.www.mydom2.com': '/mydom2', + 'tools.virtual_host.www.mydom3.com': '/mydom3', + 'tools.virtual_host.www.mydom4.com': '/dom4', + }) from cherrypy.test import helper diff --git a/cherrypy/test/test_wsgiapps.py b/cherrypy/test/test_wsgiapps.py index 4b4fe75e..63363e61 100644 --- a/cherrypy/test/test_wsgiapps.py +++ b/cherrypy/test/test_wsgiapps.py @@ -40,10 +40,7 @@ def setup_server(): 'tools.wsgiapp.app': test_app, } - cherrypy.config.update({'log_to_screen': False, - 'environment': 'production', - 'show_tracebacks': True, - }) + cherrypy.config.update({'environment': 'test_suite'}) cherrypy.tree.mount(Root()) conf0 = {'/static': {'tools.staticdir.on': True, diff --git a/cherrypy/test/test_xmlrpc.py b/cherrypy/test/test_xmlrpc.py index 4018eb97..ca099f89 100644 --- a/cherrypy/test/test_xmlrpc.py +++ b/cherrypy/test/test_xmlrpc.py @@ -58,11 +58,7 @@ def setup_server(): root = Root() root.xmlrpc = XmlRpc() cherrypy.tree.mount(root) - cherrypy.config.update({ - 'log_to_screen': False, - 'environment': 'production', - 'show_tracebacks': True, - }) + cherrypy.config.update({'environment': 'test_suite'}) from cherrypy.test import helper diff --git a/cherrypy/tutorial/tut10_http_errors.py b/cherrypy/tutorial/tut10_http_errors.py index e57ec396..f6d29cf2 100644 --- a/cherrypy/tutorial/tut10_http_errors.py +++ b/cherrypy/tutorial/tut10_http_errors.py @@ -22,7 +22,7 @@ class HTTPErrorDemo(object): def index(self): # display some links that will result in errors - tracebacks = cherrypy.config.get('show_tracebacks') + tracebacks = cherrypy.config.get('request.show_tracebacks') if tracebacks: trace = 'off' else: @@ -48,8 +48,8 @@ class HTTPErrorDemo(object): def toggleTracebacks(self): # simple function to toggle tracebacks on and off - tracebacks = cherrypy.config.get('show_tracebacks') - cherrypy.config.update({'show_tracebacks': not tracebacks}) + tracebacks = cherrypy.config.get('request.show_tracebacks') + cherrypy.config.update({'request.show_tracebacks': not tracebacks}) # redirect back to the index raise cherrypy.HTTPRedirect('/') diff --git a/cherrypy/tutorial/tutorial.conf b/cherrypy/tutorial/tutorial.conf index 3420f515..69ac7796 100644 --- a/cherrypy/tutorial/tutorial.conf +++ b/cherrypy/tutorial/tutorial.conf @@ -1,6 +1,3 @@ [global]
server.socket_port = 8080
server.thread_pool = 10
-environment = "production"
-# show_tracebacks = True
-log_to_screen = True
|