Package fabmetheus_utilities :: Package geometry :: Package geometry_utilities :: Package evaluate_enumerables :: Module list_attribute
[hide private]
[frames] | no frames]

Source Code for Module fabmetheus_utilities.geometry.geometry_utilities.evaluate_enumerables.list_attribute

  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   
15 -def _getAccessibleAttribute(attributeName, listObject):
16 'Get the accessible attribute.' 17 if attributeName in globalNativeFunctionSet: 18 return getattr(listObject, attributeName, None) 19 if attributeName in globalGetAccessibleAttributeSet: 20 stringAttribute = ListAttribute(listObject) 21 return getattr(stringAttribute, attributeName, None) 22 return None
23 24
25 -class ListAttribute:
26 'Class to handle a list.'
27 - def __init__(self, listObject):
28 'Initialize.' 29 self.listObject = listObject
30
31 - def __repr__(self):
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
39 - def copy(self):
40 'Get the copy.' 41 return self.listObject[:]
42
43 - def delete(self, arguments):
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
56 - def getExpansion(self, items):
57 'Get the concatenated copies.' 58 expansion = [] 59 for itemIndex in xrange(items): 60 expansion += self.listObject[:] 61 return expansion
62
63 - def getIsIn(self, value):
64 'Determine if the value is in.' 65 return value in self.listObject
66
67 - def getIsNotIn(self, value):
68 'Determine if the value is in.' 69 return not(value in self.listObject)
70
71 - def getLength(self):
72 'Get the length.' 73 return len(self.listObject)
74
75 - def getMax(self):
76 'Get the max.' 77 return max(self.listObject)
78
79 - def getMin(self):
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
90 - def keys(self):
91 'Get the keys.' 92 return range(len(self.listObject))
93
94 - def length(self):
95 'Get the length.' 96 return len(self.listObject)
97
98 - def rindex(self, value):
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