Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 198

Show
Ignore:
Timestamp:
05/20/05 06:01:32
Author:
rdelon
Message:

Big change: new config system (see http://www.cherrypy.org/wiki/ConfigSystem21)

Files:

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) 
    34    * Methods can now return file objects which are red in 64kb chunks. (Mike) 
    45 
    562005-04-25: 
    6     * CherryPY-2.0-final released 
     7    * CherryPy-2.0-final released 
    78    * Added tests about static content and httptools.redirect (Remi) 
    89    * Handle %20 (and others) in static content - ticket #104 (Remi) 
  • trunk/cherrypy/_cpconfig.py

    r149 r198  
    2929import _cputil, ConfigParser, cpg 
    3030 
     31class 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: 
     37cast = { 
     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} 
    3149         
    32 def setDefaultConfigOption(): 
    33     """ Return an EmptyClass instance with the default config options """ 
     50def loadConfigFile(configFile = None): 
     51    """ Convert an INI file to a dictionary """ 
     52    _cpLogMessage = _cputil.getSpecialFunction('_cpLogMessage') 
    3453 
    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) 
    3662 
    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 
    3872 
    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(): 
     73def outputConfigMap(): 
    13674    _cpLogMessage = _cputil.getSpecialFunction('_cpLogMessage') 
    13775    _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') 
    16192 
    16293def dummy(): 
  • trunk/cherrypy/_cpdefaults.py

    r157 r198  
    5555    if logToScreen: 
    5656        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') 
    5959        f.write(s + '\n') 
    6060        f.close() 
     
    7575 
    7676    if threadPool is None: 
    77         threadPool = cpg.configOption.threadPool 
     77        threadPool = cpg.getConfig('server', 'threadPool') 
    7878    if sessionStorageType is None: 
    79         sessionStorageType = cpg.configOption.sessionStorageType 
     79        sessionStorageType = cpg.getConfig('session', 'storageType') 
    8080    if sessionStorageFileDir is None: 
    81         sessionStorageFileDir = cpg.configOption.sessionStorageFileDir 
     81        sessionStorageFileDir = cpg.getConfig('session', 'storageFileDir') 
    8282 
    8383    t = time.localtime(expirationTime) 
     
    9696        cpg._sessionMap[sessionId] = (sessionData, expirationTime) 
    9797 
    98     """ TODO: implement cookie storage type 
    99     elif sessionStorageType == "cookie": 
    100          
    101          TODO: set siteKey in _cpConfig 
    102             # Get site key from config file or compute it 
    103             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 time 
    110         sessionData = (sessionData, expirationTime) 
    111         dumpStr = pickle.dumps(_sessionData) 
    112         try: dumpStr = zlib.compress(dumpStr) 
    113         except: pass # zlib is not available in all python distros 
    114         dumpStr = binascii.hexlify(dumpStr) # Need to hexlify it because it will be stored in a cookie 
    115         cpg.response.simpleCookie['CSession'] = dumpStr 
    116         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 * 60 
    119         cpg.response.simpleCookie['CSession-sig']['path'] = '/' 
    120         cpg.response.simpleCookie['CSession-sig']['max-age'] = sessionTimeout * 60 
    121     """ 
    122  
    12398def _cpLoadSessionData(sessionId, threadPool = None, sessionStorageType = None, 
    12499        sessionStorageFileDir = None): 
     
    128103 
    129104    if threadPool is None: 
    130         threadPool = cpg.configOption.threadPool 
     105        threadPool = cpg.getConfig('server', 'threadPool') 
    131106    if sessionStorageType is None: 
    132         sessionStorageType = cpg.configOption.sessionStorageType 
     107        sessionStorageType = cpg.getConfig('session', 'storageType') 
    133108    if sessionStorageFileDir is None: 
    134         sessionStorageFileDir = cpg.configOption.sessionStorageFileDir 
     109        sessionStorageFileDir = cpg.getConfig('session', 'storageFileDir') 
    135110 
    136111    if sessionStorageType == "ram": 
     
    152127        else: return None 
    153128 
    154     """ TODO: implement cookie storage type 
    155     elif _sessionStorageType == "cookie": 
    156         if request.simpleCookie.has_key('CSession') and request.simpleCookie.has_key('CSession-sig'): 
    157             data = request.simpleCookie['CSession'].value 
    158             sig  = request.simpleCookie['CSession-sig'].value 
    159             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 distros 
    164                     dumpStr = pickle.loads(dumpStr) 
    165                     return dumpStr 
    166                 except: pass 
    167         return None 
    168     """ 
    169  
    170129def _cpCleanUpOldSessions(threadPool = None, sessionStorageType = None, 
    171130        sessionStorageFileDir = None): 
     
    173132 
    174133    if threadPool is None: 
    175         threadPool = cpg.configOption.threadPool 
     134        threadPool = cpg.getConfig('server', 'threadPool') 
    176135    if sessionStorageType is None: 
    177         sessionStorageType = cpg.configOption.sessionStorageType 
     136        sessionStorageType = cpg.getConfig('session', 'storageType') 
    178137    if sessionStorageFileDir is None: 
    179         sessionStorageFileDir = cpg.configOption.sessionStorageFileDir 
     138        sessionStorageFileDir = cpg.getConfig('session', 'storageFileDir') 
    180139 
    181140    # Clean up old session data 
  • trunk/cherrypy/_cphttpserver.py

    r132 r198  
    3838    # If sessions are stored in files and we 
    3939    # 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': 
    4242        cpg._sessionFileLock = threading.RLock() 
    4343 
    4444 
    45     if cpg.configOption.socketFile
     45    if cpg.getConfig('server', 'socketFile')
    4646        # AF_UNIX socket 
    4747        # TODO: Handle threading here 
     
    4949    else: 
    5050        # AF_INET socket 
    51         if cpg.configOption.threadPool > 1: 
     51        if cpg.getConfig('server', 'threadPool') > 1: 
    5252            MyCherryHTTPServer = PooledThreadServer 
    5353        else: 
    5454            MyCherryHTTPServer = CherryHTTPServer 
    5555 
    56     MyCherryHTTPServer.request_queue_size = cpg.configOption.socketQueueSize 
     56    MyCherryHTTPServer.request_queue_size = cpg.getConfig('server', 'socketQueueSize') 
    5757 
    5858    # Set protocol_version 
    59     CherryHTTPRequestHandler.protocol_version = cpg.configOption.protocolVersion 
     59    CherryHTTPRequestHandler.protocol_version = cpg.getConfig('server', 'protocolVersion') 
    6060 
    6161    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')
    6464 
    6565def run_server(HandlerClass, ServerClass, server_address, socketFile): 
    6666    """Run the HTTP request handler class.""" 
    6767 
    68     if cpg.configOption.socketFile
    69         try: os.unlink(cpg.configOption.socketFile) # So we can reuse the socket 
     68    if cpg.getConfig('server', 'socketFile')
     69        try: os.unlink(cpg.getConfig('server', 'socketFile')) # So we can reuse the socket 
    7070        except: pass 
    71         server_address = cpg.configOption.socketFile 
    72     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) 
    7474    else: 
    7575        myCherryHTTPServer = ServerClass(server_address, HandlerClass) 
    7676    cpg._server = myCherryHTTPServer 
    77     if cpg.configOption.socketFile
     77    if cpg.getConfig('server', 'socketFile')
    7878        try: os.chmod(socketFile, 0777) # So everyone can access the socket 
    7979        except: pass 
     
    8282 
    8383    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') 
    8688    _cpLogMessage("Serving %s on %s" % (servingWhat, onWhat), 'HTTP') 
    8789 
     
    111113    def address_string(self): 
    112114        """ 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')
    114116            return BaseHTTPServer.BaseHTTPRequestHandler.address_string(self) 
    115117        else: 
  • trunk/cherrypy/_cphttptools.py

    r197 r198  
    186186    # creates some attributes on cpg.response so filters can use them 
    187187    cpg.response.wfile = wfile 
    188     cpg.response.sendResponse = 1 
     188    cpg.response.sendResponse = True 
     189 
    189190    # Prepare response variables 
    190191    now = time.time() 
     
    192193    date = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (weekdayname[wd], day, monthname[month], year, hh, mm, ss) 
    193194    cpg.response.headerMap = { 
    194         "protocolVersion": cpg.configOption.protocolVersion
     195        "protocolVersion": cpg.getConfig('server', 'protocolVersion')
    195196        "Status": "200 OK", 
    196197        "Content-Type": "text/html", 
     
    201202    } 
    202203    cpg.response.simpleCookie = Cookie.SimpleCookie() 
     204 
    203205    try: 
    204206        try: 
     
    226228 
    227229            # Still save session data 
    228             if cpg.configOption.sessionStorageType and not cpg.request.isStatic: 
    229                 sessionId = cpg.response.simpleCookie[cpg.configOption.sessionCookieName].value 
    230                 expirationTime = time.time() + cpg.configOption.sessionTimeout * 60 
     230            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 
    231233                _cputil.getSpecialFunction('_cpSaveSessionData')(sessionId, cpg.request.sessionMap, expirationTime) 
    232234 
     
    235237            if (cpg.response.headerMap.has_key('Content-Length') and 
    236238                    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]) 
    242244 
    243245            for key, valueList in cpg.response.headerMap.items(): 
     
    253255            traceback.print_exc(file = bodyFile) 
    254256            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')
    256258            wfile.write('Content-Type: text/plain\r\n') 
    257259            wfile.write('Content-Length: %s\r\n' % len(body)) 
     
    272274 
    273275    # Save session data 
    274     if cpg.configOption.sessionStorageType and not cpg.request.isStatic: 
    275         sessionId = cpg.response.simpleCookie[cpg.configOption.sessionCookieName].value 
    276         expirationTime = time.time() + cpg.configOption.sessionTimeout * 60 
     276    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 
    277279        _cputil.getSpecialFunction('_cpSaveSessionData')(sessionId, cpg.request.sessionMap, expirationTime) 
    278280 
     
    299301    # Clean up expired sessions if needed: 
    300302    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): 
    302306        cpg._lastSessionCleanUpTime = now 
    303307        _cputil.getSpecialFunction('_cpCleanUpOldSessions')() 
     
    318322 
    319323    # Handle static directories 
    320     for urlDir, fsDir in cpg.configOption.staticContentList
     324    for urlDir, fsDir in cpg.getConfig('staticContent').items()
    321325        if path == urlDir or path[:len(urlDir)+1]==urlDir+'/': 
    322326 
     
    340344                    cpg.response.headerMap = { 
    341345                        'Status': 304,  
    342                         'protocolVersion': cpg.configOption.protocolVersion,  
     346                        'protocolVersion': cpg.getConfig('server', 'protocolVersion'), 
    343347                        'Date': cpg.response.headerMap['Date']} 
    344348                    cpg.response.body = [] 
     
    361365 
    362366    # Get session data 
    363     if cpg.configOption.sessionStorageType and not cpg.request.isStatic: 
     367    if cpg.getConfig('session', 'storageType') and not cpg.request.isStatic: 
    364368        now = time.time() 
    365369        # First, get sessionId from cookie 
    366         try: sessionId = cpg.request.simpleCookie[cpg.configOption.sessionCookieName].value 
     370        try: sessionId = cpg.request.simpleCookie[cpg.getConfig('session', 'cookieName')].value 
    367371        except: sessionId=None 
    368372        if sessionId: 
     
    384388            cpg.request.sessionMap['_sessionId'] = sessionId 
    385389 
    386         cpg.response.simpleCookie[cpg.configOption.sessionCookieName] = sessionId 
    387         cpg.response.simpleCookie[cpg.configOption.sessionCookieName]['path'] = '/' 
    388         cpg.response.simpleCookie[cpg.configOption.sessionCookieName]['version'] = 1 
     390        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 
    389393 
    390394    try: 
  • trunk/cherrypy/_cpmagicattr.py

    r197 r198  
    1313 
    1414configMap = cpg.configMap 
    15 defaultMap = cpg.defaultMap 
     15defaultConfigMap = cpg.defaultConfigMap 
    1616cpgTree = cpg 
    17 reservedAttrNames = ['configMap','defaultMap'] 
     17reservedAttrNames = ['configMap','defaultConfigMap'] 
    1818 
    1919#------------------------------------------------------------------------- 
     
    2828        setDefaultAttr('root', 'encodingFilter.encoding', 'utf8') 
    2929    """ 
    30     sectMap = defaultMap.setdefault(section, {}) 
     30    sectMap = defaultConfigMap.setdefault(section, {}) 
    3131    sectMap[attr] = value 
    3232 
     
    3939            {'encodingFilter':'on', 'encodingFilter.encoding':'utf8') 
    4040    """ 
    41     sectMap = defaultMap.setdefault(section, {}) 
     41    sectMap = defaultConfigMap.setdefault(section, {}) 
    4242    sectMap.update(map) 
    4343 
     
    119119    def search_bottom_up(self, attrname): 
    120120        """ 
    121         Search on configMap, defaultMap, and cpgTree simultaneously 
     121        Search on configMap, defaultConfigMap, and cpgTree simultaneously 
    122122        Potentially recursive bottom-up implementation. It is fast  
    123123        because it can take advantage of the cache, but it it can't 
     
    134134                    return value 
    135135                except (KeyError, AttributeError): 
    136                     sectionMap = defaultMap[self.cpgpath] 
     136                    sectionMap = defaultConfigMap[self.cpgpath] 
    137137            return sectionMap[attrname] 
    138138        except KeyError: 
     
    141141    def search_top_down(self, attrname, lookupCpgTree=False): 
    142142        """ 
    143         Search on configMap, defaultMap, and cpgTree simultaneously 
     143        Search on configMap, defaultConfigMap, and cpgTree simultaneously 
    144144        Iterative top-down version. Probably slower than the bottom 
    145145        up version for big & deep web sites, because it never caches  
     
    156156            partialPath = partialPath + item 
    157157            try: 
    158                 sectionMap = defaultMap[partialPath] 
     158                sectionMap = defaultConfigMap[partialPath] 
    159159                curvalue = sectionMap[attrname] 
    160160                lastDefaultType = type(curvalue) 
     
    236236def test(): 
    237237    """simple testing""" 
    238     testDefaultMap = { 
     238    testDefaultConfigMap = { 
    239239        'server': { 
    240240            'logFile': '', 
     
    258258    testConfigFile = StringIO.StringIO(testConfigText) 
    259259    configMap = _cpconfig.loadConfigFile(testConfigFile) 
    260     defaultMap = testDefaultMap 
     260    defaultConfigMap = testDefaultConfigMap 
    261261    cpgTree = testCpgTree 
    262     reservedAttrNames = ['configMap','defaultMap'] 
     262    reservedAttrNames = ['configMap','defaultConfigMap'] 
    263263    # register more default values (simulates filters) 
    264264    setDefaultMap( 
  • trunk/cherrypy/_cpserver.py

    r148 r198  
    3333""" 
    3434 
    35 import cpg, thread, _cputil, _cpconfig, _cphttpserver, time, _cpthreadinglocal 
     35import cpg, thread, _cputil, _cphttpserver, time, _cpthreadinglocal 
    3636 
    37 def start(configFile = None, parsedConfigFile = None, configMap = {}, initOnly = 0): 
     37def start(initOnly = False): 
    3838    """ 
    3939        Main function. All it does is this: 
    40             - read/parse config file if any 
     40            - output config options 
    4141            - create response and request objects 
    4242            - creates HTTP server based on configFile and configMap 
    4343            - 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) 
    4844    """ 
    4945 
    50     # cpg.configOption contains an EmptyClass instance with all the configuration option 
    51     _cpconfig.setDefaultConfigOption() 
    52  
    53     # cpg.parsedConfigFile contains the ConfigParser instance with the parse config file 
    54     cpg.parsedConfigFile = None 
    55  
    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  
    6546    # Output config options 
    66     _cpconfig.outputConfigOptions() 
     47    cpg.config.outputConfigMap() 
    6748 
    6849    # Check the config options 
  • trunk/cherrypy/cpg.py

    r108 r198  
    3535# import server module 
    3636import _cpserver as server 
     37import _cpconfig as config 
    3738 
    3839# decorator function for exposing methods 
     
    4041    func.exposed = True 
    4142    return func 
     43 
     44# Default config options 
     45defaultConfigMap = { 
     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 
     68configMap = {} 
     69 
     70import _cpmagicattr 
  • trunk/cherrypy/test/helper.py

    r158 r198  
    132132sys.path.insert(0,os.path.normpath(os.path.join(os.getcwd(),'../../'))) 
    133133""" 
    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')) 
    135135    f.close() 
    136136 
  • trunk/cherrypy/test/testFilter1.py

    r108 r198  
    4444    index.exposed = True 
    4545cpg.root = Root() 
    46 cpg.server.start(configFile = 'testsite.cfg') 
     46cpg.config.loadConfigFile('testsite.cfg') 
     47cpg.server.start() 
    4748""" 
    4849config = "" 
  • trunk/cherrypy/test/testObjectMapping.py

    r156 r198  
    7878cpg.root.dir1.dir2.dir3 = Dir3() 
    7979cpg.root.dir1.dir2.dir3.dir4 = Dir4() 
    80 cpg.server.start(configFile = 'testsite.cfg') 
     80cpg.config.loadConfigFile('testsite.cfg') 
     81cpg.server.start() 
    8182""" 
    8283 
  • trunk/cherrypy/test/testStaticContent.py

    r158 r198  
    3333class Root: pass 
    3434cpg.root = Root() 
    35 cpg.server.start(configFile = 'testsite.cfg') 
     35cpg.config.loadConfigFile('testsite.cfg') 
     36cpg.server.start() 
    3637""" 
    3738 
  • trunk/cherrypy/test/testVirtualHostFilter.py

    r108 r198  
    6161cpg.root.site1 = Site1() 
    6262cpg.root.site2 = Site2() 
    63 cpg.server.start(configFile = 'testsite.cfg') 
     63cpg.config.loadConfigFile('testsite.cfg') 
     64cpg.server.start() 
    6465""" 
    6566 
  • trunk/cherrypy/tutorial/01_helloworld.py

    r102 r198  
    2828 
    2929# Start the CherryPy server using the configuration file tutorial.conf. 
    30 cpg.server.start(configFile = 'tutorial.conf') 
     30cpg.config.loadConfigFile('tutorial.conf') 
     31cpg.server.start() 
    3132 
  • trunk/cherrypy/tutorial/02_expose_methods.py

    r102 r198  
    2424 
    2525cpg.root = HelloWorld() 
    26 cpg.server.start(configFile = 'tutorial.conf') 
     26cpg.config.loadConfigFile('tutorial.conf') 
     27cpg.server.start() 
  • trunk/cherrypy/tutorial/03_get_and_post.py

    r102 r198  
    4242 
    4343cpg.root = WelcomePage() 
    44 cpg.server.start(configFile = 'tutorial.conf') 
     44cpg.config.loadConfigFile('tutorial.conf') 
     45cpg.server.start() 
  • trunk/cherrypy/tutorial/04_complex_site.py

    r102 r198  
    9090# creating all contained request handler objects. 
    9191 
    92 cpg.server.start(configFile = 'tutorial.conf') 
     92cpg.config.loadConfigFile('tutorial.conf') 
     93cpg.server.start() 
  • trunk/cherrypy/tutorial/05_derived_objects.py

    r102 r198  
    7373cpg.root = HomePage() 
    7474 
    75 cpg.server.start(configFile = 'tutorial.conf') 
     75cpg.config.loadConfigFile('tutorial.conf') 
     76cpg.server.start() 
  • trunk/cherrypy/tutorial/06_aspects.py

    r130 r198  
    9595cpg.root = HomePage() 
    9696 
    97 cpg.server.start(configFile = 'tutorial.conf') 
     97cpg.config.loadConfigFile('tutorial.conf') 
     98cpg.server.start() 
  • trunk/cherrypy/tutorial/07_default_method.py

    r102 r198  
    5454cpg.root = UsersPage() 
    5555 
    56 cpg.server.start(configFile = 'tutorial.conf') 
     56cpg.config.loadConfigFile('tutorial.conf') 
     57cpg.server.start() 
  • trunk/cherrypy/tutorial/08_sessions.py

    r102 r198  
    3131cpg.root = HitCounter() 
    3232 
    33 cpg.server.start(configFile = 'tutorial.conf') 
     33cpg.config.loadConfigFile('tutorial.conf') 
     34cpg.server.start() 
  • trunk/cherrypy/tutorial/09_generators_and_yield.py

    r115 r198  
    3333 
    3434cpg.root = GeneratorDemo() 
    35 cpg.server.start(configFile = 'tutorial.conf') 
     35cpg.config.loadConfigFile('tutorial.conf') 
     36cpg.server.start() 
  • trunk/cherrypy/tutorial/bonus-sqlobject.py

    r101 r198  
    167167 
    168168cpg.root = ContactManager() 
    169 cpg.server.start(configFile = 'tutorial.conf'
     169cpg.server.start(

Hosted by WebFaction

Log in as guest/cpguest to create tickets