This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: SaveConfigParser.write() doesn't quote %-Sign
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, mark-roberts, rbreu
Priority: normal Keywords:

Created on 2006-11-27 12:15 by rbreu, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg30695 - (view) Author: Rebecca Breu (rbreu) Date: 2006-11-27 12:15
>>> parser = ConfigParser.SafeConfigParser()
>>> parser.add_section("test")
>>> parser.set("test", "foo", "bar%bar")
>>> parser.write(open("test.config", "w"))
>>> parser2 = ConfigParser.SafeConfigParser()
>>> parser2.readfp(open("test.config"))
>>> parser.get("test", "foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/ConfigParser.py", line 525, in get
    return self._interpolate(section, option, value, d)
  File "/usr/lib/python2.4/ConfigParser.py", line 593, in _interpolate
    self._interpolate_some(option, L, rawval, section, vars, 1)
  File "/usr/lib/python2.4/ConfigParser.py", line 634, in _interpolate_some
    "'%%' must be followed by '%%' or '(', found: %r" % (rest,))
ConfigParser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%bar'


Problem: SaveConfigParser saves the string "bar%bar" as is and not as "bar%%bar".
msg30696 - (view) Author: Mark Roberts (mark-roberts) Date: 2007-01-15 02:33
I'm not sure that automagically changing their input is such a great idea.  I'm -0 for automagically changing their input, but +1 for raising ValueError when the input contains a string that can't be properly interpolated.  I've implemented the patch both ways.  Anyone else have an opinion about this?

Examples of such malformatted strings include bar%bar and bar%.
msg30697 - (view) Author: Mark Roberts (mark-roberts) Date: 2007-01-15 07:45
Initially, I believed ValueError was the appropriate way to go with this. However, when I thought about how I use ConfigParser, I realized that it would be far nicer if it simply worked.

See the patches in 1635639.
http://sourceforge.net/tracker/index.php?func=detail&aid=1635639&group_id=5470&atid=105470

Good catch on this.  I haven't caught it and I've been using ConfigParser for a while now.
msg30698 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-01-16 20:50
Closing this as a duplicate.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44283
2006-11-27 12:15:17rbreucreate