Package lxml :: Package html :: Module setmixin

[hide private]
[frames] | no frames]

# Source Code for Module lxml.html.setmixin

      1 -class SetMixin(object):
      2
      3      """
      4      Mix-in for sets.  You must define __iter__, add, remove
      5      """
      6
      7 -    def __len__(self):
      8          length = 0
      9          for item in self:
     10              length += 1
     11          return length
     12
     13 -    def __contains__(self, item):
     14          for has_item in self:
     15              if item == has_item:
     16                  return True
     17          return False
     18
     19 -    def issubset(self, other):
     20          for item in other:
     21              if item not in self:
     22                  return False
     23          return True
     24
     25      __le__ = issubset
     26
     27 -    def issuperset(self, other):
     28          for item in self:
     29              if item not in other:
     30                  return False
     31          return True
     32
     33      __ge__ = issuperset
     34
     35 -    def union(self, other):
     36          return self | other
     37
     38 -    def __or__(self, other):
     39          new = self.copy()
     40          new |= other
     41          return new
     42
     43 -    def intersection(self, other):
     44          return self & other
     45
     46 -    def __and__(self, other):
     47          new = self.copy()
     48          new &= other
     49          return new
     50
     51 -    def difference(self, other):
     52          return self - other
     53
     54 -    def __sub__(self, other):
     55          new = self.copy()
     56          new -= other
     57          return new
     58
     59 -    def symmetric_difference(self, other):
     60          return self ^ other
     61
     62 -    def __xor__(self, other):
     63          new = self.copy()
     64          new ^= other
     65          return new
     66
     67 -    def copy(self):
     68          return set(self)
     69
     70 -    def update(self, other):
     71          for item in other:
     72              self.add(item)
     73
     74 -    def __ior__(self, other):
     75          self.update(other)
     76          return self
     77
     78 -    def intersection_update(self, other):
     79          for item in self:
     80              if item not in other:
     81                  self.remove(item)
     82
     83 -    def __iand__(self, other):
     84          self.intersection_update(other)
     85          return self
     86
     87 -    def difference_update(self, other):
     88          for item in other:
     89              if item in self:
     90                  self.remove(item)
     91
     92 -    def __isub__(self, other):
     93          self.difference_update(other)
     94          return self
     95
     96 -    def symmetric_difference_update(self, other):
     97          for item in other:
     98              if item in self:
     99                  self.remove(item)
    100              else:
    101                  self.add(item)
    102
    103 -    def __ixor__(self, other):
    104          self.symmetric_difference_update(other)
    105          return self
    106
    107 -    def discard(self, item):
    108          try:
    109              self.remove(item)
    110          except KeyError:
    111              pass
    112
    113 -    def clear(self):
    114          for item in list(self):
    115              self.remove(item)
    116