mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
Time machine experiment. Use '__name__' as the special key (always
present) that refers to the section name. Also added a (slightly) better InterpolationError error message, which includes the raw string.
This commit is contained in:
parent
f5475c95a7
commit
6446212593
1 changed files with 10 additions and 6 deletions
|
@ -28,7 +28,7 @@ ConfigParser -- responsible for for parsing a list of
|
||||||
dictionary of intrinsic defaults. The
|
dictionary of intrinsic defaults. The
|
||||||
keys must be strings, the values must
|
keys must be strings, the values must
|
||||||
be appropriate for %()s string
|
be appropriate for %()s string
|
||||||
interpolation. Note that `name' is
|
interpolation. Note that `__name__' is
|
||||||
always an intrinsic default; it's value
|
always an intrinsic default; it's value
|
||||||
is the section's name.
|
is the section's name.
|
||||||
|
|
||||||
|
@ -87,10 +87,14 @@ class NoOptionError(Error):
|
||||||
self.section = section
|
self.section = section
|
||||||
|
|
||||||
class InterpolationError(Error):
|
class InterpolationError(Error):
|
||||||
def __init__(self, reference, option, section):
|
def __init__(self, reference, option, section, rawval):
|
||||||
Error.__init__(self,
|
Error.__init__(self,
|
||||||
"Bad value substitution: sect `%s', opt `%s', ref `%s'"
|
"Bad value substitution:\n"
|
||||||
% (section, option, reference))
|
"\tsection: [%s]\n"
|
||||||
|
"\toption : %s\n"
|
||||||
|
"\tkey : %s\n"
|
||||||
|
"\trawval : %s\n"
|
||||||
|
% (section, option, reference, rawval))
|
||||||
self.reference = reference
|
self.reference = reference
|
||||||
self.option = option
|
self.option = option
|
||||||
self.section = section
|
self.section = section
|
||||||
|
@ -198,7 +202,7 @@ class ConfigParser:
|
||||||
try:
|
try:
|
||||||
return rawval % d
|
return rawval % d
|
||||||
except KeyError, key:
|
except KeyError, key:
|
||||||
raise InterpolationError(key, option, section)
|
raise InterpolationError(key, option, section, rawval)
|
||||||
|
|
||||||
def __get(self, section, conv, option):
|
def __get(self, section, conv, option):
|
||||||
return conv(self.get(section, option))
|
return conv(self.get(section, option))
|
||||||
|
@ -275,7 +279,7 @@ class ConfigParser:
|
||||||
elif sectname == DEFAULTSECT:
|
elif sectname == DEFAULTSECT:
|
||||||
cursect = self.__defaults
|
cursect = self.__defaults
|
||||||
else:
|
else:
|
||||||
cursect = {}
|
cursect = {'__name__': sectname}
|
||||||
self.__sections[sectname] = cursect
|
self.__sections[sectname] = cursect
|
||||||
# So sections can't start with a continuation line
|
# So sections can't start with a continuation line
|
||||||
optname = None
|
optname = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue