-class ParamsValidator(UnicodeStringValidator):
- def to_python(self, value, state):
- if isinstance(value, basestring) or value is None:
- value = super(ParamsValidator, self).to_python(value, state)
- try:
- value = params_to_list(value)
- except ParseError, e:
- raise Invalid("invalid parameters in the ParamsCol '%s', parse "
- "error: %s" % (self.name, e), value, state)
- elif not isinstance(value, (list, tuple)):
- raise Invalid("expected a tuple, list or valid string in the "
- "ParamsCol '%s', got %s %r instead"
- % (self.name, type(value), value), value, state)
- return value
- def from_python(self, value, state):
- if isinstance(value, (list, tuple)):
- value = ' '.join([repr(p) for p in value])
- elif isinstance(value, basestring) or value is None:
- value = super(ParamsValidator, self).to_python(value, state)
- try:
- params_to_list(value)
- except ParseError, e:
- raise Invalid("invalid parameters in the ParamsCol '%s', parse "
- "error: %s" % (self.name, e), value, state)
- else:
- raise Invalid("expected a tuple, list or valid string in the "
- "ParamsCol '%s', got %s %r instead"
- % (self.name, type(value), value), value, state)
- return value
-
-class SOParamsCol(SOUnicodeCol):
- def createValidators(self):
- return [ParamsValidator(db_encoding=self.dbEncoding, name=self.name)]
-
-class ParamsCol(UnicodeCol):
- baseClass = SOParamsCol
-