2 String object attributes.
6 from __future__ import absolute_import
8 from fabmetheus_utilities import euclidean
11 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
12 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
13 __date__ = '$Date: 2008/02/05 $'
14 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
17 def _getAccessibleAttribute(attributeName, stringObject):
18 'Get the accessible attribute.'
19 if attributeName in globalNativeFunctionSet:
20 return getattr(stringObject, attributeName, None)
21 if attributeName in globalGetAccessibleAttributeSet:
22 stringAttribute = StringAttribute(stringObject)
23 return getattr(stringAttribute, attributeName, None)
27 class StringAttribute(object):
28 'Class to handle a string.'
29 def __init__(self, stringObject):
31 self.stringObject = stringObject
34 "Get the string representation of this StringAttribute."
35 return self.stringObject
37 def add(self, nextString):
38 'Get the add string, same as append.'
39 return self.stringObject + nextString
41 def append(self, nextString):
42 'Get the append string.'
43 return self.stringObject + nextString
47 return self.stringObject[:]
49 def delete(self, arguments):
50 'Get the delete string.'
52 enumeratorSet = set(euclidean.getEnumeratorKeysAlwaysList(self.stringObject, arguments))
53 for characterIndex, character in enumerate(self.stringObject):
54 if characterIndex not in enumeratorSet:
55 deleteString += character
58 def get(self, itemIndex):
59 'Get value by characterIndex'
60 return self.stringObject[itemIndex]
62 def getExpansion(self, items):
63 'Get the concatenated copies.'
65 for itemIndex in xrange(items):
66 expansion += self.stringObject
69 def getIsIn(self, value):
70 'Determine if the value is in.'
71 return value in self.stringObject
73 def getIsNotIn(self, value):
74 'Determine if the value is in.'
75 return not(value in self.stringObject)
79 return len(self.stringObject)
83 return max(self.stringObject)
87 return min(self.stringObject)
89 def insert(self, insertIndex, value):
90 'Get the insert string.'
92 insertIndex += len(self.stringObject)
93 insertIndex = max(0, insertIndex)
94 return self.stringObject[: insertIndex] + value + self.stringObject[insertIndex :]
98 return range(len(self.stringObject))
102 return len(self.stringObject)
104 def remove(self, value):
105 'Get the remove string.'
106 removeIndex = self.stringObject.find(value)
108 return self.stringObject[: removeIndex] + self.stringObject[removeIndex + len(value) :]
109 return self.stringObject
112 'Get the reverse string.'
113 return self.stringObject[: : -1]
115 def set(self, itemIndex, value):
117 self.stringObject[itemIndex] = value
118 return self.stringObject
123 for character in self.stringObject:
124 values.append(character)
128 globalAccessibleAttributeDictionary = 'add append copy delete get getExpansion getIsIn getIsNotIn getLength getMax getMin'.split()
129 globalAccessibleAttributeDictionary += 'insert keys length remove reverse set values'.split()
130 globalGetAccessibleAttributeSet = set(globalAccessibleAttributeDictionary)
131 globalNativeFunctions = 'capitalize center count decode encode endswith expandtabs find format index isalnum join'.split()
132 globalNativeFunctions += 'isalpha isdigit islower isspace istitle isupper ljust lower lstrip partition replace rfind rindex'.split()
133 globalNativeFunctions += 'rjust rpartition rsplit rstrip split splitlines startswith strip swapcase title translate upper zfill'.split()
134 globalNativeFunctionSet = set(globalNativeFunctions)