Reimplemented CommaSeparatedStringType in an extensible manner.

This commit is contained in:
Jeremy Fincher 2004-01-21 16:15:31 +00:00
parent 4b8df598a9
commit b2b9f64558

View File

@ -189,13 +189,34 @@ class StringSurroundedBySpaces(String):
v += ' ' v += ' '
self.value = v self.value = v
class CommaSeparatedListOfStrings(String): class SeparatedListOf(Value):
Value = Value
def splitter(self, s):
"""Override this with a function that takes a string and returns a list
of strings."""
raise NotImplementedError
def joiner(self, L):
"""Override this to join the internal list for output."""
raise NotImplementedError
def set(self, s): def set(self, s):
String.set(self, s) L = self.splitter(s)
self.setValue(map(str.strip, re.split(r'\s*,\s*', self.value))) for (i, s) in enumerate(L):
v = self.Value(s, 'help does not matter here')
L[i] = v()
self.setValue(L)
def __str__(self): def __str__(self):
return ','.join(self.value) return self.joiner(self.value)
class CommaSeparatedListOfStrings(SeparatedListOf):
Value = String
def splitter(self, s):
return re.split(r'\s*,\s*', s)
def joiner(self, L):
return ','.join(L)
class CommaSeparatedSetOfStrings(CommaSeparatedListOfStrings): class CommaSeparatedSetOfStrings(CommaSeparatedListOfStrings):
def setValue(self, v): def setValue(self, v):