wasm-demo/demo/ermis-f/python_m/cur/1252

59 lines
1.8 KiB
Plaintext

From: fatjim at home.com (Jim Meier)
Date: Mon, 12 Apr 1999 15:59:05 GMT
Subject: ConfigParser module and alternatives (flad, flan)
References: <19990331160323.21601.00000471@ng-fi1.aol.com> <7du3ab$3ag@chronicle.concentric.net> <jtaewsfmlj.fsf@wazor.biostat.wisc.edu> <xcxP2.1302$rd2.27684@news14.ispnews.com>
Message-ID: <371219E9.9EA91839@home.com>
Content-Length: 1444
X-UID: 1252
Mike Orr wrote:
> I'm not sure if I'll use ConfigParser for the next version. I don't
> really need the sections (multiple files work just fine, using the filename
> for the section name), and I haven't found a use for the the %(other_key)s
> substitutions. On the other hand, it doesn't handle multiple values (the
> same key repeated within a record), which I sometimes need.
>
> Attached is a wrapper class for ConfigParser which supports booleans
> and can also return an entire section as a dictionary (or all the sections
> as nested dictionaries). I find these make it a little more convenient.
>
Why not simply use a file of python expressions? Like this:
{'section1': {
'key1':[1,2,3,'value',['useful','nesting','eh?']],
'key2':'anotherval'
},
'section2': {
'subsection':{
'subkey':5
}
}
}
I beleive you can even use variable names in such files for application-specified
substitutions, like this:
(python app defines variable "rootdir")
{'pathssection': {
'fontpath': rootdir+'/font/'
}
}
This introduces some major security problems, and is a little difficult to edit,
but there is very little parsing needed to make it usable. Does anyone know of a
way to limit the damage a user can do to such a file?
Another idea is to run your config file through a simple macro utility (or do the
macro conversion in python itself) to convert it into python code to eval.
Jim Meier