summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrabner <pjg.github@ubergrabner.net>2014-04-16 15:35:47 -0400
committergrabner <pjg.github@ubergrabner.net>2014-04-16 15:35:47 -0400
commit8a4a5c92c7691270d86a282f3b60fc0f94866328 (patch)
tree656eeb5bb72e3e61e181e5818e5f363b6822a565
parente8b3d11417e9adae65f6d36b2a75de9cd1116242 (diff)
downloadiniherit-8a4a5c92c7691270d86a282f3b60fc0f94866328.tar.gz
added workaround for py3 issue #21265
-rw-r--r--iniherit/parser.py12
-rw-r--r--iniherit/test.py11
2 files changed, 22 insertions, 1 deletions
diff --git a/iniherit/parser.py b/iniherit/parser.py
index 95ccba4..ee9ae6e 100644
--- a/iniherit/parser.py
+++ b/iniherit/parser.py
@@ -154,7 +154,17 @@ class IniheritMixin(object):
if src.has_option(self.IM_DEFAULTSECT, option) \
and value == src.get(self.IM_DEFAULTSECT, option):
continue
- _real_RawConfigParser.set(dst, dstsect, option, value)
+ if six.PY3 and hasattr(dst, '_interpolation'):
+ # todo: don't do this for systems that have
+ # http://bugs.python.org/issue21265 fixed
+ try:
+ tmp = dst._interpolation.before_set
+ dst._interpolation.before_set = lambda self,s,o,v,*a,**k: v
+ _real_RawConfigParser.set(dst, dstsect, option, value)
+ finally:
+ dst._interpolation.before_set = tmp
+ else:
+ _real_RawConfigParser.set(dst, dstsect, option, value)
#------------------------------------------------------------------------------
# todo: i'm a little worried about the diamond inheritance here...
diff --git a/iniherit/test.py b/iniherit/test.py
index dc66e96..676eed7 100644
--- a/iniherit/test.py
+++ b/iniherit/test.py
@@ -133,6 +133,17 @@ kw6 = extend-kw6
sorted(dict(foo='bar', zig='zag', x='z').items()))
#----------------------------------------------------------------------------
+ def test_iniherit_interpolation(self):
+ files = [
+ ('config.ini', '[app]\noutput = %(tmpdir)s/var/result.log\n'),
+ ]
+ parser = SafeConfigParser(
+ defaults={'tmpdir': '/tmp'}, loader=ByteLoader(dict(files)))
+ parser.read('config.ini')
+ self.assertEqual(parser.get('app', 'output'), '/tmp/var/result.log')
+ self.assertEqual(parser.get('app', 'output', raw=True), '%(tmpdir)s/var/result.log')
+
+ #----------------------------------------------------------------------------
def test_iniherit_invalidInterpolationValues(self):
files = [
('config.ini', '[logger]\ntimefmt=%H:%M:%S\n'),