2 List object attributes.
6 from __future__ import absolute_import
7 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
10 from fabmetheus_utilities import euclidean
13 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
14 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
15 __date__ = '$Date: 2008/02/05 $'
16 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
19 def _getAccessibleAttribute(attributeName, listObject):
20 'Get the accessible attribute.'
21 if attributeName in globalNativeFunctionSet:
22 return getattr(listObject, attributeName, None)
23 if attributeName in globalGetAccessibleAttributeSet:
24 stringAttribute = ListAttribute(listObject)
25 return getattr(stringAttribute, attributeName, None)
30 'Class to handle a list.'
31 def __init__(self, listObject):
33 self.listObject = listObject
36 "Get the list representation of this ListAttribute."
37 return str(self.listObject)
40 'Get the concatenation, same as append.'
41 return self.listObject + [value]
45 return self.listObject[:]
47 def delete(self, arguments):
48 'Get the delete list.'
50 enumeratorSet = set(euclidean.getEnumeratorKeysAlwaysList(self.listObject, arguments))
51 for elementIndex, element in enumerate(self.listObject):
52 if elementIndex not in enumeratorSet:
53 deleteList.append(element)
56 def get(self, itemIndex):
58 return self.listObject[itemIndex]
60 def getExpansion(self, items):
61 'Get the concatenated copies.'
63 for itemIndex in xrange(items):
64 expansion += self.listObject[:]
67 def getIsIn(self, value):
68 'Determine if the value is in.'
69 return value in self.listObject
71 def getIsNotIn(self, value):
72 'Determine if the value is in.'
73 return not(value in self.listObject)
77 return len(self.listObject)
81 return max(self.listObject)
85 return min(self.listObject)
87 def insert(self, insertIndex, value):
88 'Get the insert list.'
90 insertIndex += len(self.listObject)
91 insertIndex = max(0, insertIndex)
92 return self.listObject[: insertIndex] + [value] + self.listObject[insertIndex :]
96 return range(len(self.listObject))
100 return len(self.listObject)
102 def rindex(self, value):
103 'Get the rindex element.'
104 for elementIndex, element in enumerate(self.listObject):
107 raise ValueError('Value (%s) not found in rindex in ListAttribute for (%s).' % (value, self.listObject))
109 def set(self, itemIndex, value):
111 self.listObject[itemIndex] = value
112 return self.listObject
114 def values(self, arguments=None):
116 return self.listObject
119 globalAccessibleAttributeDictionary = 'add copy count delete get getExpansion getIsIn getIsNotIn getLength getMax getMin'.split()
120 globalAccessibleAttributeDictionary += 'insert keys length rindex set values'.split()
121 globalGetAccessibleAttributeSet = set(globalAccessibleAttributeDictionary)
122 globalNativeFunctions = 'append extend index pop remove reverse sort'.split()
123 globalNativeFunctionSet = set(globalNativeFunctions)