mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-11 21:01:44 +00:00
Add a helper to make a deep copy of a ConfigParser
This will help avoid unintentional side-effects
This commit is contained in:
parent
84647e25b7
commit
53aa434d77
@ -280,3 +280,16 @@ enabled = false
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
@given(arbitrary_config_dicts())
|
||||
def test_copy_config(self, cfgdict):
|
||||
"""
|
||||
``copy_config`` creates a new ``ConfigParser`` object containing the same
|
||||
values as its input.
|
||||
"""
|
||||
cfg = to_configparser(cfgdict)
|
||||
copied = configutil.copy_config(cfg)
|
||||
# Should be equal
|
||||
self.assertEqual(cfg, copied)
|
||||
# But not because they're the same object.
|
||||
self.assertIsNot(cfg, copied)
|
||||
|
@ -173,6 +173,23 @@ class ValidConfiguration(object):
|
||||
)
|
||||
|
||||
|
||||
def copy_config(old):
|
||||
"""
|
||||
Return a brand new ``ConfigParser`` containing the same values as
|
||||
the given object.
|
||||
|
||||
:param ConfigParser old: The configuration to copy.
|
||||
|
||||
:return ConfigParser: The new object containing the same configuration.
|
||||
"""
|
||||
new = ConfigParser()
|
||||
for section_name in old.sections():
|
||||
new.add_section(section_name)
|
||||
for k, v in old.items(section_name):
|
||||
new.set(section_name, k, v.replace("%", "%%"))
|
||||
return new
|
||||
|
||||
|
||||
def _either(f, g):
|
||||
"""
|
||||
:return: A function which returns True if either f or g returns True.
|
||||
|
Loading…
x
Reference in New Issue
Block a user