diff options
author | fuzzyman <devnull@localhost> | 2010-02-27 19:05:24 +0000 |
---|---|---|
committer | fuzzyman <devnull@localhost> | 2010-02-27 19:05:24 +0000 |
commit | 045d26e83cafc87e1da5d7960f1cadc88696b20e (patch) | |
tree | 3a10d481942a7f2323457120d7635eb7da15eb36 | |
parent | b5bc74d538a40a1dfecf3dcb6e35c17b747d36f5 (diff) | |
download | configobj-045d26e83cafc87e1da5d7960f1cadc88696b20e.tar.gz |
Values refering missing interpolation options can now be repr'd. Issue 9.
-rw-r--r-- | configobj.py | 14 | ||||
-rw-r--r-- | functionaltests/test_configobj.py | 7 |
2 files changed, 17 insertions, 4 deletions
diff --git a/configobj.py b/configobj.py index 3827cee..7e3adee 100644 --- a/configobj.py +++ b/configobj.py @@ -753,7 +753,12 @@ class Section(dict): def __repr__(self): """x.__repr__() <==> repr(x)""" - return '{%s}' % ', '.join([('%s: %s' % (repr(key), repr(self[key]))) + def _getval(key): + try: + return self[key] + except MissingInterpolationOption: + return dict.__getitem__(self, key) + return '{%s}' % ', '.join([('%s: %s' % (repr(key), repr(_getval(key)))) for key in (self.scalars + self.sections)]) __str__ = __repr__ @@ -1367,8 +1372,13 @@ class ConfigObj(Section): def __repr__(self): + def _getval(key): + try: + return self[key] + except MissingInterpolationOption: + return dict.__getitem__(self, key) return ('ConfigObj({%s})' % - ', '.join([('%s: %s' % (repr(key), repr(self[key]))) + ', '.join([('%s: %s' % (repr(key), repr(_getval(key)))) for key in (self.scalars + self.sections)])) diff --git a/functionaltests/test_configobj.py b/functionaltests/test_configobj.py index 8528028..31e63d9 100644 --- a/functionaltests/test_configobj.py +++ b/functionaltests/test_configobj.py @@ -76,13 +76,16 @@ item1 = 1234 item2 = '$item1'""".splitlines() c = ConfigObj(cfg, interpolation='Template') - # This raises an exception in 4.7.1 and earlier + # This raises an exception in 4.7.1 and earlier due to the section + # being found as the interpolation value repr(c) def test_interoplation_repr(self): c = ConfigObj(['foo = $bar'], interpolation='Template') + c['baz'] = {} + c['baz']['spam'] = '%(bar)s' - # This raises an exception in 4.7.1 and earlier + # This raises a MissingInterpolationOption exception in 4.7.1 and earlier repr(c) |