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

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

 1  """ 
 2  Dictionary object attributes. 
 3  """ 
 4   
 5  from fabmetheus_utilities import euclidean 
 6   
 7   
 8  __author__ = 'Enrique Perez (perez_enrique@yahoo.com)' 
 9  __credits__ = 'Art of Illusion <http://www.artofillusion.org/>' 
10  __date__ = '$Date: 2008/02/05 $' 
11  __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' 
12   
13   
14 -def _getAccessibleAttribute(attributeName, dictionaryObject):
15 'Get the accessible attribute.' 16 if attributeName in globalNativeFunctionSet: 17 return getattr(dictionaryObject, attributeName, None) 18 if attributeName in globalGetAccessibleAttributeSet: 19 stringAttribute = DictionaryAttribute(dictionaryObject) 20 return getattr(stringAttribute, attributeName, None) 21 return None
22 23
24 -class DictionaryAttribute:
25 'Class to handle a dictionary.'
26 - def __init__(self, dictionaryObject):
27 'Initialize.' 28 self.dictionaryObject = dictionaryObject
29
30 - def __repr__(self):
31 "Get the dictionary representation of this DictionaryAttribute." 32 return str(self.dictionaryObject)
33
34 - def count(self, value):
35 'Get the count.' 36 countTotal = 0 37 for key, iteratorValue in self.dictionaryObject.iteritems(): 38 if iteratorValue == value: 39 countTotal += 1 40 return countTotal
41
42 - def delete(self, arguments):
43 'Get the delete dictionary.' 44 if arguments.__class__ != list: 45 del self.dictionaryObject[arguments] 46 return self.dictionaryObject 47 if len(arguments) == 0: 48 self.dictionaryObject.clear() 49 return self.dictionaryObject 50 if len(arguments) == 1: 51 del self.dictionaryObject[arguments[0]] 52 return self.dictionaryObject 53 for enumeratorKey in euclidean.getEnumeratorKeysAlwaysList(self.dictionaryObject, arguments): 54 del self.dictionaryObject[enumeratorKey] 55 return self.dictionaryObject
56
57 - def getIsIn(self, value):
58 'Determine if the value is in.' 59 return value in self.dictionaryObject
60
61 - def getIsNotIn(self, value):
62 'Determine if the value is in.' 63 return not(value in self.dictionaryObject)
64
65 - def getLength(self):
66 'Get the length.' 67 return len(self.dictionaryObject)
68
69 - def getMax(self):
70 'Get the max.' 71 return max(self.dictionaryObject)
72
73 - def getMin(self):
74 'Get the min.' 75 return min(self.dictionaryObject)
76
77 - def index(self, value):
78 'Get the index element.' 79 for key, iteratorValue in self.dictionaryObject.iteritems(): 80 if iteratorValue == value: 81 return key 82 raise ValueError('Value (%s) not found in index in DictionaryAttribute for (%s).' % (value, self.dictionaryObject))
83
84 - def length(self):
85 'Get the length.' 86 return len(self.dictionaryObject)
87
88 - def set(self, itemIndex, value):
89 'Set value.' 90 self.dictionaryObject[itemIndex] = value 91 return self.dictionaryObject
92 93 94 globalAccessibleAttributes = 'count delete getIsIn getIsNotIn getLength getMax getMin index length set'.split() 95 globalGetAccessibleAttributeSet = set(globalAccessibleAttributes) 96 globalNativeFunctions = 'clear copy fromkeys get items keys pop popitem remove setdefault update values'.split() 97 globalNativeFunctionSet = set(globalNativeFunctions) 98