def parseDate(self, value):
     try:
         y, m, d = [int(p) for p in value.split('-')]
     except ValueError:
         raise validation.FieldValidationError('Invalid date')
     try:
         value = date(y, m, d)
     except ValueError, e:
         raise validation.FieldValidationError('Invalid date: ' + str(e))
 def toType(self, value):
     if value is None:
         return None
     try:
         value = date(*value)
     except (TypeError, ValueError), e:
         raise validation.FieldValidationError('Invalid date: ' + str(e))
 def toType(self, value):
     if value is not None:
         value = value.strip()
     if not value:
         return None
     if value not in ('True', 'False'):
         raise validation.FieldValidationError(
             '%r should be either True or False' % value)
     return value == 'True'
 def toType(self, value):
     if value is not None:
         value = value.strip()
     if not value:
         return None
     # "Cast" the value to the correct type. For some strange reason,
     # Python's decimal.Decimal type raises an ArithmeticError when it's
     # given a dodgy value.
     try:
         value = self.cast(value)
     except (ValueError, ArithmeticError):
         raise validation.FieldValidationError("Not a valid number")
     return value
    def parseTime(self, value):

        if '.' in value:
            value, ms = value.split('.')
        else:
            ms = 0

        try:
            parts = value.split(':')
            if len(parts) < 2 or len(parts) > 3:
                raise ValueError()
            if len(parts) == 2:
                h, m = parts
                s = 0
            else:
                h, m, s = parts
            h, m, s, ms = int(h), int(m), int(s), int(ms)
        except:
            raise validation.FieldValidationError('Invalid time')

        try:
            value = time(h, m, s, ms)
        except ValueError, e:
            raise validation.FieldValidationError('Invalid time: ' + str(e))