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
22
23
25 'Class to handle a dictionary.'
27 'Initialize.'
28 self.dictionaryObject = dictionaryObject
29
31 "Get the dictionary representation of this DictionaryAttribute."
32 return str(self.dictionaryObject)
33
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
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
58 'Determine if the value is in.'
59 return value in self.dictionaryObject
60
62 'Determine if the value is in.'
63 return not(value in self.dictionaryObject)
64
66 'Get the length.'
67 return len(self.dictionaryObject)
68
70 'Get the max.'
71 return max(self.dictionaryObject)
72
74 'Get the min.'
75 return min(self.dictionaryObject)
76
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
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