[Python-checkins] CVS: python/dist/src/Lib ConfigParser.py,1.36,1.37
Guido van Rossum
gvanrossum@users.sourceforge.net
2001年10月04日 12:58:48 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv15959
Modified Files:
ConfigParser.py
Log Message:
Apply modified SF patch 467580: ConfigParser.getboolean(): FALSE, TRUE.
This patch allows ConfigParser.getboolean() to interpret TRUE,
FALSE, YES, NO, ON and OFF instead just '0' and '1'.
While just allowing '0' and '1' sounds more correct users often
demand to use more descriptive directives in configuration
files. Instead of forcing every programmer do brew his own
solution a system should include the batteries for this.
[My modification to the patch is a slight rewording of the docstring
and use of lowercase instead of uppercase templates. The code is
still case sensitive. GvR.]
Index: ConfigParser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ConfigParser.py,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** ConfigParser.py 2001年08月17日 18:39:24 1.36
--- ConfigParser.py 2001年10月04日 19:58:46 1.37
***************
*** 67,72 ****
getboolean(section, options)
! like get(), but convert value to a boolean (currently defined as 0 or
! 1, only)
remove_section(section)
--- 67,73 ----
getboolean(section, options)
! like get(), but convert value to a boolean (currently case
! insensitively defined as 0, false, no, off for 0, and 1, true,
! yes, on for 1). Returns 0 or 1.
remove_section(section)
***************
*** 307,315 ****
def getboolean(self, section, option):
! v = self.get(section, option)
! val = int(v)
! if val not in (0, 1):
raise ValueError, 'Not a boolean: %s' % v
! return val
def optionxform(self, optionstr):
--- 308,317 ----
def getboolean(self, section, option):
! states = {'1': 1, 'yes': 1, 'true': 1, 'on': 1,
! '0': 0, 'no': 0, 'false': 0, 'off': 0}
! v = self.get(section, option)
! if not states.has_key(v.lower()):
raise ValueError, 'Not a boolean: %s' % v
! return states[v.lower()]
def optionxform(self, optionstr):