2 String object attributes.
6 from __future__ import absolute_import
7 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
10 from fabmetheus_utilities import euclidean
13 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
14 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
15 __date__ = '$Date: 2008/02/05 $'
16 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
19 def _getAccessibleAttribute(attributeName, stringObject):
20 'Get the accessible attribute.'
21 if attributeName in globalNativeFunctionSet:
22 return getattr(stringObject, attributeName, None)
23 if attributeName in globalGetAccessibleAttributeSet:
24 stringAttribute = StringAttribute(stringObject)
25 return getattr(stringAttribute, attributeName, None)
29 class StringAttribute:
30 'Class to handle a string.'
31 def __init__(self, stringObject):
33 self.stringObject = stringObject
36 "Get the string representation of this StringAttribute."
37 return self.stringObject
39 def add(self, nextString):
40 'Get the add string, same as append.'
41 return self.stringObject + nextString
43 def append(self, nextString):
44 'Get the append string.'
45 return self.stringObject + nextString
49 return self.stringObject[:]
51 def delete(self, arguments):
52 'Get the delete string.'
54 enumeratorSet = set(euclidean.getEnumeratorKeysAlwaysList(self.stringObject, arguments))
55 for characterIndex, character in enumerate(self.stringObject):
56 if characterIndex not in enumeratorSet:
57 deleteString += character
60 def get(self, itemIndex):
61 'Get value by characterIndex'
62 return self.stringObject[itemIndex]
64 def getExpansion(self, items):
65 'Get the concatenated copies.'
67 for itemIndex in xrange(items):
68 expansion += self.stringObject
71 def getIsIn(self, value):
72 'Determine if the value is in.'
73 return value in self.stringObject
75 def getIsNotIn(self, value):
76 'Determine if the value is in.'
77 return not(value in self.stringObject)
81 return len(self.stringObject)
85 return max(self.stringObject)
89 return min(self.stringObject)
91 def insert(self, insertIndex, value):
92 'Get the insert string.'
94 insertIndex += len(self.stringObject)
95 insertIndex = max(0, insertIndex)
96 return self.stringObject[: insertIndex] + value + self.stringObject[insertIndex :]
100 return range(len(self.stringObject))
104 return len(self.stringObject)
106 def remove(self, value):
107 'Get the remove string.'
108 removeIndex = self.stringObject.find(value)
110 return self.stringObject[: removeIndex] + self.stringObject[removeIndex + len(value) :]
111 return self.stringObject
114 'Get the reverse string.'
115 return self.stringObject[: : -1]
117 def set(self, itemIndex, value):
119 self.stringObject[itemIndex] = value
120 return self.stringObject
125 for character in self.stringObject:
126 values.append(character)
130 globalAccessibleAttributeDictionary = 'add append copy delete get getExpansion getIsIn getIsNotIn getLength getMax getMin'.split()
131 globalAccessibleAttributeDictionary += 'insert keys length remove reverse set values'.split()
132 globalGetAccessibleAttributeSet = set(globalAccessibleAttributeDictionary)
133 globalNativeFunctions = 'capitalize center count decode encode endswith expandtabs find format index isalnum join'.split()
134 globalNativeFunctions += 'isalpha isdigit islower isspace istitle isupper ljust lower lstrip partition replace rfind rindex'.split()
135 globalNativeFunctions += 'rjust rpartition rsplit rstrip split splitlines startswith strip swapcase title translate upper zfill'.split()
136 globalNativeFunctionSet = set(globalNativeFunctions)