def difference(self, other):
return ImmutableRdataset(super().difference(other))
+ def symmetric_difference(self, other):
+ return ImmutableRdataset(super().symmetric_difference(other))
+
def from_text_list(rdclass, rdtype, ttl, text_rdatas, idna_codec=None,
origin=None, relativize=True, relativize_to=None):
for item in other.items:
self.discard(item)
+ def symmetric_difference_update(self, other):
+ """Update the set, retaining only elements unique to both sets."""
+
+ if not isinstance(other, Set):
+ raise ValueError('other must be a Set instance')
+ if self is other:
+ self.items.clear()
+ else:
+ overlap = self.intersection(other)
+ self.union_update(other)
+ self.difference_update(overlap)
+
def union(self, other):
"""Return a new set which is the union of ``self`` and ``other``.
obj.difference_update(other)
return obj
+ def symmetric_difference(self, other):
+ """Return a new set which (``self`` - ``other``) | (``other``
+ - ``self), ie: the items in either ``self`` or ``other`` which
+ are not contained in their intersection.
+
+ Returns the same Set type as this set.
+ """
+
+ obj = self._clone()
+ obj.symmetric_difference_update(other)
+ return obj
+
def __or__(self, other):
return self.union(other)
def __sub__(self, other):
return self.difference(other)
+ def __xor__(self, other):
+ return self.symmetric_difference(other)
+
def __ior__(self, other):
self.union_update(other)
return self
self.difference_update(other)
return self
+ def __ixor__(self, other):
+ self.symmetric_difference_update(other)
+ return self
+
def update(self, other):
"""Update the set, adding any elements from other which are not
already in the set.
e = S([])
self.assertEqual(s1 - s2, e)
+ def testSymmetricDifference1(self):
+ s1 = S([1, 2, 3])
+ s2 = S([5, 4])
+ e = S([1, 2, 3, 4, 5])
+ self.assertEqual(s1 ^ s2, e)
+
+ def testSymmetricDifference2(self):
+ s1 = S([1, 2, 3])
+ s2 = S([])
+ e = S([1, 2, 3])
+ self.assertEqual(s1 ^ s2, e)
+
+ def testSymmetricDifference3(self):
+ s1 = S([1, 2, 3])
+ s2 = S([3, 2])
+ e = S([1])
+ self.assertEqual(s1 ^ s2, e)
+
+ def testSymmetricDifference4(self):
+ s1 = S([1, 2, 3])
+ s2 = S([3, 2, 1])
+ e = S([])
+ self.assertEqual(s1 ^ s2, e)
+
def testSubset1(self):
s1 = S([1, 2, 3])
s2 = S([3, 2, 1])