From b2b9f6455856eeb535d1ec609784e646cd1d581a Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 21 Jan 2004 16:15:31 +0000 Subject: [PATCH] Reimplemented CommaSeparatedStringType in an extensible manner. --- src/registry.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/registry.py b/src/registry.py index fed9c9c9b..a0910a1a1 100644 --- a/src/registry.py +++ b/src/registry.py @@ -189,14 +189,35 @@ class StringSurroundedBySpaces(String): 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): - String.set(self, s) - self.setValue(map(str.strip, re.split(r'\s*,\s*', self.value))) + L = self.splitter(s) + for (i, s) in enumerate(L): + v = self.Value(s, 'help does not matter here') + L[i] = v() + self.setValue(L) 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): def setValue(self, v): self.value = sets.Set(v)