Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e480ad

Browse files
committed
Patch suggested (and partially provided) by Lars Damerow: instead of
always lowercasing the option name, call a method optionxform() which can be overridden. Also make the regexps SECTRE and OPTRE non-private variables so they can also be overridden.
1 parent e019789 commit 9e480ad

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Lib/ConfigParser.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def get(self, section, option, raw=0, vars=None):
199199
# Update with the entry specific variables
200200
if vars:
201201
d.update(vars)
202-
option = string.lower(option)
202+
option = self.optionxform(option)
203203
try:
204204
rawval = d[option]
205205
except KeyError:
@@ -236,16 +236,19 @@ def getboolean(self, section, option):
236236
raise ValueError, 'Not a boolean: %s' % v
237237
return val
238238

239+
def optionxform(self, optionstr):
240+
return string.lower(optionstr)
241+
239242
#
240243
# Regular expressions for parsing section headers and options. Note a
241244
# slight semantic change from the previous version, because of the use
242245
# of \w, _ is allowed in section header names.
243-
__SECTCRE = re.compile(
246+
SECTCRE = re.compile(
244247
r'\[' # [
245248
r'(?P<header>[-\w]+)' # `-', `_' or any alphanum
246249
r'\]' # ]
247250
)
248-
__OPTCRE = re.compile(
251+
OPTCRE = re.compile(
249252
r'(?P<option>[-.\w]+)' # - . _ alphanum
250253
r'[ \t]*[:=][ \t]*' # any number of space/tab,
251254
# followed by separator
@@ -287,7 +290,7 @@ def __read(self, fp):
287290
# a section header or option header?
288291
else:
289292
# is it a section header?
290-
mo = self.__SECTCRE.match(line)
293+
mo = self.SECTCRE.match(line)
291294
if mo:
292295
sectname = mo.group('header')
293296
if self.__sections.has_key(sectname):
@@ -304,7 +307,7 @@ def __read(self, fp):
304307
raise MissingSectionHeaderError(fp.name, lineno, `line`)
305308
# an option line?
306309
else:
307-
mo = self.__OPTCRE.match(line)
310+
mo = self.OPTCRE.match(line)
308311
if mo:
309312
optname, optval = mo.group('option', 'value')
310313
optname = string.lower(optname)

0 commit comments

Comments
 (0)