Back to index

plone3  3.1.7
DynaList.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 ## GroupUserFolder
00003 ## Copyright (C)2006 Ingeniweb
00004 
00005 ## This program is free software; you can redistribute it and/or modify
00006 ## it under the terms of the GNU General Public License as published by
00007 ## the Free Software Foundation; either version 2 of the License, or
00008 ## (at your option) any later version.
00009 
00010 ## This program is distributed in the hope that it will be useful,
00011 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ## GNU General Public License for more details.
00014 
00015 ## You should have received a copy of the GNU General Public License
00016 ## along with this program; see the file COPYING. If not, write to the
00017 ## Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 """
00019 DynaList.py => a list that has dynamic data (ie. calculated by a 'data' method).
00020 Please override this class and define a data(self,) method that will return the actual list.
00021 """
00022 __version__ = "$Revision:  $"
00023 # $Source:  $
00024 # $Id: DynaList.py 30098 2006-09-08 12:35:01Z encolpe $
00025 __docformat__ = 'restructuredtext'
00026 
00027 class DynaList:
00028     def __init__(self, initlist=None):
00029         pass
00030 
00031     def __repr__(self): return repr(self.data())
00032     def __lt__(self, other): return self.data() <  self.__cast(other)
00033     def __le__(self, other): return self.data() <= self.__cast(other)
00034     def __eq__(self, other): return self.data() == self.__cast(other)
00035     def __ne__(self, other): return self.data() != self.__cast(other)
00036     def __gt__(self, other): return self.data() >  self.__cast(other)
00037     def __ge__(self, other): return self.data() >= self.__cast(other)
00038     def __cast(self, other):
00039         if isinstance(other, UserList): return other.data()
00040         else: return other
00041     def __cmp__(self, other):
00042         raise RuntimeError, "UserList.__cmp__() is obsolete"
00043     def __contains__(self, item): return item in self.data()
00044     def __len__(self): return len(self.data())
00045     def __getitem__(self, i): return self.data()[i]
00046     def __setitem__(self, i, item): self.data()[i] = item
00047     def __delitem__(self, i): del self.data()[i]
00048     def __getslice__(self, i, j):
00049         i = max(i, 0); j = max(j, 0)
00050         return self.__class__(self.data()[i:j])
00051     def __setslice__(self, i, j, other):
00052         i = max(i, 0); j = max(j, 0)
00053         if isinstance(other, UserList):
00054             self.data()[i:j] = other.data()
00055         elif isinstance(other, type(self.data())):
00056             self.data()[i:j] = other
00057         else:
00058             self.data()[i:j] = list(other)
00059     def __delslice__(self, i, j):
00060         i = max(i, 0); j = max(j, 0)
00061         del self.data()[i:j]
00062     def __add__(self, other):
00063         if isinstance(other, UserList):
00064             return self.__class__(self.data() + other.data())
00065         elif isinstance(other, type(self.data())):
00066             return self.__class__(self.data() + other)
00067         else:
00068             return self.__class__(self.data() + list(other))
00069     def __radd__(self, other):
00070         if isinstance(other, UserList):
00071             return self.__class__(other.data() + self.data())
00072         elif isinstance(other, type(self.data())):
00073             return self.__class__(other + self.data())
00074         else:
00075             return self.__class__(list(other) + self.data())
00076     def __iadd__(self, other):
00077         raise NotImplementedError, "Not implemented"
00078 
00079     def __mul__(self, n):
00080         return self.__class__(self.data()*n)
00081     __rmul__ = __mul__
00082     def __imul__(self, n):
00083         raise NotImplementedError, "Not implemented"
00084     def append(self, item): self.data().append(item)
00085     def insert(self, i, item): self.data().insert(i, item)
00086     def pop(self, i=-1): return self.data().pop(i)
00087     def remove(self, item): self.data().remove(item)
00088     def count(self, item): return self.data().count(item)
00089     def index(self, item): return self.data().index(item)
00090     def reverse(self): self.data().reverse()
00091     def sort(self, *args): apply(self.data().sort, args)
00092     def extend(self, other):
00093         if isinstance(other, UserList):
00094             self.data().extend(other.data())
00095         else:
00096             self.data().extend(other)