Changeset 198
- Timestamp:
- 05/20/05 06:01:32
- Files:
-
- trunk/CHANGELOG.txt (modified) (1 diff)
- trunk/cherrypy/_cpconfig.py (modified) (1 diff)
- trunk/cherrypy/_cpdefaults.py (modified) (6 diffs)
- trunk/cherrypy/_cphttpserver.py (modified) (4 diffs)
- trunk/cherrypy/_cphttptools.py (modified) (12 diffs)
- trunk/cherrypy/_cpmagicattr.py (copied) (copied from branches/ticket-112/cherrypy/_cpmagicattr.py) (9 diffs)
- trunk/cherrypy/_cpserver.py (modified) (1 diff)
- trunk/cherrypy/cpg.py (modified) (2 diffs)
- trunk/cherrypy/test/helper.py (modified) (1 diff)
- trunk/cherrypy/test/testFilter1.py (modified) (1 diff)
- trunk/cherrypy/test/testObjectMapping.py (modified) (1 diff)
- trunk/cherrypy/test/testStaticContent.py (modified) (1 diff)
- trunk/cherrypy/test/testVirtualHostFilter.py (modified) (1 diff)
- trunk/cherrypy/tutorial/01_helloworld.py (modified) (1 diff)
- trunk/cherrypy/tutorial/02_expose_methods.py (modified) (1 diff)
- trunk/cherrypy/tutorial/03_get_and_post.py (modified) (1 diff)
- trunk/cherrypy/tutorial/04_complex_site.py (modified) (1 diff)
- trunk/cherrypy/tutorial/05_derived_objects.py (modified) (1 diff)
- trunk/cherrypy/tutorial/06_aspects.py (modified) (1 diff)
- trunk/cherrypy/tutorial/07_default_method.py (modified) (1 diff)
- trunk/cherrypy/tutorial/08_sessions.py (modified) (1 diff)
- trunk/cherrypy/tutorial/09_generators_and_yield.py (modified) (1 diff)
- trunk/cherrypy/tutorial/bonus-sqlobject.py (modified) (1 diff)
- trunk/cherrypy/wsgiapp.py (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/CHANGELOG.txt
r192 r198 1 * Fixed small bug in httptools.redirect 2 * Allow methods to return recursive generators 1 * BACKWARD INCOMPATIBILITY: New config system, see http://www.cherrypy.org/wiki/ConfigSystem21 (Remi) 2 * Fixed small bug in httptools.redirect (Remi) 3 * Allow methods to return recursive generators (Remi) 3 4 * Methods can now return file objects which are red in 64kb chunks. (Mike) 4 5 5 6 2005-04-25: 6 * CherryP Y-2.0-final released7 * CherryPy-2.0-final released 7 8 * Added tests about static content and httptools.redirect (Remi) 8 9 * Handle %20 (and others) in static content - ticket #104 (Remi) trunk/cherrypy/_cpconfig.py
r149 r198 29 29 import _cputil, ConfigParser, cpg 30 30 31 class CaseSensitiveConfigParser(ConfigParser.ConfigParser): 32 """ Sub-class of ConfigParser that keeps the case of options """ 33 def optionxform(self, optionstr): 34 return optionstr 35 36 # Known options to cast: 37 cast = { 38 'server': { 39 'logToScreen': 'getboolean', 40 'socketPort': 'getint', 41 'reverseDNS': 'getboolean', 42 'socketQueueSize': 'getint', 43 'threadPool': 'getint'}, 44 'session': { 45 'sessionTimeout': 'getint', 46 'cleanUpDelay': 'getint', 47 } 48 } 31 49 32 def setDefaultConfigOption(): 33 """ Return an EmptyClass instance with the default config options """ 50 def loadConfigFile(configFile = None): 51 """ Convert an INI file to a dictionary """ 52 _cpLogMessage = _cputil.getSpecialFunction('_cpLogMessage') 34 53 35 cpg.configOption = _cputil.EmptyClass() 54 # Parse config file 55 configParser = CaseSensitiveConfigParser() 56 if hasattr(configFile, 'read'): 57 _cpLogMessage("Reading infos from configFile stream", 'CONFIG') 58 configParser.readfp(configFile) 59 else: 60 _cpLogMessage("Reading infos from configFile: %s" % configFile, 'CONFIG') 61 configParser.read(configFile) 36 62 37 # Set default values for all options 63 # Load INI file into cpg.configMap 64 for section in configParser.sections(): 65 if section not in cpg.configMap: 66 cpg.configMap[section] = {} 67 for option in configParser.options(section): 68 # Check if we need to cast options 69 funcName = cast.get(section, {}).get(option, 'get') 70 value = getattr(configParser, funcName)(section, option) 71 cpg.configMap[section][option] = value 38 72 39 # Parameters used for logging 40 cpg.configOption.logToScreen = 1 41 cpg.configOption.logFile = '' 42 43 # Parameters used to tell which socket the server should listen on 44 # Note that socketPort and socketFile conflict wich each 45 # other: if one has a non-null value, the other one should be null 46 cpg.configOption.socketHost = '' 47 cpg.configOption.socketPort = 8080 48 cpg.configOption.socketFile = '' # Used if server should listen on 49 # AF_UNIX socket 50 cpg.configOption.reverseDNS = 0 51 cpg.configOption.socketQueueSize = 5 # Size of the socket queue 52 cpg.configOption.protocolVersion = "HTTP/1.0" 53 54 # Parameters used to tell what kind of server we want 55 cpg.configOption.threadPool = 0 # Used if we want to create a pool 56 # of threads at the beginning 57 58 # Variables used to tell if this is an SSL server 59 cpg.configOption.sslKeyFile = "" 60 cpg.configOption.sslCertificateFile = "" 61 cpg.configOption.sslClientCertificateVerification = 0 62 cpg.configOption.sslCACertificateFile = "" 63 cpg.configOption.sslVerifyDepth = 1 64 65 # Variable used to flush cache 66 cpg.configOption.flushCacheDelay=0 67 68 # Variable used for enabling debugging 69 cpg.configOption.debugMode=0 70 71 # Variable used to serve static content 72 cpg.configOption.staticContentList = [] 73 74 # Variable used for session handling 75 cpg.configOption.sessionStorageType = "" 76 cpg.configOption.sessionTimeout = 60 # In minutes 77 cpg.configOption.sessionCleanUpDelay = 60 # In minutes 78 cpg.configOption.sessionCookieName = "CherryPySession" 79 cpg.configOption.sessionStorageFileDir = "" 80 81 def parseConfigFile(configFile = None, parsedConfigFile = None): 82 """ 83 Parse the config file and set values in cpg.configOption 84 """ 85 _cpLogMessage = _cputil.getSpecialFunction('_cpLogMessage') 86 if configFile: 87 cpg.parsedConfigFile = ConfigParser.ConfigParser() 88 if hasattr(configFile, 'read'): 89 _cpLogMessage("Reading infos from configFile stream", 'CONFIG') 90 cpg.parsedConfigFile.readfp(configFile) 91 else: 92 _cpLogMessage("Reading infos from configFile: %s" % configFile, 'CONFIG') 93 cpg.parsedConfigFile.read(configFile) 94 else: 95 cpg.parsedConfigFile = parsedConfigFile 96 97 # Read parameters from configFile 98 for sectionName, optionName, valueType in [ 99 ('server', 'logToScreen', 'int'), 100 ('server', 'logFile', 'str'), 101 ('server', 'socketHost', 'str'), 102 ('server', 'protocolVersion', 'str'), 103 ('server', 'socketPort', 'int'), 104 ('server', 'socketFile', 'str'), 105 ('server', 'reverseDNS', 'int'), 106 ('server', 'threadPool', 'int'), 107 ('server', 'sslKeyFile', 'str'), 108 ('server', 'sslCertificateFile', 'str'), 109 ('server', 'sslClientCertificateVerification', 'int'), 110 ('server', 'sslCACertificateFile', 'str'), 111 ('server', 'sslVerifyDepth', 'int'), 112 ('session', 'storageType', 'str'), 113 ('session', 'timeout', 'float'), 114 ('session', 'cleanUpDelay', 'float'), 115 ('session', 'cookieName', 'str'), 116 ('session', 'storageFileDir', 'str') 117 ]: 118 try: 119 value = cpg.parsedConfigFile.get(sectionName, optionName) 120 if valueType == 'int': value = int(value) 121 elif valueType == 'float': value = float(value) 122 if sectionName == 'session': 123 optionName = 'session' + optionName[0].upper() + optionName[1:] 124 setattr(cpg.configOption, optionName, value) 125 except: 126 pass 127 128 try: 129 staticDirList = cpg.parsedConfigFile.options('staticContent') 130 for staticDir in staticDirList: 131 staticDirTarget = cpg.parsedConfigFile.get('staticContent', staticDir) 132 cpg.configOption.staticContentList.append((staticDir, staticDirTarget)) 133 except: pass 134 135 def outputConfigOptions(): 73 def outputConfigMap(): 136 74 _cpLogMessage = _cputil.getSpecialFunction('_cpLogMessage') 137 75 _cpLogMessage("Server parameters:", 'CONFIG') 138 _cpLogMessage(" logToScreen: %s" % cpg.configOption.logToScreen, 'CONFIG') 139 _cpLogMessage(" logFile: %s" % cpg.configOption.logFile, 'CONFIG') 140 _cpLogMessage(" protocolVersion: %s" % cpg.configOption.protocolVersion, 'CONFIG') 141 _cpLogMessage(" socketHost: %s" % cpg.configOption.socketHost, 'CONFIG') 142 _cpLogMessage(" socketPort: %s" % cpg.configOption.socketPort, 'CONFIG') 143 _cpLogMessage(" socketFile: %s" % cpg.configOption.socketFile, 'CONFIG') 144 _cpLogMessage(" reverseDNS: %s" % cpg.configOption.reverseDNS, 'CONFIG') 145 _cpLogMessage(" socketQueueSize: %s" % cpg.configOption.socketQueueSize, 'CONFIG') 146 _cpLogMessage(" threadPool: %s" % cpg.configOption.threadPool, 'CONFIG') 147 _cpLogMessage(" sslKeyFile: %s" % cpg.configOption.sslKeyFile, 'CONFIG') 148 if cpg.configOption.sslKeyFile: 149 _cpLogMessage(" sslCertificateFile: %s" % cpg.configOption.sslCertificateFile, 'CONFIG') 150 _cpLogMessage(" sslClientCertificateVerification: %s" % cpg.configOption.sslClientCertificateVerification, 'CONFIG') 151 _cpLogMessage(" sslCACertificateFile: %s" % cpg.configOption.sslCACertificateFile, 'CONFIG') 152 _cpLogMessage(" sslVerifyDepth: %s" % cpg.configOption.sslVerifyDepth, 'CONFIG') 153 _cpLogMessage(" flushCacheDelay: %s min" % cpg.configOption.flushCacheDelay, 'CONFIG') 154 _cpLogMessage(" sessionStorageType: %s" % cpg.configOption.sessionStorageType, 'CONFIG') 155 if cpg.configOption.sessionStorageType: 156 _cpLogMessage(" sessionTimeout: %s min" % cpg.configOption.sessionTimeout, 'CONFIG') 157 _cpLogMessage(" cleanUpDelay: %s min" % cpg.configOption.sessionCleanUpDelay, 'CONFIG') 158 _cpLogMessage(" sessionCookieName: %s" % cpg.configOption.sessionCookieName, 'CONFIG') 159 _cpLogMessage(" sessionStorageFileDir: %s" % cpg.configOption.sessionStorageFileDir, 'CONFIG') 160 _cpLogMessage(" staticContent: %s" % cpg.configOption.staticContentList, 'CONFIG') 76 _cpLogMessage(" server.logToScreen: %s" % cpg.getConfig('server', 'logToScreen'), 'CONFIG') 77 _cpLogMessage(" server.logFile: %s" % cpg.getConfig('server', 'logFile'), 'CONFIG') 78 _cpLogMessage(" server.protocolVersion: %s" % cpg.getConfig('server', 'protocolVersion'), 'CONFIG') 79 _cpLogMessage(" server.socketHost: %s" % cpg.getConfig('server', 'socketHost'), 'CONFIG') 80 _cpLogMessage(" server.socketPort: %s" % cpg.getConfig('server', 'socketPort'), 'CONFIG') 81 _cpLogMessage(" server.socketFile: %s" % cpg.getConfig('server', 'socketFile'), 'CONFIG') 82 _cpLogMessage(" server.reverseDNS: %s" % cpg.getConfig('server', 'reverseDNS'), 'CONFIG') 83 _cpLogMessage(" server.socketQueueSize: %s" % cpg.getConfig('server', 'socketQueueSize'), 'CONFIG') 84 _cpLogMessage(" server.threadPool: %s" % cpg.getConfig('server', 'threadPool'), 'CONFIG') 85 _cpLogMessage(" session.storageType: %s" % cpg.getConfig('session', 'storageType'), 'CONFIG') 86 if cpg.getConfig('session', 'storageType'): 87 _cpLogMessage(" session.timeout: %s min" % cpg.getConfig('session', 'timeout'), 'CONFIG') 88 _cpLogMessage(" session.cleanUpDelay: %s min" % cpg.getConfig('session', 'cleanUpDelay'), 'CONFIG') 89 _cpLogMessage(" session.cookieName: %s" % cpg.getConfig('session', 'cookieName'), 'CONFIG') 90 _cpLogMessage(" session.storageFileDir: %s" % cpg.getConfig('session', 'storageFileDir'), 'CONFIG') 91 _cpLogMessage(" staticContent: %s" % cpg.getConfig('staticContent'), 'CONFIG') 161 92 162 93 def dummy(): trunk/cherrypy/_cpdefaults.py
r157 r198 55 55 if logToScreen: 56 56 print s 57 if cpg. configOption.logFile:58 f = open(cpg. configOption.logFile, 'ab')57 if cpg.getConfig('server', 'logFile'): 58 f = open(cpg.getConfig('server','logFile'), 'ab') 59 59 f.write(s + '\n') 60 60 f.close() … … 75 75 76 76 if threadPool is None: 77 threadPool = cpg. configOption.threadPool77 threadPool = cpg.getConfig('server', 'threadPool') 78 78 if sessionStorageType is None: 79 sessionStorageType = cpg.configOption.sessionStorageType79 sessionStorageType = cpg.getConfig('session', 'storageType') 80 80 if sessionStorageFileDir is None: 81 sessionStorageFileDir = cpg. configOption.sessionStorageFileDir81 sessionStorageFileDir = cpg.getConfig('session', 'storageFileDir') 82 82 83 83 t = time.localtime(expirationTime) … … 96 96 cpg._sessionMap[sessionId] = (sessionData, expirationTime) 97 97 98 """ TODO: implement cookie storage type99 elif sessionStorageType == "cookie":100 101 TODO: set siteKey in _cpConfig102 # Get site key from config file or compute it103 try: cpg._SITE_KEY_ = configFile.get('server','siteKey')104 except:105 _SITE_KEY_ = ''106 for i in range(30):107 _SITE_KEY_ += random.choice(string.letters)108 109 # Update expiration time110 sessionData = (sessionData, expirationTime)111 dumpStr = pickle.dumps(_sessionData)112 try: dumpStr = zlib.compress(dumpStr)113 except: pass # zlib is not available in all python distros114 dumpStr = binascii.hexlify(dumpStr) # Need to hexlify it because it will be stored in a cookie115 cpg.response.simpleCookie['CSession'] = dumpStr116 cpg.response.simpleCookie['CSession-sig'] = md5.md5(dumpStr + cpg.configOption.siteKey).hexdigest()117 cpg.response.simpleCookie['CSession']['path'] = '/'118 cpg.response.simpleCookie['CSession']['max-age'] = sessionTimeout * 60119 cpg.response.simpleCookie['CSession-sig']['path'] = '/'120 cpg.response.simpleCookie['CSession-sig']['max-age'] = sessionTimeout * 60121 """122 123 98 def _cpLoadSessionData(sessionId, threadPool = None, sessionStorageType = None, 124 99 sessionStorageFileDir = None): … … 128 103 129 104 if threadPool is None: 130 threadPool = cpg. configOption.threadPool105 threadPool = cpg.getConfig('server', 'threadPool') 131 106 if sessionStorageType is None: 132 sessionStorageType = cpg.configOption.sessionStorageType107 sessionStorageType = cpg.getConfig('session', 'storageType') 133 108 if sessionStorageFileDir is None: 134 sessionStorageFileDir = cpg. configOption.sessionStorageFileDir109 sessionStorageFileDir = cpg.getConfig('session', 'storageFileDir') 135 110 136 111 if sessionStorageType == "ram": … … 152 127 else: return None 153 128 154 """ TODO: implement cookie storage type155 elif _sessionStorageType == "cookie":156 if request.simpleCookie.has_key('CSession') and request.simpleCookie.has_key('CSession-sig'):157 data = request.simpleCookie['CSession'].value158 sig = request.simpleCookie['CSession-sig'].value159 if md5.md5(data + cpg.configOption.siteKey).hexdigest() == sig:160 try:161 dumpStr = binascii.unhexlify(data)162 try: dumpStr = zlib.decompress(dumpStr)163 except: pass # zlib is not available in all python distros164 dumpStr = pickle.loads(dumpStr)165 return dumpStr166 except: pass167 return None168 """169 170 129 def _cpCleanUpOldSessions(threadPool = None, sessionStorageType = None, 171 130 sessionStorageFileDir = None): … … 173 132 174 133 if threadPool is None: 175 threadPool = cpg. configOption.threadPool134 threadPool = cpg.getConfig('server', 'threadPool') 176 135 if sessionStorageType is None: 177 sessionStorageType = cpg.configOption.sessionStorageType136 sessionStorageType = cpg.getConfig('session', 'storageType') 178 137 if sessionStorageFileDir is None: 179 sessionStorageFileDir = cpg. configOption.sessionStorageFileDir138 sessionStorageFileDir = cpg.getConfig('session', 'storageFileDir') 180 139 181 140 # Clean up old session data trunk/cherrypy/_cphttpserver.py
r132 r198 38 38 # If sessions are stored in files and we 39 39 # use threading, we need a lock on the file 40 if (cpg. configOption.threadPool> 1) and \41 cpg. configOption.sessionStorageType== 'file':40 if (cpg.getConfig('server', 'threadPool') > 1) and \ 41 cpg.getConfig('session', 'storageType') == 'file': 42 42 cpg._sessionFileLock = threading.RLock() 43 43 44 44 45 if cpg. configOption.socketFile:45 if cpg.getConfig('server', 'socketFile'): 46 46 # AF_UNIX socket 47 47 # TODO: Handle threading here … … 49 49 else: 50 50 # AF_INET socket 51 if cpg. configOption.threadPool> 1:51 if cpg.getConfig('server', 'threadPool') > 1: 52 52 MyCherryHTTPServer = PooledThreadServer 53 53 else: 54 54 MyCherryHTTPServer = CherryHTTPServer 55 55 56 MyCherryHTTPServer.request_queue_size = cpg. configOption.socketQueueSize56 MyCherryHTTPServer.request_queue_size = cpg.getConfig('server', 'socketQueueSize') 57 57 58 58 # Set protocol_version 59 CherryHTTPRequestHandler.protocol_version = cpg. configOption.protocolVersion59 CherryHTTPRequestHandler.protocol_version = cpg.getConfig('server', 'protocolVersion') 60 60 61 61 run_server(CherryHTTPRequestHandler, MyCherryHTTPServer, \ 62 (cpg. configOption.socketHost, cpg.configOption.socketPort), \63 cpg. configOption.socketFile)62 (cpg.getConfig('server', 'socketHost'), cpg.getConfig('server', 'socketPort')), \ 63 cpg.getConfig('server', 'socketFile')) 64 64 65 65 def run_server(HandlerClass, ServerClass, server_address, socketFile): 66 66 """Run the HTTP request handler class.""" 67 67 68 if cpg. configOption.socketFile:69 try: os.unlink(cpg. configOption.socketFile) # So we can reuse the socket68 if cpg.getConfig('server', 'socketFile'): 69 try: os.unlink(cpg.getConfig('server', 'socketFile')) # So we can reuse the socket 70 70 except: pass 71 server_address = cpg. configOption.socketFile72 if cpg. configOption.threadPool> 1:73 myCherryHTTPServer = ServerClass(server_address, cpg. configOption.threadPool, HandlerClass)71 server_address = cpg.getConfig('server', 'socketFile') 72 if cpg.getConfig('server', 'threadPool') > 1: 73 myCherryHTTPServer = ServerClass(server_address, cpg.getConfig('server', 'threadPool'), HandlerClass) 74 74 else: 75 75 myCherryHTTPServer = ServerClass(server_address, HandlerClass) 76 76 cpg._server = myCherryHTTPServer 77 if cpg. configOption.socketFile:77 if cpg.getConfig('server', 'socketFile'): 78 78 try: os.chmod(socketFile, 0777) # So everyone can access the socket 79 79 except: pass … … 82 82 83 83 servingWhat = "HTTP" 84 if cpg.configOption.socketPort: onWhat = "socket: ('%s', %s)" % (cpg.configOption.socketHost, cpg.configOption.socketPort) 85 else: onWhat = "socket file: %s" % cpg.configOption.socketFile 84 if cpg.getConfig('server', 'socketPort'): 85 onWhat = ("socket: ('%s', %s)" % 86 (cpg.getConfig('server', 'socketHost'), cpg.getConfig('server', 'socketPort'))) 87 else: onWhat = "socket file: %s" % cpg.getConfig('server', 'socketFile') 86 88 _cpLogMessage("Serving %s on %s" % (servingWhat, onWhat), 'HTTP') 87 89 … … 111 113 def address_string(self): 112 114 """ Try to do a reverse DNS based on [server]reverseDNS in the config file """ 113 if cpg. configOption.reverseDNS:115 if cpg.getConfig('server', 'reverseDNS'): 114 116 return BaseHTTPServer.BaseHTTPRequestHandler.address_string(self) 115 117 else: trunk/cherrypy/_cphttptools.py
r197 r198 186 186 # creates some attributes on cpg.response so filters can use them 187 187 cpg.response.wfile = wfile 188 cpg.response.sendResponse = 1 188 cpg.response.sendResponse = True 189 189 190 # Prepare response variables 190 191 now = time.time() … … 192 193 date = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (weekdayname[wd], day, monthname[month], year, hh, mm, ss) 193 194 cpg.response.headerMap = { 194 "protocolVersion": cpg. configOption.protocolVersion,195 "protocolVersion": cpg.getConfig('server', 'protocolVersion'), 195 196 "Status": "200 OK", 196 197 "Content-Type": "text/html", … … 201 202 } 202 203 cpg.response.simpleCookie = Cookie.SimpleCookie() 204 203 205 try: 204 206 try: … … 226 228 227 229 # Still save session data 228 if cpg. configOption.sessionStorageTypeand not cpg.request.isStatic:229 sessionId = cpg.response.simpleCookie[cpg. configOption.sessionCookieName].value230 expirationTime = time.time() + cpg. configOption.sessionTimeout* 60230 if cpg.getConfig('session', 'storageType') and not cpg.request.isStatic: 231 sessionId = cpg.response.simpleCookie[cpg.getConfig('session', 'cookieName')].value 232 expirationTime = time.time() + cpg.getConfig('session', 'timeout') * 60 231 233 _cputil.getSpecialFunction('_cpSaveSessionData')(sessionId, cpg.request.sessionMap, expirationTime) 232 234 … … 235 237 if (cpg.response.headerMap.has_key('Content-Length') and 236 238 cpg.response.headerMap['Content-Length']==0): 237 buf = StringIO.StringIO()238 [buf.write(x) for x in cpg.response.body]239 buf.seek(0)240 cpg.response.body = [buf.read()]241 cpg.response.headerMap['Content-Length'] = len(cpg.response.body[0])239 buf = StringIO.StringIO() 240 [buf.write(x) for x in cpg.response.body] 241 buf.seek(0) 242 cpg.response.body = [buf.read()] 243 cpg.response.headerMap['Content-Length'] = len(cpg.response.body[0]) 242 244 243 245 for key, valueList in cpg.response.headerMap.items(): … … 253 255 traceback.print_exc(file = bodyFile) 254 256 body = bodyFile.getvalue() 255 wfile.write('%s 200 OK\r\n' % cpg. configOption.protocolVersion)257 wfile.write('%s 200 OK\r\n' % cpg.getConfig('server', 'protocolVersion')) 256 258 wfile.write('Content-Type: text/plain\r\n') 257 259 wfile.write('Content-Length: %s\r\n' % len(body)) … … 272 274 273 275 # Save session data 274 if cpg. configOption.sessionStorageTypeand not cpg.request.isStatic:275 sessionId = cpg.response.simpleCookie[cpg. configOption.sessionCookieName].value276 expirationTime = time.time() + cpg. configOption.sessionTimeout* 60276 if cpg.getConfig('session', 'storageType') and not cpg.request.isStatic: 277 sessionId = cpg.response.simpleCookie[cpg.getConfig('session', 'cookieName')].value 278 expirationTime = time.time() + cpg.getConfig('session', 'timeout') * 60 277 279 _cputil.getSpecialFunction('_cpSaveSessionData')(sessionId, cpg.request.sessionMap, expirationTime) 278 280 … … 299 301 # Clean up expired sessions if needed: 300 302 now = time.time() 301 if cpg.configOption.sessionStorageType and cpg.configOption.sessionCleanUpDelay and cpg._lastSessionCleanUpTime + cpg.configOption.sessionCleanUpDelay * 60 <= now: 303 if (cpg.getConfig('session', 'storageType') and 304 cpg.getConfig('session', 'cleanUpDelay') and 305 (cpg._lastSessionCleanUpTime + cpg.getConfig('session', 'cleanUpDelay') * 60) <= now): 302 306 cpg._lastSessionCleanUpTime = now 303 307 _cputil.getSpecialFunction('_cpCleanUpOldSessions')() … … 318 322 319 323 # Handle static directories 320 for urlDir, fsDir in cpg. configOption.staticContentList:324 for urlDir, fsDir in cpg.getConfig('staticContent').items(): 321 325 if path == urlDir or path[:len(urlDir)+1]==urlDir+'/': 322 326 … … 340 344 cpg.response.headerMap = { 341 345 'Status': 304, 342 'protocolVersion': cpg. configOption.protocolVersion,346 'protocolVersion': cpg.getConfig('server', 'protocolVersion'), 343 347 'Date': cpg.response.headerMap['Date']} 344 348 cpg.response.body = [] … … 361 365 362 366 # Get session data 363 if cpg. configOption.sessionStorageTypeand not cpg.request.isStatic:367 if cpg.getConfig('session', 'storageType') and not cpg.request.isStatic: 364 368 now = time.time() 365 369 # First, get sessionId from cookie 366 try: sessionId = cpg.request.simpleCookie[cpg. configOption.sessionCookieName].value370 try: sessionId = cpg.request.simpleCookie[cpg.getConfig('session', 'cookieName')].value 367 371 except: sessionId=None 368 372 if sessionId: … … 384 388 cpg.request.sessionMap['_sessionId'] = sessionId 385 389 386 cpg.response.simpleCookie[cpg. configOption.sessionCookieName] = sessionId387 cpg.response.simpleCookie[cpg. configOption.sessionCookieName]['path'] = '/'388 cpg.response.simpleCookie[cpg. configOption.sessionCookieName]['version'] = 1390 cpg.response.simpleCookie[cpg.getConfig('session', 'cookieName')] = sessionId 391 cpg.response.simpleCookie[cpg.getConfig('session', 'cookieName')]['path'] = '/' 392 cpg.response.simpleCookie[cpg.getConfig('session', 'cookieName')]['version'] = 1 389 393 390 394 try: trunk/cherrypy/_cpmagicattr.py
r197 r198 13 13 14 14 configMap = cpg.configMap 15 default Map = cpg.defaultMap15 defaultConfigMap = cpg.defaultConfigMap 16 16 cpgTree = cpg 17 reservedAttrNames = ['configMap','default Map']17 reservedAttrNames = ['configMap','defaultConfigMap'] 18 18 19 19 #------------------------------------------------------------------------- … … 28 28 setDefaultAttr('root', 'encodingFilter.encoding', 'utf8') 29 29 """ 30 sectMap = default Map.setdefault(section, {})30 sectMap = defaultConfigMap.setdefault(section, {}) 31 31 sectMap[attr] = value 32 32 … … 39 39 {'encodingFilter':'on', 'encodingFilter.encoding':'utf8') 40 40 """ 41 sectMap = default Map.setdefault(section, {})41 sectMap = defaultConfigMap.setdefault(section, {}) 42 42 sectMap.update(map) 43 43 … … 119 119 def search_bottom_up(self, attrname): 120 120 """ 121 Search on configMap, default Map, and cpgTree simultaneously121 Search on configMap, defaultConfigMap, and cpgTree simultaneously 122 122 Potentially recursive bottom-up implementation. It is fast 123 123 because it can take advantage of the cache, but it it can't … … 134 134 return value 135 135 except (KeyError, AttributeError): 136 sectionMap = default Map[self.cpgpath]136 sectionMap = defaultConfigMap[self.cpgpath] 137 137 return sectionMap[attrname] 138 138 except KeyError: … … 141 141 def search_top_down(self, attrname, lookupCpgTree=False): 142 142 """ 143 Search on configMap, default Map, and cpgTree simultaneously143 Search on configMap, defaultConfigMap, and cpgTree simultaneously 144 144 Iterative top-down version. Probably slower than the bottom 145 145 up version for big & deep web sites, because it never caches … … 156 156 partialPath = partialPath + item 157 157 try: 158 sectionMap = default Map[partialPath]158 sectionMap = defaultConfigMap[partialPath] 159 159 curvalue = sectionMap[attrname] 160 160 lastDefaultType = type(curvalue) … … 236 236 def test(): 237 237 """simple testing""" 238 testDefault Map = {238 testDefaultConfigMap = { 239 239 'server': { 240 240 'logFile': '', … … 258 258 testConfigFile = StringIO.StringIO(testConfigText) 259 259 configMap = _cpconfig.loadConfigFile(testConfigFile) 260 default Map = testDefaultMap260 defaultConfigMap = testDefaultConfigMap 261 261 cpgTree = testCpgTree 262 reservedAttrNames = ['configMap','default Map']262 reservedAttrNames = ['configMap','defaultConfigMap'] 263 263 # register more default values (simulates filters) 264 264 setDefaultMap( trunk/cherrypy/_cpserver.py
r148 r198 33 33 """ 34 34 35 import cpg, thread, _cputil, _cp config, _cphttpserver, time, _cpthreadinglocal35 import cpg, thread, _cputil, _cphttpserver, time, _cpthreadinglocal 36 36 37 def start( configFile = None, parsedConfigFile = None, configMap = {}, initOnly = 0):37 def start(initOnly = False): 38 38 """ 39 39 Main function. All it does is this: 40 - read/parse config file if any40 - output config options 41 41 - create response and request objects 42 42 - creates HTTP server based on configFile and configMap 43 43 - start HTTP server 44 45 Input: There are 2 ways to pass config options:46 - Let CherryPy parse a config file (configFile)47 - Pass the options as a dictionary (configMap)48 44 """ 49 45 50 # cpg.configOption contains an EmptyClass instance with all the configuration option51 _cpconfig.setDefaultConfigOption()52 53 # cpg.parsedConfigFile contains the ConfigParser instance with the parse config file54 cpg.parsedConfigFile = None55 56 if configFile:57 _cpconfig.parseConfigFile(configFile = configFile)58 elif parsedConfigFile:59 _cpconfig.parseConfigFile(parsedConfigFile = parsedConfigFile)60 61 if configMap:62 for key, value in configMap.items():63 setattr(cpg.configOption, key, value)64 65 46 # Output config options 66 _cpconfig.outputConfigOptions()47 cpg.config.outputConfigMap() 67 48 68 49 # Check the config options trunk/cherrypy/cpg.py
r108 r198 35 35 # import server module 36 36 import _cpserver as server 37 import _cpconfig as config 37 38 38 39 # decorator function for exposing methods … … 40 41 func.exposed = True 41 42 return func 43 44 # Default config options 45 defaultConfigMap = { 46 'server': { 47 'protocolVersion': 'HTTP/1.0', 48 'logToScreen': True, 49 'logFile': '', 50 'socketHost': '', 51 'socketPort': 8080, 52 'socketFile': '', 53 'reverseDNS': False, 54 'socketQueueSize': 5, 55 'protocolVersion': 'HTTP/1.0', 56 'threadPool': 0, 57 'environment': 'dev'}, 58 'session': { 59 'storageType': 'ram', 60 'timeout': 60, 61 'cleanUpDelay': 60, 62 'cookieName': 'CherryPySession', 63 'storageFileDir': '', 64 }, 65 'staticContent': {} 66 } 67 68 configMap = {} 69 70 import _cpmagicattr trunk/cherrypy/test/helper.py
r158 r198 132 132 sys.path.insert(0,os.path.normpath(os.path.join(os.getcwd(),'../../'))) 133 133 """ 134 f.write(includePathsToSysPath+code.replace('cpg. server.start', beforeStart + 'cpg.server.start'))134 f.write(includePathsToSysPath+code.replace('cpg.config.loadConfigFile', beforeStart + 'cpg.config.loadConfigFile')) 135 135 f.close() 136 136 trunk/cherrypy/test/testFilter1.py
r108 r198 44 44 index.exposed = True 45 45 cpg.root = Root() 46 cpg.server.start(configFile = 'testsite.cfg') 46 cpg.config.loadConfigFile('testsite.cfg') 47 cpg.server.start() 47 48 """ 48 49 config = "" trunk/cherrypy/test/testObjectMapping.py
r156 r198 78 78 cpg.root.dir1.dir2.dir3 = Dir3() 79 79 cpg.root.dir1.dir2.dir3.dir4 = Dir4() 80 cpg.server.start(configFile = 'testsite.cfg') 80 cpg.config.loadConfigFile('testsite.cfg') 81 cpg.server.start() 81 82 """ 82 83 trunk/cherrypy/test/testStaticContent.py
r158 r198 33 33 class Root: pass 34 34 cpg.root = Root() 35 cpg.server.start(configFile = 'testsite.cfg') 35 cpg.config.loadConfigFile('testsite.cfg') 36 cpg.server.start() 36 37 """ 37 38 trunk/cherrypy/test/testVirtualHostFilter.py
r108 r198 61 61 cpg.root.site1 = Site1() 62 62 cpg.root.site2 = Site2() 63 cpg.server.start(configFile = 'testsite.cfg') 63 cpg.config.loadConfigFile('testsite.cfg') 64 cpg.server.start() 64 65 """ 65 66 trunk/cherrypy/tutorial/01_helloworld.py
r102 r198 28 28 29 29 # Start the CherryPy server using the configuration file tutorial.conf. 30 cpg.server.start(configFile = 'tutorial.conf') 30 cpg.config.loadConfigFile('tutorial.conf') 31 cpg.server.start() 31 32 trunk/cherrypy/tutorial/02_expose_methods.py
r102 r198 24 24 25 25 cpg.root = HelloWorld() 26 cpg.server.start(configFile = 'tutorial.conf') 26 cpg.config.loadConfigFile('tutorial.conf') 27 cpg.server.start() trunk/cherrypy/tutorial/03_get_and_post.py
r102 r198 42 42 43 43 cpg.root = WelcomePage() 44 cpg.server.start(configFile = 'tutorial.conf') 44 cpg.config.loadConfigFile('tutorial.conf') 45 cpg.server.start() trunk/cherrypy/tutorial/04_complex_site.py
r102 r198 90 90 # creating all contained request handler objects. 91 91 92 cpg.server.start(configFile = 'tutorial.conf') 92 cpg.config.loadConfigFile('tutorial.conf') 93 cpg.server.start() trunk/cherrypy/tutorial/05_derived_objects.py
r102 r198 73 73 cpg.root = HomePage() 74 74 75 cpg.server.start(configFile = 'tutorial.conf') 75 cpg.config.loadConfigFile('tutorial.conf') 76 cpg.server.start() trunk/cherrypy/tutorial/06_aspects.py
r130 r198 95 95 cpg.root = HomePage() 96 96 97 cpg.server.start(configFile = 'tutorial.conf') 97 cpg.config.loadConfigFile('tutorial.conf') 98 cpg.server.start() trunk/cherrypy/tutorial/07_default_method.py
r102 r198 54 54 cpg.root = UsersPage() 55 55 56 cpg.server.start(configFile = 'tutorial.conf') 56 cpg.config.loadConfigFile('tutorial.conf') 57 cpg.server.start() trunk/cherrypy/tutorial/08_sessions.py
r102 r198 31 31 cpg.root = HitCounter() 32 32 33 cpg.server.start(configFile = 'tutorial.conf') 33 cpg.config.loadConfigFile('tutorial.conf') 34 cpg.server.start() trunk/cherrypy/tutorial/09_generators_and_yield.py
r115 r198 33 33 34 34 cpg.root = GeneratorDemo() 35 cpg.server.start(configFile = 'tutorial.conf') 35 cpg.config.loadConfigFile('tutorial.conf') 36 cpg.server.start() trunk/cherrypy/tutorial/bonus-sqlobject.py
r101 r198 167 167 168 168 cpg.root = ContactManager() 169 cpg.server.start( configFile = 'tutorial.conf')169 cpg.server.start()

