1 """
2 List object attributes.
3
4 """
5
6 from fabmetheus_utilities import euclidean
7
8
9 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
10 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
11 __date__ = '$Date: 2008/02/05 $'
12 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
13
14
23
24
26 'Class to handle a list.'
28 'Initialize.'
29 self.listObject = listObject
30
32 "Get the list representation of this ListAttribute."
33 return str(self.listObject)
34
35 - def add(self, value):
36 'Get the concatenation, same as append.'
37 return self.listObject + [value]
38
40 'Get the copy.'
41 return self.listObject[:]
42
44 'Get the delete list.'
45 deleteList = []
46 enumeratorSet = set(euclidean.getEnumeratorKeysAlwaysList(self.listObject, arguments))
47 for elementIndex, element in enumerate(self.listObject):
48 if elementIndex not in enumeratorSet:
49 deleteList.append(element)
50 return deleteList
51
52 - def get(self, itemIndex):
53 'Get value by index'
54 return self.listObject[itemIndex]
55
57 'Get the concatenated copies.'
58 expansion = []
59 for itemIndex in xrange(items):
60 expansion += self.listObject[:]
61 return expansion
62
64 'Determine if the value is in.'
65 return value in self.listObject
66
68 'Determine if the value is in.'
69 return not(value in self.listObject)
70
72 'Get the length.'
73 return len(self.listObject)
74
76 'Get the max.'
77 return max(self.listObject)
78
80 'Get the min.'
81 return min(self.listObject)
82
83 - def insert(self, insertIndex, value):
84 'Get the insert list.'
85 if insertIndex < 0:
86 insertIndex += len(self.listObject)
87 insertIndex = max(0, insertIndex)
88 return self.listObject[: insertIndex] + [value] + self.listObject[insertIndex :]
89
91 'Get the keys.'
92 return range(len(self.listObject))
93
95 'Get the length.'
96 return len(self.listObject)
97
99 'Get the rindex element.'
100 for elementIndex, element in enumerate(self.listObject):
101 if element == value:
102 return elementIndex
103 raise ValueError('Value (%s) not found in rindex in ListAttribute for (%s).' % (value, self.listObject))
104
105 - def set(self, itemIndex, value):
106 'Set value.'
107 self.listObject[itemIndex] = value
108 return self.listObject
109
110 - def values(self, arguments=None):
111 'Get the values.'
112 return self.listObject
113
114
115 globalAccessibleAttributes = 'add copy count delete get getExpansion getIsIn getIsNotIn getLength getMax getMin'.split()
116 globalAccessibleAttributes += 'insert keys length rindex set values'.split()
117 globalGetAccessibleAttributeSet = set(globalAccessibleAttributes)
118 globalNativeFunctions = 'append extend index pop remove reverse sort'.split()
119 globalNativeFunctionSet = set(globalNativeFunctions)
120