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

Ticket #427 (enhancement)

Opened 3 years ago

Last modified 3 years ago

Use RawConfigParser instead of ConfigParser

Status: closed (fixed)

Reported by: lasi Assigned to: rdelon
Priority: lowest Milestone:
Component: CherryPy code Keywords: config
Cc: lasi@freekeylabs.com

The cherrypy.config module is a wraper of python ConfigParser.ConfigParser class. It could be easily a wraper for ConfigParser.RawConfigParser.

Thanks a lot

Change History

12/30/05 18:45:50: Modified by fumanchu

  • summary changed from Enhancement to Use RawConfigParser instead of ConfigParser.

Why?

12/30/05 19:11:51: Modified by lasi

Sorry, my english is very bad, i can't mean instead i can mean also.

ConfigParser is util in many cases (99%), but sometimes is necessary RawConfigParser (ConfigParser replace variables in value of the config files).

The overload of optionxform function in CaseSensitiveConfigParser class is very usefull. This is the reason to add this feature to this library, and not use RawConfigParser directly.

pardon to confuse instead by also

do you think that could be usefull add the RawConfigParser functionality?

12/30/05 21:42:46: Modified by lasi

A diff whith my proposal:

=== config.py
==================================================================
--- config.py   (revision 1343)
+++ config.py   (local)
@@ -200,7 +200,7 @@
             finally:
                 fp.close()
 
-def dict_from_config_file(configFile):
+def dict_from_config_file(configFile, raw=False, vars=None):
     """Convert an INI file to a dictionary"""
     
     # Parse config file
@@ -216,7 +216,7 @@
         if section not in result:
             result[section] = {}
         for option in configParser.options(section):
-            value = configParser.get(section, option)
+            value = configParser.get(section, option, raw, vars)
             try:
                 value = cptools.unrepr(value)
             except Exception, x:

With this change, I can use dict_from_config_file function to get quickly a config for my app.

With raw parameter set to True, I can read easily messages for use with formencode api. A example message in formencode validations:

messages = {
        'tooLong': "Enter a value less than %(maxLength)i characters long",
        'invalid': "Invalid value (value with length expected)",
        }

The tooLong key is problematic because have the maxLength variable. With raw read, there are no problem.

I haven't got idea of a realistic example of convenience of vars parameter. But is cheap add it, and it could be useful.

PD: The authentic revision isn't 1343, this is my local revision because I use SVK

03/03/06 18:27:44: Modified by fumanchu

  • status changed from new to closed.
  • resolution set to fixed.

Implemented in [999].

Hosted by WebFaction

Log in as guest/cpguest to create tickets