registry: Make subvalues inherit privacy. Closes GH-519.

This commit is contained in:
Valentin Lorentz 2013-10-06 14:26:03 +00:00
parent 16b95bb244
commit 359d3c633d
2 changed files with 28 additions and 1 deletions

View File

@ -252,7 +252,9 @@ class Group(object):
if not isValidRegistryName(name): if not isValidRegistryName(name):
raise InvalidRegistryName, name raise InvalidRegistryName, name
if node is None: if node is None:
node = Group() node = Group(private=self._private)
else:
node._private = node._private or self._private
# We tried in any number of horrible ways to make it so that # We tried in any number of horrible ways to make it so that
# re-registering something would work. It doesn't, plain and simple. # re-registering something would work. It doesn't, plain and simple.
# For the longest time, we had an "Is this right?" comment here, but # For the longest time, we had an "Is this right?" comment here, but

View File

@ -199,4 +199,29 @@ class ValuesTestCase(SupyTestCase):
self.assertEqual(v(), 'bar') self.assertEqual(v(), 'bar')
self.assertEqual(v(), 'foo') self.assertEqual(v(), 'foo')
class SecurityTestCase(SupyTestCase):
def testPrivate(self):
v = registry.String('foo', 'help')
self.assertFalse(v._private)
v = registry.String('foo', 'help', private=True)
self.assertTrue(v._private)
g = registry.Group('foo')
v = registry.String('foo', 'help')
g.register('val', v)
self.assertFalse(g._private)
self.assertFalse(g.val._private)
g = registry.Group('foo', private=True)
v = registry.String('foo', 'help')
g.register('val', v)
self.assertTrue(g._private)
self.assertTrue(g.val._private)
g = registry.Group('foo')
v = registry.String('foo', 'help', private=True)
g.register('val', v)
self.assertFalse(g._private)
self.assertTrue(g.val._private)
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: