2 List object attributes.
6 from __future__ import absolute_import
8 from fabmetheus_utilities import euclidean
11 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
12 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
13 __date__ = '$Date: 2008/02/05 $'
14 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
17 def _getAccessibleAttribute(attributeName, listObject):
18 'Get the accessible attribute.'
19 if attributeName in globalNativeFunctionSet:
20 return getattr(listObject, attributeName, None)
21 if attributeName in globalGetAccessibleAttributeSet:
22 stringAttribute = ListAttribute(listObject)
23 return getattr(stringAttribute, attributeName, None)
28 'Class to handle a list.'
29 def __init__(self, listObject):
31 self.listObject = listObject
34 "Get the list representation of this ListAttribute."
35 return str(self.listObject)
38 'Get the concatenation, same as append.'
39 return self.listObject + [value]
43 return self.listObject[:]
45 def delete(self, arguments):
46 'Get the delete list.'
48 enumeratorSet = set(euclidean.getEnumeratorKeysAlwaysList(self.listObject, arguments))
49 for elementIndex, element in enumerate(self.listObject):
50 if elementIndex not in enumeratorSet:
51 deleteList.append(element)
54 def get(self, itemIndex):
56 return self.listObject[itemIndex]
58 def getExpansion(self, items):
59 'Get the concatenated copies.'
61 for itemIndex in xrange(items):
62 expansion += self.listObject[:]
65 def getIsIn(self, value):
66 'Determine if the value is in.'
67 return value in self.listObject
69 def getIsNotIn(self, value):
70 'Determine if the value is in.'
71 return not(value in self.listObject)
75 return len(self.listObject)
79 return max(self.listObject)
83 return min(self.listObject)
85 def insert(self, insertIndex, value):
86 'Get the insert list.'
88 insertIndex += len(self.listObject)
89 insertIndex = max(0, insertIndex)
90 return self.listObject[: insertIndex] + [value] + self.listObject[insertIndex :]
94 return range(len(self.listObject))
98 return len(self.listObject)
100 def rindex(self, value):
101 'Get the rindex element.'
102 for elementIndex, element in enumerate(self.listObject):
105 raise ValueError('Value (%s) not found in rindex in ListAttribute for (%s).' % (value, self.listObject))
107 def set(self, itemIndex, value):
109 self.listObject[itemIndex] = value
110 return self.listObject
112 def values(self, arguments=None):
114 return self.listObject
117 globalAccessibleAttributeDictionary = 'add copy count delete get getExpansion getIsIn getIsNotIn getLength getMax getMin'.split()
118 globalAccessibleAttributeDictionary += 'insert keys length rindex set values'.split()
119 globalGetAccessibleAttributeSet = set(globalAccessibleAttributeDictionary)
120 globalNativeFunctions = 'append extend index pop remove reverse sort'.split()
121 globalNativeFunctionSet = set(globalNativeFunctions)