mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 04:02:46 +01:00
Reimplemented CommaSeparatedStringType in an extensible manner.
This commit is contained in:
parent
4b8df598a9
commit
b2b9f64558
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user