diff options
author | Daniel Stutzbach <daniel@stutzbachenterprises.com> | 2010-08-24 21:09:30 (GMT) |
---|---|---|
committer | Daniel Stutzbach <daniel@stutzbachenterprises.com> | 2010-08-24 21:09:30 (GMT) |
commit | 9128732de668e5777e135a423d3fa8b9bbd71fe1 (patch) | |
tree | 19cf1f302337c077e6a421d247fedfd2f7f907dd | |
parent | 6fb0fd12328449d7899f11d42f11e2b0d39231cf (diff) | |
download | cpython-9128732de668e5777e135a423d3fa8b9bbd71fe1.zip cpython-9128732de668e5777e135a423d3fa8b9bbd71fe1.tar.gz cpython-9128732de668e5777e135a423d3fa8b9bbd71fe1.tar.bz2 |
Merged revisions 84301 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r84301 | daniel.stutzbach | 2010-08-24 15:49:57 -0500 (Tue, 24 Aug 2010) | 1 line
Issue 8750: Fixed MutableSet's methods to correctly handle reflexive operations, namely x -= x and x ^= x
........
-rw-r--r-- | Lib/_abcoll.py | 24 | ||||
-rw-r--r-- | Lib/test/test_collections.py | 15 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 33 insertions, 9 deletions
diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py index e9234af..73e668c 100644 --- a/Lib/_abcoll.py +++ b/Lib/_abcoll.py @@ -305,18 +305,24 @@ class MutableSet(Set): return self def __ixor__(self, it): - if not isinstance(it, Set): - it = self._from_iterable(it) - for value in it: - if value in self: - self.discard(value) - else: - self.add(value) + if it is self: + self.clear() + else: + if not isinstance(it, Set): + it = self._from_iterable(it) + for value in it: + if value in self: + self.discard(value) + else: + self.add(value) return self def __isub__(self, it): - for value in it: - self.discard(value) + if it is self: + self.clear() + else: + for value in it: + self.discard(value) return self MutableSet.register(set) diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index f10f956..16c4552 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -526,6 +526,21 @@ class TestCollectionABCs(ABCTestCase): s = MySet([5,43,2,1]) self.assertEqual(s.pop(), 1) + def test_issue8750(self): + empty = WithSet() + full = WithSet(range(10)) + s = WithSet(full) + s -= s + self.assertEqual(s, empty) + s = WithSet(full) + s ^= s + self.assertEqual(s, empty) + s = WithSet(full) + s &= s + self.assertEqual(s, full) + s |= s + self.assertEqual(s, full) + def test_Mapping(self): for sample in [dict]: self.assertIsInstance(sample(), Mapping) @@ -31,6 +31,9 @@ Core and Builtins Library ------- +- Issue #8750: Fixed MutableSet's methods to correctly handle + reflexive operations, namely x -= x and x ^= x. + - Issue #9129: smtpd.py is vulnerable to DoS attacks deriving from missing error handling when accepting a new connection. |