home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1691 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  7.6 KB  |  219 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4.  
  5. class Set(object):
  6.     __slots__ = [
  7.         'items']
  8.     
  9.     def __init__(self, items = None):
  10.         self.items = []
  11.         if items is not None:
  12.             for item in items:
  13.                 self.add(item)
  14.             
  15.         
  16.  
  17.     
  18.     def __repr__(self):
  19.         return 'dns.simpleset.Set(%s)' % repr(self.items)
  20.  
  21.     
  22.     def add(self, item):
  23.         if item not in self.items:
  24.             self.items.append(item)
  25.         
  26.  
  27.     
  28.     def remove(self, item):
  29.         self.items.remove(item)
  30.  
  31.     
  32.     def discard(self, item):
  33.         
  34.         try:
  35.             self.items.remove(item)
  36.         except ValueError:
  37.             pass
  38.  
  39.  
  40.     
  41.     def _clone(self):
  42.         cls = self.__class__
  43.         obj = cls.__new__(cls)
  44.         obj.items = list(self.items)
  45.         return obj
  46.  
  47.     
  48.     def __copy__(self):
  49.         return self._clone()
  50.  
  51.     
  52.     def copy(self):
  53.         return self._clone()
  54.  
  55.     
  56.     def union_update(self, other):
  57.         if not isinstance(other, Set):
  58.             raise ValueError, 'other must be a Set instance'
  59.         isinstance(other, Set)
  60.         if self is other:
  61.             return None
  62.         for item in other.items:
  63.             self.add(item)
  64.         
  65.  
  66.     
  67.     def intersection_update(self, other):
  68.         if not isinstance(other, Set):
  69.             raise ValueError, 'other must be a Set instance'
  70.         isinstance(other, Set)
  71.         if self is other:
  72.             return None
  73.         for item in list(self.items):
  74.             if item not in other.items:
  75.                 self.items.remove(item)
  76.                 continue
  77.             self is other
  78.         
  79.  
  80.     
  81.     def difference_update(self, other):
  82.         if not isinstance(other, Set):
  83.             raise ValueError, 'other must be a Set instance'
  84.         isinstance(other, Set)
  85.         if self is other:
  86.             self.items = []
  87.         else:
  88.             for item in other.items:
  89.                 self.discard(item)
  90.             
  91.  
  92.     
  93.     def union(self, other):
  94.         obj = self._clone()
  95.         obj.union_update(other)
  96.         return obj
  97.  
  98.     
  99.     def intersection(self, other):
  100.         obj = self._clone()
  101.         obj.intersection_update(other)
  102.         return obj
  103.  
  104.     
  105.     def difference(self, other):
  106.         obj = self._clone()
  107.         obj.difference_update(other)
  108.         return obj
  109.  
  110.     
  111.     def __or__(self, other):
  112.         return self.union(other)
  113.  
  114.     
  115.     def __and__(self, other):
  116.         return self.intersection(other)
  117.  
  118.     
  119.     def __add__(self, other):
  120.         return self.union(other)
  121.  
  122.     
  123.     def __sub__(self, other):
  124.         return self.difference(other)
  125.  
  126.     
  127.     def __ior__(self, other):
  128.         self.union_update(other)
  129.         return self
  130.  
  131.     
  132.     def __iand__(self, other):
  133.         self.intersection_update(other)
  134.         return self
  135.  
  136.     
  137.     def __iadd__(self, other):
  138.         self.union_update(other)
  139.         return self
  140.  
  141.     
  142.     def __isub__(self, other):
  143.         self.difference_update(other)
  144.         return self
  145.  
  146.     
  147.     def update(self, other):
  148.         for item in other:
  149.             self.add(item)
  150.         
  151.  
  152.     
  153.     def clear(self):
  154.         self.items = []
  155.  
  156.     
  157.     def __eq__(self, other):
  158.         for item in self.items:
  159.             if item not in other.items:
  160.                 return False
  161.         
  162.         for item in other.items:
  163.             if item not in self.items:
  164.                 return False
  165.         
  166.         return True
  167.  
  168.     
  169.     def __ne__(self, other):
  170.         return not self.__eq__(other)
  171.  
  172.     
  173.     def __len__(self):
  174.         return len(self.items)
  175.  
  176.     
  177.     def __iter__(self):
  178.         return iter(self.items)
  179.  
  180.     
  181.     def __getitem__(self, i):
  182.         return self.items[i]
  183.  
  184.     
  185.     def __delitem__(self, i):
  186.         del self.items[i]
  187.  
  188.     
  189.     def __getslice__(self, i, j):
  190.         return self.items[i:j]
  191.  
  192.     
  193.     def __delslice__(self, i, j):
  194.         del self.items[i:j]
  195.  
  196.     
  197.     def issubset(self, other):
  198.         if not isinstance(other, Set):
  199.             raise ValueError, 'other must be a Set instance'
  200.         isinstance(other, Set)
  201.         for item in self.items:
  202.             if item not in other.items:
  203.                 return False
  204.         
  205.         return True
  206.  
  207.     
  208.     def issuperset(self, other):
  209.         if not isinstance(other, Set):
  210.             raise ValueError, 'other must be a Set instance'
  211.         isinstance(other, Set)
  212.         for item in other.items:
  213.             if item not in self.items:
  214.                 return False
  215.         
  216.         return True
  217.  
  218.  
  219.