diff options
author | fuzzyman <devnull@localhost> | 2009-12-13 23:00:59 +0000 |
---|---|---|
committer | fuzzyman <devnull@localhost> | 2009-12-13 23:00:59 +0000 |
commit | 176324adf691052eb61dcc79d5aa510e0e901392 (patch) | |
tree | 47a6d3e86a924cc4229f729e9cb129b14920b4f8 | |
parent | 664df64c7d3dae37de86bc2af0a9a55180fbe5d7 (diff) | |
download | configobj-176324adf691052eb61dcc79d5aa510e0e901392.tar.gz |
Creating a ConfigObj from another ConfigObj instance preserves order.
-rw-r--r-- | configobj.py | 13 | ||||
-rw-r--r-- | functionaltests/test_configobj.py | 5 |
2 files changed, 14 insertions, 4 deletions
diff --git a/configobj.py b/configobj.py index e9e6710..3be82d7 100644 --- a/configobj.py +++ b/configobj.py @@ -1264,10 +1264,17 @@ class ConfigObj(Section): # the Section class handles creating subsections if isinstance(infile, ConfigObj): # get a copy of our ConfigObj - infile = infile.dict() + def set_section(in_section, this_section): + for entry in in_section.scalars: + this_section[entry] = in_section[entry] + for section in in_section.sections: + this_section[section] = {} + set_section(in_section[section], this_section[section]) + set_section(infile, self) - for entry in infile: - self[entry] = infile[entry] + else: + for entry in infile: + self[entry] = infile[entry] del self._errors if configspec is not None: diff --git a/functionaltests/test_configobj.py b/functionaltests/test_configobj.py index 6ecfec2..b7e3ac2 100644 --- a/functionaltests/test_configobj.py +++ b/functionaltests/test_configobj.py @@ -23,4 +23,7 @@ class TestConfigObj(unittest.TestCase): self.assertEqual(c2.scalars, ['a', 'b', 'c']) self.assertEqual(c2.sections, ['section', 'section2', 'section3']) self.assertEqual(c2['section'].scalars, ['a', 'b', 'c']) - self.assertEqual(c2['section'].c.sections, ['section', 'section2', 'section3'])
\ No newline at end of file + self.assertEqual(c2['section'].sections, ['section', 'section2', 'section3']) + + self.assertFalse(c['section'] is c2['section']) + self.assertFalse(c['section']['section'] is c2['section']['section'])
\ No newline at end of file |