SafeConfigParser can set unsafe values

Matimus mccredie at gmail.com
Wed Jul 11 01:20:52 EDT 2007


> I agree, but that was a trivial example to demonstrate the problem.
> Writing the file out to disk writes it exactly as set(), causing a get()
> to fail just the same later.

No... The above statement is not true.

The following code:

[code]
from ConfigParser import *
import sys

cp = SafeConfigParser()
cp.add_section("sect")
cp.set("sect","opt","hello%world")

cp.write(sys.stdout)
[/code]

Produces this output:
[sect]
opt = hello%world

The write method never calls get. However, when you read the file that
was output by the above code using .get(...) will raise an error. You
can avoid that error by setting the optional 'raw' parameter to True.




More information about the Python-list mailing list