Changeset 908
- Timestamp:
- 01/02/06 02:29:42
- Files:
-
- branches/multiapp/cherrypy/__init__.py (modified) (3 diffs)
- branches/multiapp/cherrypy/_cphttpserver.py (modified) (11 diffs)
- branches/multiapp/cherrypy/_cphttptools.py (modified) (7 diffs)
- branches/multiapp/cherrypy/_cpserver.py (modified) (7 diffs)
- branches/multiapp/cherrypy/_cputil.py (modified) (5 diffs)
- branches/multiapp/cherrypy/_cpwsgi.py (modified) (5 diffs)
- branches/multiapp/cherrypy/config.py (modified) (8 diffs)
- branches/multiapp/cherrypy/filters/__init__.py (modified) (2 diffs)
- branches/multiapp/cherrypy/filters/cachefilter.py (modified) (1 diff)
- branches/multiapp/cherrypy/lib/covercp.py (modified) (1 diff)
- branches/multiapp/cherrypy/lib/cptools.py (modified) (2 diffs)
- branches/multiapp/cherrypy/lib/httptools.py (modified) (2 diffs)
- branches/multiapp/cherrypy/lib/profiler.py (modified) (1 diff)
- branches/multiapp/cherrypy/test/__init__.py (modified) (1 diff)
- branches/multiapp/cherrypy/test/custom_filters.py (added)
- branches/multiapp/cherrypy/test/helper.py (modified) (7 diffs)
- branches/multiapp/cherrypy/test/test.py (modified) (3 diffs)
- branches/multiapp/cherrypy/test/test_baseurl_filter.py (modified) (2 diffs)
- branches/multiapp/cherrypy/test/test_cache_filter.py (modified) (1 diff)
- branches/multiapp/cherrypy/test/test_combinedfilters.py (modified) (1 diff)
- branches/multiapp/cherrypy/test/test_config.py (modified) (3 diffs)
- branches/multiapp/cherrypy/test/test_core.py (modified) (23 diffs)
- branches/multiapp/cherrypy/test/test_custom_filters.py (modified) (5 diffs)
- branches/multiapp/cherrypy/test/test_decodingencoding_filter.py (modified) (1 diff)
- branches/multiapp/cherrypy/test/test_gzip_filter.py (modified) (1 diff)
- branches/multiapp/cherrypy/test/test_logdebuginfo_filter.py (modified) (2 diffs)
- branches/multiapp/cherrypy/test/test_noserver.py (modified) (2 diffs)
- branches/multiapp/cherrypy/test/test_objectmapping.py (modified) (1 diff)
- branches/multiapp/cherrypy/test/test_response_headers_filter.py (modified) (2 diffs)
- branches/multiapp/cherrypy/test/test_session_filter.py (modified) (1 diff)
- branches/multiapp/cherrypy/test/test_sessionauthenticate_filter.py (modified) (2 diffs)
- branches/multiapp/cherrypy/test/test_states.py (modified) (3 diffs)
- branches/multiapp/cherrypy/test/test_static_filter.py (modified) (2 diffs)
- branches/multiapp/cherrypy/test/test_tutorials.py (modified) (3 diffs)
- branches/multiapp/cherrypy/test/test_virtualhost_filter.py (modified) (2 diffs)
- branches/multiapp/cherrypy/test/test_xmlrpc_filter.py (modified) (3 diffs)
- branches/multiapp/cherrypy/tutorial/bonus-sqlobject.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tut01_helloworld.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tut02_expose_methods.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tut03_get_and_post.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tut04_complex_site.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tut05_derived_objects.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tut06_default_method.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tut07_sessions.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tut08_generators_and_yield.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tut09_files.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tut10_http_errors.py (modified) (1 diff)
- branches/multiapp/cherrypy/tutorial/tutorial.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/multiapp/cherrypy/__init__.py
r887 r908 4 4 5 5 import datetime 6 import os 6 7 import sys 7 8 import types … … 19 20 from cherrypy._cpthreadinglocal import local 20 21 21 # Create a threadlocal object to hold the request and response22 # objects. In this way, we can easily dump those objects when22 # Create a threadlocal object to hold the app, request and response 23 # references. In this way, we can easily dump those objects when 23 24 # we stop/start a new HTTP conversation, yet still refer to 24 25 # them as module-level globals in a thread-safe way. 25 serving = local() 26 class _Serving(local): 27 28 def __init__(self): 29 # Called each time the local object is used in a separate thread. 30 # When those threads are HTTP conversation threads, the 31 # cherrypy.server object will re-assign these attributes asap. 32 # When the local thread is a main thread (not part of an HTTP 33 # request), only self.app should be re-assigned. Call 34 # cherrypy.use(app) to set it more easily in app code. 35 self.app = None 36 self.request = None 37 self.response = None 38 39 serving = _Serving() 40 41 42 class Application(object): 43 44 def __init__(self, root=None): 45 self.root = root 46 self.config = { 47 'global': { 48 'server.environment': "development", 49 }, 50 '/favicon.ico': { 51 'static_filter.on': True, 52 'static_filter.file': os.path.join(os.path.dirname(__file__), 53 "favicon.ico"), 54 }, 55 } 56 57 def mount_point(self): 58 return self.config["global"].get("http.mount_point", "/") 59 60 def dispatch_path(self, mounted_path): 61 path = mounted_path[len(self.mount_point()):] 62 if not path.startswith("/"): 63 path = "/" + path 64 return path 65 66 67 apps = [] 68 69 def use(app): 70 """Use the given Application object in the current thread.""" 71 serving.app = app 72 if app not in apps: 73 apps.append(app) 74 75 def new(root=None): 76 """Return a new Application object and use it in the current thread.""" 77 app = Application(root) 78 use(app) 79 return app 80 81 def dispatch(path): 82 """Return and use() an Application object based on the given path.""" 83 matches = [] 84 for app in apps: 85 mount = app.mount_point() 86 if path.startswith(mount): 87 matches.append((mount, app)) 88 89 if not matches: 90 raise NotFound(path) 91 92 # Use the longest matching mount point 93 matches.sort() 94 mount, app = matches[-1] 95 96 use(app) 97 return app 98 26 99 27 100 class _ThreadLocalProxy: … … 42 115 delattr(childobject, name) 43 116 44 # Create request and response object (the same objects will be used117 # Create app, request and response object (the same objects will be used 45 118 # throughout the entire life of the webserver, but will redirect 46 119 # to the "serving" object) 120 app = _ThreadLocalProxy('app') 47 121 request = _ThreadLocalProxy('request') 48 122 response = _ThreadLocalProxy('response') branches/multiapp/cherrypy/_cphttpserver.py
r887 r908 20 20 def address_string(self): 21 21 """ Try to do a reverse DNS based on server.reverse_dns in the config file """ 22 if cherrypy.config. get('server.reverse_dns'):22 if cherrypy.config.serverconf.get('server.reverse_dns'): 23 23 return BaseHTTPRequestHandler.address_string(self) 24 24 else: … … 42 42 43 43 def parse_request(self): 44 conf = cherrypy.config.serverconf.get 44 45 # Extended to provide header and body length limits. 45 mhs = int(cherrypy.config.get('server.max_request_header_size', 46 500 * 1024)) 46 mhs = int(conf('server.max_request_header_size', 500 * 1024)) 47 47 self.rfile = httptools.SizeCheckWrapper(self.rfile, mhs) 48 48 try: … … 60 60 if path == "*": 61 61 path = "global" 62 mbs = int(cherrypy.config.get('server.max_request_body_size', 63 100 * 1024 * 1024, path=path)) 62 mbs = int(conf('server.max_request_body_size', 100 * 1024 * 1024)) 64 63 self.rfile.maxlen = mbs 65 64 return presult … … 67 66 def handle_one_request(self): 68 67 """Handle a single HTTP request.""" 68 conf = cherrypy.config.serverconf.get 69 69 70 70 self.raw_requestline = self.rfile.readline() … … 79 79 request = cherrypy.server.request(self.client_address, 80 80 self.address_string(), "http") 81 request.multithread = c herrypy.config.get("server.thread_pool") > 181 request.multithread = conf("server.thread_pool") > 1 82 82 request.multiprocess = False 83 83 response = request.run(self.raw_requestline, self._headerlist(), … … 88 88 raise 89 89 except: 90 tb = _cputil.formatExc() 91 cherrypy.log(tb) 92 if cherrypy.config.get("server.throw_errors", False): 90 cherrypy.log(traceback=True) 91 if conf("server.throw_errors", False): 93 92 msg = "THROWN ERROR: %s" % sys.exc_info()[0].__name__ 94 93 s = "500 Internal Server Error" … … 97 96 b = [msg] 98 97 else: 99 if not cherrypy.config.get("server.show_tracebacks", False): 100 tb = "" 101 s, h, b = _cputil.bareError(tb) 98 s, h, b = _cputil.bareError() 102 99 103 100 try: … … 181 178 # but we have to in order to implement SSL and IPv6 support! 182 179 180 conf = cherrypy.config.serverconf.get 181 183 182 # Set protocol_version 184 httpproto = c herrypy.config.get('server.protocol_version') or "HTTP/1.0"183 httpproto = conf('server.protocol_version') or "HTTP/1.0" 185 184 self.RequestHandlerClass.protocol_version = httpproto 186 185 187 self.request_queue_size = c herrypy.config.get('server.socket_queue_size')186 self.request_queue_size = conf('server.socket_queue_size') 188 187 189 188 # Select the appropriate server based on config options 190 sockFile = c herrypy.config.get('server.socket_file')189 sockFile = conf('server.socket_file') 191 190 if sockFile: 192 191 # AF_UNIX socket … … 206 205 else: 207 206 # AF_INET or AF_INET6 socket 208 host = c herrypy.config.get('server.socket_host')209 port = c herrypy.config.get('server.socket_port')207 host = conf('server.socket_host') 208 port = conf('server.socket_port') 210 209 self.server_address = (host, port) 211 210 … … 314 313 315 314 def __init__(self): 316 self.numThreads = cherrypy.config. get('server.thread_pool')315 self.numThreads = cherrypy.config.serverconf.get('server.thread_pool') 317 316 self.ThreadClass = ServerThread 318 317 self.requestQueue = Queue.Queue() … … 399 398 400 399 # Select the appropriate server based on config options 401 if cherrypy.config. get('server.thread_pool', 1) > 1:400 if cherrypy.config.serverconf.get('server.thread_pool', 1) > 1: 402 401 ServerClass = PooledThreadServer 403 402 else: branches/multiapp/cherrypy/_cphttptools.py
r904 r908 9 9 from cherrypy import _cputil, _cpcgifs 10 10 from cherrypy.filters import applyFilters 11 from cherrypy.lib import cptools, httptools 11 from cherrypy.lib import cptools, httptools, profiler 12 12 13 13 … … 65 65 self.simpleCookie = Cookie.SimpleCookie() 66 66 67 if cherrypy.profiler: 68 cherrypy.profiler.run(self._run) 67 # Set up the profiler if requested. 68 if cherrypy.config.serverconf.get("profiling.on", False): 69 ppath = cherrypy.config.serverconf.get("profiling.path", "") 70 profiler.Profiler(ppath).run(self._run) 69 71 else: 70 72 self._run() … … 122 124 raise 123 125 except: 124 if cherrypy.config. get("server.throw_errors", False):126 if cherrypy.config.serverconf.get("server.throw_errors", False): 125 127 raise 126 128 cherrypy.response.handleError(sys.exc_info()) … … 129 131 rl = self.requestLine 130 132 method, path, qs, proto = httptools.parseRequestLine(rl) 131 if path == "*":132 path = "global"133 133 134 134 self.method = method … … 141 141 # Change object_path in filters to change 142 142 # the object that will get rendered 143 self.object_path = path 143 cherrypy.dispatch(path) 144 self.object_path = cherrypy.app.dispatch_path(path) 144 145 145 146 # Compare request and server HTTP versions, in case our server does … … 159 160 # cherrypy.request.version == request.protocol in a Version instance. 160 161 self.version = httptools.Version.from_http(self.protocol) 161 server_v = cherrypy.config. get("server.protocol_version", "HTTP/1.0")162 server_v = cherrypy.config.serverconf.get("server.protocol_version", "HTTP/1.0") 162 163 server_v = httptools.Version.from_http(server_v) 163 164 … … 372 373 self.headers = httptools.HeaderMap() 373 374 self.headerMap = self.headers # Backward compatibility 374 content_type = cherrypy.config.get('server.default_content_type', 'text/html') 375 content_type = cherrypy.config.serverconf.get('server.default_content_type', 376 'text/html') 375 377 self.headers.update({ 376 378 "Content-Type": content_type, branches/multiapp/cherrypy/_cpserver.py
r905 r908 9 9 import cherrypy 10 10 from cherrypy import _cphttptools, filters 11 from cherrypy.lib import autoreload, profiler,cptools11 from cherrypy.lib import autoreload, cptools 12 12 13 13 # Use a flag to indicate the state of the application server. … … 52 52 self.interrupt = None 53 53 54 conf = cherrypy.config. get54 conf = cherrypy.config.serverconf.get 55 55 56 56 if serverClass is _missing: … … 93 93 94 94 def _start(self): 95 conf = cherrypy.config.serverconf.get 95 96 # Output config options to log 96 if c herrypy.config.get("server.log_config_options", True):97 if conf("server.log_config_options", True): 97 98 cherrypy.config.outputConfigMap() 98 99 99 100 try: 100 configure() 101 if cherrypy.codecoverage: 102 from cherrypy.lib import covercp 103 covercp.start() 104 105 # set cgi.maxlen which will limit the size of POST request bodies 106 cgi.maxlen = conf('server.max_request_size') 107 108 # Initialize the built in filters 109 filters.init() 101 110 102 111 for func in cherrypy.server.on_start_server_list + cherrypy.server.onStartServerList: … … 134 143 return 135 144 136 if cherrypy.config.get('server.socket_port'): 137 host = cherrypy.config.get('server.socket_host') 138 port = cherrypy.config.get('server.socket_port') 145 conf = cherrypy.config.serverconf.get 146 if conf('server.socket_port'): 147 host = conf('server.socket_host') 148 port = conf('server.socket_port') 139 149 140 150 wait_for_free_port(host, port) … … 144 154 on_what = "http://%s:%s/" % (host, port) 145 155 else: 146 on_what = "socket file: %s" % c herrypy.config.get('server.socket_file')156 on_what = "socket file: %s" % conf('server.socket_file') 147 157 148 158 # Instantiate the server. … … 171 181 172 182 # Wait for port to be occupied 173 if cherrypy.config.get('server.socket_port'): 174 host = cherrypy.config.get('server.socket_host') 175 port = cherrypy.config.get('server.socket_port') 183 conf = cherrypy.config.serverconf.get 184 if conf('server.socket_port'): 185 host = conf('server.socket_host') 186 port = conf('server.socket_port') 176 187 wait_for_occupied_port(host, port) 177 188 … … 276 287 def check_config(): 277 288 err = cherrypy.WrongConfigValue 278 for name, section in cherrypy.config.configs.iteritems(): 279 for k, v in section.iteritems(): 280 if k == "server.environment": 281 if v and v not in cherrypy.config.environments: 282 raise err("'%s' is not a registered environment." % v) 283 284 285 def configure(): 286 """Perform one-time actions to prepare the CherryPy core.""" 287 if cherrypy.codecoverage: 288 from cherrypy.lib import covercp 289 covercp.start() 290 291 conf = cherrypy.config.get 292 # TODO: config.checkConfigOptions() 293 294 # If sessions are stored in files and we 295 # use threading, we need a lock on the file 296 if (conf('server.thread_pool') > 1 297 and conf('session.storage_type') == 'file'): 298 cherrypy._sessionFileLock = threading.RLock() 299 300 # set cgi.maxlen which will limit the size of POST request bodies 301 cgi.maxlen = conf('server.max_request_size') 302 303 # Set up the profiler if requested. 304 if conf("profiling.on", False): 305 ppath = conf("profiling.path", "") 306 cherrypy.profiler = profiler.Profiler(ppath) 307 else: 308 cherrypy.profiler = None 309 310 # Initialize the built in filters 311 filters.init() 289 for app in cherrypy.apps: 290 for name, section in app.config.iteritems(): 291 for k, v in section.iteritems(): 292 if k == "server.environment": 293 if v and v not in cherrypy.config.environments: 294 raise err("'%s' is not a registered environment." % v) 312 295 313 296 314 297 def check_port(host, port): 315 298 """Raise an error if the given port is not free on the given host.""" 316 sock_file = cherrypy.config. get('server.socket_file')299 sock_file = cherrypy.config.serverconf.get('server.socket_file') 317 300 if sock_file: 318 301 return branches/multiapp/cherrypy/_cputil.py
r901 r908 33 33 if nameList == ['global']: 34 34 # Special-case a Request-URI of * to allow for our default handler. 35 root = getattr(cherrypy , 'root', None)35 root = getattr(cherrypy.app, 'root', None) 36 36 if root is None: 37 37 return [('root', None), ('global_', None), ('index', None)] 38 38 gh = getattr(root, 'global_', _cpGlobalHandler) 39 return [('root', cherrypy. root), ('global_', gh), ('index', None)]39 return [('root', cherrypy.app.root), ('global_', gh), ('index', None)] 40 40 41 41 nameList = ['root'] + nameList + ['index'] 42 42 43 43 # Convert the list of names into a list of objects 44 node = cherrypy 44 node = cherrypy.app 45 45 objectTrail = [] 46 46 for name in nameList: … … 117 117 } 118 118 119 if cherrypy.config. get('server.log_to_screen', True):119 if cherrypy.config.serverconf.get('server.log_to_screen', True): 120 120 print s 121 121 122 fname = cherrypy.config. get('server.log_access_file', '')122 fname = cherrypy.config.serverconf.get('server.log_access_file', '') 123 123 if fname: 124 124 f = open(fname, 'ab') … … 140 140 s = ' '.join((logtime(), context, level, msg)) 141 141 142 if cherrypy.config. get('server.log_to_screen', True):142 if cherrypy.config.serverconf.get('server.log_to_screen', True): 143 143 print s 144 144 145 fname = cherrypy.config. get('server.log_file', '')145 fname = cherrypy.config.serverconf.get('server.log_file', '') 146 146 #logdir = os.path.dirname(fname) 147 147 #if logdir and not os.path.exists(logdir): … … 232 232 logmsg = "" 233 233 234 if cherrypy.config. get('server.log_tracebacks', True):234 if cherrypy.config.serverconf.get('server.log_tracebacks', True): 235 235 logmsg = tb 236 if cherrypy.config. get('server.log_request_headers', True):236 if cherrypy.config.serverconf.get('server.log_request_headers', True): 237 237 h = [" %s: %s" % (k, v) for k, v in cherrypy.request.header_list] 238 238 logmsg += 'Request Headers:\n' + '\n'.join(h) … … 352 352 """ Default _cp_on_error method """ 353 353 # Allow logging of only *unexpected* HTTPError's. 354 if (not cherrypy.config. get('server.log_tracebacks', True)355 and cherrypy.config. get('server.log_unhandled_tracebacks', True)):354 if (not cherrypy.config.serverconf.get('server.log_tracebacks', True) 355 and cherrypy.config.serverconf.get('server.log_unhandled_tracebacks', True)): 356 356 cherrypy.log(traceback=True) 357 357 branches/multiapp/cherrypy/_cpwsgi.py
r887 r908 55 55 56 56 # Trap screen output from BaseHTTPRequestHandler.log_message() 57 if not cherrypy.config. get('server.log_to_screen'):57 if not cherrypy.config.serverconf.get('server.log_to_screen'): 58 58 sys.stderr = NullWriter() 59 59 … … 78 78 raise 79 79 except: 80 if cherrypy.config. get("server.throw_errors", False):80 if cherrypy.config.serverconf.get("server.throw_errors", False): 81 81 raise 82 tb = _cputil.formatExc() 83 cherrypy.log(tb) 84 if not cherrypy.config.get("server.show_tracebacks", False): 85 tb = "" 86 s, h, b = _cputil.bareError(tb) 82 cherrypy.log(traceback=True) 83 s, h, b = _cputil.bareError() 87 84 exc = sys.exc_info() 88 85 … … 126 123 def __init__(self, socket, addr, server): 127 124 _cpwsgiserver.HTTPRequest.__init__(self, socket, addr, server) 128 mhs = int(cherrypy.config. get('server.max_request_header_size',129 500 * 1024))125 mhs = int(cherrypy.config.serverconf.get('server.max_request_header_size', 126 500 * 1024)) 130 127 self.rfile = httptools.SizeCheckWrapper(self.rfile, mhs) 131 128 … … 149 146 self.rfile.bytes_read = 0 150 147 path = self.environ["SCRIPT_NAME"] 151 if path == "*": 152 path = "global" 153 else: 154 path = "/" + path 155 mbs = int(cherrypy.config.get('server.max_request_body_size', 156 100 * 1024 * 1024, path=path)) 148 mbs = int(cherrypy.config.serverconf.get('server.max_request_body_size', 149 100 * 1024 * 1024)) 157 150 self.rfile.maxlen = mbs 158 151 … … 171 164 172 165 def __init__(self, app=wsgiApp): 173 conf = cherrypy.config. get166 conf = cherrypy.config.serverconf.get 174 167 175 sockFile = c herrypy.config.get('server.socket_file')168 sockFile = conf('server.socket_file') 176 169 if sockFile: 177 170 bind_addr = sockFile branches/multiapp/cherrypy/config.py
r892 r908 9 9 10 10 11 # This configs dict holds the settings metadata for all cherrypy objects. 12 # Keys are URL paths, and values are dicts. 13 configs = {} 14 configMap = configs # Backward compatibility 15 16 default_global = { 11 default_serverconf = { 17 12 'server.socket_port': 8080, 18 13 'server.socket_host': '', 19 14 'server.socket_file': '', 20 15 'server.socket_queue_size': 5, 16 'server.reverse_dns': False, 17 'autoreload.on': False, 18 'autoreload.frequency': 1, 21 19 'server.protocol_version': 'HTTP/1.0', 20 'server.thread_pool': 0, 22 21 'server.log_to_screen': True, 23 22 'server.log_tracebacks': True, 24 23 'server.log_file': '', 25 'server.reverse_dns': False, 26 'server.thread_pool': 0, 27 'server.environment': "development", 28 29 '/favicon.ico': { 30 'static_filter.on': True, 31 'static_filter.file': os.path.join(os.path.dirname(__file__), "favicon.ico"),} 24 'server.log_config_options': False, 25 'server.log_file_not_found': False, 26 'server.log_request_headers': False, 32 27 } 28 serverconf = default_serverconf.copy() 33 29 34 30 environments = { … … 36 32 'autoreload.on': True, 37 33 'log_debug_info_filter.on': True, 38 'server.log_file_not_found': True,39 34 'server.show_tracebacks': True, 40 'server.log_request_headers': True,41 35 }, 42 36 "staging": { 43 37 'autoreload.on': False, 44 38 'log_debug_info_filter.on': False, 45 'server.log_file_not_found': False,46 39 'server.show_tracebacks': False, 47 'server.log_request_headers': False,48 40 }, 49 41 "production": { 50 42 'autoreload.on': False, 51 43 'log_debug_info_filter.on': False, 52 'server.log_file_not_found': False,53 44 'server.show_tracebacks': False, 54 'server.log_request_headers': False,55 45 }, 56 46 } … … 62 52 already defined in the configs. 63 53 """ 54 55 appconf = cherrypy.app.config 56 64 57 if updateMap is None: 65 58 updateMap = {} … … 71 64 updateMap.update(dict_from_config_file(file)) 72 65 73 # Load new conf into cherrypy .configs66 # Load new conf into cherrypy configs 74 67 for section, valueMap in updateMap.iteritems(): 75 68 # Handle shortcut syntax for "global" section 76 # example: update({' server.socket_port': 80})69 # example: update({'http.show_tracebacks': True}) 77 70 if not isinstance(valueMap, dict): 78 71 valueMap = {section: valueMap} 79 72 section = 'global' 80 73 81 bucket = configs.setdefault(section, {}) 74 if section == "server": 75 bucket = serverconf 76 else: 77 bucket = appconf.setdefault(section, {}) 78 82 79 if overwrite: 83 80 bucket.update(valueMap) … … 86 83 bucket.setdefault(key, value) 87 84 88 def reset(useDefaults=True):89 """Clear configuration and restore defaults"""90 configs.clear()91 if useDefaults:92 update(default_global)93 reset()94 85 95 86 def get(key, default_value=None, return_section=False, path = None): … … 98 89 specified, return the path to the value, instead of the value itself. 99 90 """ 91 92 configs = cherrypy.app.config 100 93 101 94 if path is None: … … 156 149 """ 157 150 # Needed by the session filter 151 152 configs = cherrypy.app.config 158 153 159 154 try: … … 233 228 """Log server configuration parameters""" 234 229 cherrypy.log("Server parameters:", 'CONFIG') 235 236 serverVars = [ 237 'server.environment', 238 'server.log_to_screen', 239 'server.log_file', 240 'server.log_tracebacks', 241 'server.log_request_headers', 242 'server.protocol_version', 243 'server.socket_host', 244 'server.socket_port', 245 'server.socket_file', 246 'server.reverse_dns', 247 'server.socket_queue_size', 248 'server.thread_pool', 249 ] 250 251 for var in serverVars: 252 cherrypy.log(" %s: %s" % (var, get(var)), 'CONFIG') 253 230 for k, v in serverconf.iteritems(): 231 cherrypy.log(" %s: %s" % (k, v), 'CONFIG') 232 branches/multiapp/cherrypy/filters/__init__.py
r903 r908 56 56 inputs, outputs = [], [] 57 57 58 conf = cherrypy.config. get58 conf = cherrypy.config.serverconf.get 59 59 60 60 for filtercls in input_filters + conf('server.input_filters', []): … … 106 106 if method: 107 107 special_methods.append(method) 108 108 109 109 if method_name in _input_methods: 110 110 # Run special filters after defaults. branches/multiapp/cherrypy/filters/cachefilter.py
r906 r908 103 103 104 104 def __init__(self): 105 cache_class = cherrypy.config.get("cache_filter.cacheClass", MemoryCache) 105 cache_class = cherrypy.config.serverconf.get("cache_filter.cacheClass", 106 MemoryCache) 106 107 cherrypy._cache = cache_class() 107 108 branches/multiapp/cherrypy/lib/covercp.py
r856 r908 345 345 346 346 import cherrypy 347 cherrypy.root = CoverStats() 348 cherrypy.config.update({'server.socket_port': port, 349 'server.thread_pool': 10, 350 'server.environment': "production", 351 }) 347 cherrypy.new(root = CoverStats()) 348 cherrypy.config.update({ 349 'server': { 350 'server.socket_port': port, 351 'server.thread_pool': 10, 352 }, 353 'global': { 354 'server.environment': "production", 355 }, 356 }) 352 357 cherrypy.server.start() 353 358 branches/multiapp/cherrypy/lib/cptools.py
r896 r908 52 52 from cherrypy.lib.cptools import ExposeItems 53 53 ... 54 cherrypy. root.foo = ExposeItems(mylist)55 cherrypy. root.bar = ExposeItems(mydict)54 cherrypy.app.root.foo = ExposeItems(mylist) 55 cherrypy.app.root.bar = ExposeItems(mydict) 56 56 """ 57 57 exposed = True … … 76 76 response = cherrypy.response 77 77 78 # If path is relative, make absolute using cherrypy. root's module.79 # If there is no cherrypy. root, or it doesn't have a __module__78 # If path is relative, make absolute using cherrypy.app.root's module. 79 # If there is no cherrypy.app.root, or it doesn't have a __module__ 80 80 # attribute, then users should fix the issue by making path absolute. 81 81 # That is, CherryPy should not guess where the application root is 82 # any further than trying cherrypy. root.__module__, and it certainly82 # any further than trying cherrypy.app.root.__module__, and it certainly 83 83 # should *not* use cwd (since CP may be invoked from a variety of 84 84 # paths). If using static_filter, you can make your relative paths 85 85 # become absolute by supplying a value for "static_filter.root". 86 86 if not os.path.isabs(path): 87 root = os.path.dirname(sys.modules[cherrypy. root.__module__].__file__)87 root = os.path.dirname(sys.modules[cherrypy.app.root.__module__].__file__) 88 88 path = os.path.join(root, path) 89 89 branches/multiapp/cherrypy/lib/httptools.py
r899 r908 299 299 def parseRequestLine(requestLine): 300 300 """Return (method, path, querystring, protocol) from a requestLine.""" 301 method, path, protocol = requestLine.split() 302 303 # path may be an abs_path (including "http://host.domain.tld"); 301 method, url, protocol = requestLine.split() 302 path, qs = parse_request_url(url) 303 return method, path, qs, protocol 304 305 def parse_request_url(url): 306 """Return (relative path, querystring) from a requestline url.""" 307 308 # url may be an abs_path (including "http://host.domain.tld"); 304 309 # Ignore scheme, location, and fragments (so config lookups work). 305 310 # [Therefore, this assumes all hosts are valid for this server.] 306 scheme, location, path, params, qs, frag = urlparse( path)311 scheme, location, path, params, qs, frag = urlparse(url) 307 312 if path == "*": 308 313 # "...the request does not apply to a particular resource, … … 325 330 atoms = [urllib.unquote(x) for x in re.split("(?i)%2F", path)] 326 331 path = "%2F".join(atoms) 327 328 return method, path, qs, protocol 332 return path, qs 333 329 334 330 335 def parseQueryString(queryString, keep_blank_values=True): branches/multiapp/cherrypy/lib/profiler.py
r882 r908 131 131 import cherrypy 132 132 cherrypy.root = Profiler(path) 133 cherrypy.config.update({'server.socket_port': int(port), 134 'server.thread_pool': 10, 135 'server.environment': "production", 136 'session.storageType': "ram", 137 }) 133 cherrypy.config.update({ 134 'server': { 135 'server.socket_port': int(port), 136 'server.thread_pool': 10, 137 }, 138 'global': { 139 'server.environment': "production", 140 'session.storageType': "ram", 141 }, 142 }) 138 143 cherrypy.server.start() 139 144 branches/multiapp/cherrypy/test/__init__.py
r762 r908 7 7 # - test if tabs and whitespaces are handled correctly in source file (option -W) 8 8 # - test if absolute pathnames work fine on windows 9 # - test sessions10 # - test threading server11 9 # - test forking server 12 10 # - test process pooling server branches/multiapp/cherrypy/test/helper.py
r893 r908 30 30 import cherrypy 31 31 from cherrypy import _cpwsgi 32 from cherrypy.lib import httptools 32 33 import webtest 33 34 … … 43 44 if not handled: 44 45 cherrypy._cputil._cp_on_error() 45 46 47 class VirtualRootFilter:48 49 def __init__(self, prefix):50 self.prefix = prefix51 52 def on_start_resource(self):53 path = cherrypy.request.object_path54 if path.startswith(self.prefix):55 cherrypy.request.object_path = path[len(self.prefix):]56 vroot = ""57 ##vr
