bug 1050922 - Add an update method to FlagsFactory.Flags. r=gps

This commit is contained in:
Ted Mielczarek 2014-08-14 12:12:04 -04:00
parent 3920eb41a0
commit 3f3545c38e
2 changed files with 11 additions and 0 deletions

View File

@ -370,6 +370,13 @@ class TestStrictOrderingOnAppendListWithFlagsFactory(unittest.TestCase):
with self.assertRaises(AttributeError):
l['b'].baz = False
l['b'].update(foo=False, bar=12)
self.assertEqual(l['b'].foo, False)
self.assertEqual(l['b'].bar, 12)
with self.assertRaises(AttributeError):
l['b'].update(xyz=1)
class TestHierarchicalStringListWithFlagsFactory(unittest.TestCase):
def test_hierarchical_string_list_with_flags_factory(self):

View File

@ -375,6 +375,10 @@ def FlagsFactory(flags):
__slots__ = flags.keys()
_flags = flags
def update(self, **kwargs):
for k, v in kwargs.iteritems():
setattr(self, k, v)
def __getattr__(self, name):
if name not in self.__slots__:
raise AttributeError("'%s' object has no attribute '%s'" %