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

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

  1  """ 
  2  String 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, stringObject):
16 'Get the accessible attribute.' 17 if attributeName in globalNativeFunctionSet: 18 return getattr(stringObject, attributeName, None) 19 if attributeName in globalGetAccessibleAttributeSet: 20 stringAttribute = StringAttribute(stringObject) 21 return getattr(stringAttribute, attributeName, None) 22 return None
23 24
25 -class StringAttribute:
26 'Class to handle a string.'
27 - def __init__(self, stringObject):
28 'Initialize.' 29 self.stringObject = stringObject
30
31 - def __repr__(self):
32 "Get the string representation of this StringAttribute." 33 return self.stringObject
34
35 - def add(self, nextString):
36 'Get the add string, same as append.' 37 return self.stringObject + nextString
38
39 - def append(self, nextString):
40 'Get the append string.' 41 return self.stringObject + nextString
42
43 - def copy(self):
44 'Get the copy.' 45 return self.stringObject[:]
46
47 - def delete(self, arguments):
48 'Get the delete string.' 49 deleteString = '' 50 enumeratorSet = set(euclidean.getEnumeratorKeysAlwaysList(self.stringObject, arguments)) 51 for characterIndex, character in enumerate(self.stringObject): 52 if characterIndex not in enumeratorSet: 53 deleteString += character 54 return deleteString
55
56 - def get(self, itemIndex):
57 'Get value by characterIndex' 58 return self.stringObject[itemIndex]
59
60 - def getExpansion(self, items):
61 'Get the concatenated copies.' 62 expansion = '' 63 for itemIndex in xrange(items): 64 expansion += self.stringObject 65 return expansion
66
67 - def getIsIn(self, value):
68 'Determine if the value is in.' 69 return value in self.stringObject
70
71 - def getIsNotIn(self, value):
72 'Determine if the value is in.' 73 return not(value in self.stringObject)
74
75 - def getLength(self):
76 'Get the length.' 77 return len(self.stringObject)
78
79 - def getMax(self):
80 'Get the max.' 81 return max(self.stringObject)
82
83 - def getMin(self):
84 'Get the min.' 85 return min(self.stringObject)
86
87 - def insert(self, insertIndex, value):
88 'Get the insert string.' 89 if insertIndex < 0: 90 insertIndex += len(self.stringObject) 91 insertIndex = max(0, insertIndex) 92 return self.stringObject[: insertIndex] + value + self.stringObject[insertIndex :]
93
94 - def keys(self):
95 'Get the keys.' 96 return range(len(self.stringObject))
97
98 - def length(self):
99 'Get the length.' 100 return len(self.stringObject)
101
102 - def remove(self, value):
103 'Get the remove string.' 104 removeIndex = self.stringObject.find(value) 105 if removeIndex > -1: 106 return self.stringObject[: removeIndex] + self.stringObject[removeIndex + len(value) :] 107 return self.stringObject
108
109 - def reverse(self):
110 'Get the reverse string.' 111 return self.stringObject[: : -1]
112
113 - def set(self, itemIndex, value):
114 'Set value.' 115 self.stringObject[itemIndex] = value 116 return self.stringObject
117
118 - def values(self):
119 'Get the values.' 120 values = [] 121 for character in self.stringObject: 122 values.append(character) 123 return values
124 125 126 globalAccessibleAttributes = 'add append copy delete get getExpansion getIsIn getIsNotIn getLength getMax getMin'.split() 127 globalAccessibleAttributes += 'insert keys length remove reverse set values'.split() 128 globalGetAccessibleAttributeSet = set(globalAccessibleAttributes) 129 globalNativeFunctions = 'capitalize center count decode encode endswith expandtabs find format index isalnum join'.split() 130 globalNativeFunctions += 'isalpha isdigit islower isspace istitle isupper ljust lower lstrip partition replace rfind rindex'.split() 131 globalNativeFunctions += 'rjust rpartition rsplit rstrip split splitlines startswith strip swapcase title translate upper zfill'.split() 132 globalNativeFunctionSet = set(globalNativeFunctions) 133