[issue10387] ConfigParser's getboolean method is broken

2010-11-11 Thread Felix Laurie von Massenbach

New submission from Felix Laurie von Massenbach fantasi...@gmail.com:

If the config file has a boolean formatted as either True or False, python 
raises an attribute error when doing str.lower() on it. In my code I've worked 
around this in the following way:

class MyConfigParser(ConfigParser.RawConfigParser):
def getboolean(self, section, option):
result = self.get(section, option)
try:
trues = [1, yes, true, on]
falses = [0, no, false, off]
if result in trues:
return True
if result in falses:
return False
except AttributeError as err:
if str(err) == \'bool\' object has no attribute \'lower\':
return result
raise err

Felix

(p.s. first bug report, sorry if it's a bit of a mess...)

--
components: Extension Modules
messages: 120943
nosy: Felix.Laurie.von.Massenbach
priority: normal
severity: normal
status: open
title: ConfigParser's getboolean method is broken
type: crash
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10387
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10387] ConfigParser's getboolean method is broken

2010-11-11 Thread Felix Laurie von Massenbach

Felix Laurie von Massenbach fantasi...@gmail.com added the comment:

Oops, that was the broken first version. Let's try again:

class MyConfigParser(ConfigParser.RawConfigParser):
def getboolean(self, section, option):
result = self.get(section, option)
try:
trues = [1, yes, true, on]
falses = [0, no, false, off]
if result.lower() in trues:
return True
if result.lower() in falses:
return False
except AttributeError as err:
if str(err) == \'bool\' object has no attribute \'lower\':
return result
raise err

Felix

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10387
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10387] ConfigParser's getboolean method is broken

2010-11-11 Thread Felix Laurie von Massenbach

Felix Laurie von Massenbach fantasi...@gmail.com added the comment:

Perhaps I don't understand fully, but I am reading, for example, option = 
True from a config file. When doing this getboolean raises:

AttributeError: 'bool' object has no attribute 'lower'

Is it intended that you cannot store True and False as values in the config 
file?

Apologies if I'm being dense.

Felix

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10387
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10387] ConfigParser's getboolean method is broken

2010-11-11 Thread Felix Laurie von Massenbach

Felix Laurie von Massenbach fantasi...@gmail.com added the comment:

Ok, so I understand the issue, but why doesn't the set method simply convert to 
a string?

 from ConfigParser import RawConfigParser
 from StringIO import StringIO
 parser = RawConfigParser()
 config = 
[section]
test = True

 parser.readfp(StringIO(config))
 parser.get(section, test)
'True'
 parser.getboolean(section, test)
True
 parser.set(section, test, True)
 parser.get(section, test)
True
 parser.getboolean(section, test)

Traceback (most recent call last):
  File pyshell#33, line 1, in module
parser.getboolean(section, test)
  File C:\Python27\lib\ConfigParser.py, line 361, in getboolean
if v.lower() not in self._boolean_states:
AttributeError: 'bool' object has no attribute 'lower'

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10387
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com