home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Lib / UserList.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  5.6 KB  |  131 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4.  
  5. class UserList:
  6.     
  7.     def __init__(self, list = None):
  8.         self.data = []
  9.         if list is not None:
  10.             if type(list) == type(self.data):
  11.                 self.data[:] = list
  12.             else:
  13.                 self.data[:] = list.data[:]
  14.         
  15.  
  16.     
  17.     def __repr__(self):
  18.         return repr(self.data)
  19.  
  20.     
  21.     def __cmp__(self, other):
  22.         if isinstance(other, UserList):
  23.             return cmp(self.data, other.data)
  24.         else:
  25.             return cmp(self.data, other)
  26.  
  27.     
  28.     def __len__(self):
  29.         return len(self.data)
  30.  
  31.     
  32.     def __getitem__(self, i):
  33.         return self.data[i]
  34.  
  35.     
  36.     def __setitem__(self, i, item):
  37.         self.data[i] = item
  38.  
  39.     
  40.     def __delitem__(self, i):
  41.         del self.data[i]
  42.  
  43.     
  44.     def __getslice__(self, i, j):
  45.         i = max(i, 0)
  46.         j = max(j, 0)
  47.         userlist = self.__class__()
  48.         userlist.data[:] = self.data[i:j]
  49.         return userlist
  50.  
  51.     
  52.     def __setslice__(self, i, j, other):
  53.         i = max(i, 0)
  54.         j = max(j, 0)
  55.         if isinstance(other, UserList):
  56.             self.data[i:j] = other.data
  57.         elif isinstance(other, type(self.data)):
  58.             self.data[i:j] = other
  59.         else:
  60.             self.data[i:j] = list(other)
  61.  
  62.     
  63.     def __delslice__(self, i, j):
  64.         i = max(i, 0)
  65.         j = max(j, 0)
  66.         del self.data[i:j]
  67.  
  68.     
  69.     def __add__(self, other):
  70.         if isinstance(other, UserList):
  71.             return self.__class__(self.data + other.data)
  72.         elif isinstance(other, type(self.data)):
  73.             return self.__class__(self.data + other)
  74.         else:
  75.             return self.__class__(self.data + list(other))
  76.  
  77.     
  78.     def __radd__(self, other):
  79.         if isinstance(other, UserList):
  80.             return self.__class__(other.data + self.data)
  81.         elif isinstance(other, type(self.data)):
  82.             return self.__class__(other + self.data)
  83.         else:
  84.             return self.__class__(list(other) + self.data)
  85.  
  86.     
  87.     def __mul__(self, n):
  88.         return self.__class__(self.data * n)
  89.  
  90.     __rmul__ = __mul__
  91.     
  92.     def append(self, item):
  93.         self.data.append(item)
  94.  
  95.     
  96.     def insert(self, i, item):
  97.         self.data.insert(i, item)
  98.  
  99.     
  100.     def pop(self, i = -1):
  101.         return self.data.pop(i)
  102.  
  103.     
  104.     def remove(self, item):
  105.         self.data.remove(item)
  106.  
  107.     
  108.     def count(self, item):
  109.         return self.data.count(item)
  110.  
  111.     
  112.     def index(self, item):
  113.         return self.data.index(item)
  114.  
  115.     
  116.     def reverse(self):
  117.         self.data.reverse()
  118.  
  119.     
  120.     def sort(self, *args):
  121.         apply(self.data.sort, args)
  122.  
  123.     
  124.     def extend(self, other):
  125.         if isinstance(other, UserList):
  126.             self.data.extend(other.data)
  127.         else:
  128.             self.data.extend(other)
  129.  
  130.  
  131.