1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """Validator base class for validating strings."""
17
18 from muntjac.data.validators.abstract_validator import AbstractValidator
19
20
22 """Validator base class for validating strings. See L{AbstractValidator}
23 for more information.
24
25 To include the value that failed validation in the exception message you
26 can use "{0}" in the error message. This will be replaced with the failed
27 value (converted to string using L{__str__}) or "None" if the value is
28 C{None}.
29
30 @author: Vaadin Ltd.
31 @author: Richard Lincoln
32 @version: 1.1.2
33 """
34
36 """Constructs a validator for strings.
37
38 None and empty string values are always accepted. To reject empty
39 values, set the field being validated as required.
40
41 @param errorMessage:
42 the message to be included in an L{InvalidValueException}
43 (with "{0}" replaced by the value that failed validation).
44 """
45 super(AbstractStringValidator, self).__init__(errorMessage)
46
47
49 """Tests if the given value is a valid string.
50
51 None values are always accepted. Values that are not strings are
52 converted using L{__str__}. Then L{isValidString} is used to validate
53 the value.
54
55 @param value:
56 the value to check
57 @return: true if the value (or its __str__) is a valid string, false
58 otherwise
59 """
60 if value is None:
61 return True
62
63 if not isinstance(value, str):
64 value = str(value)
65
66 return self.isValidString(value)
67
68
70 """Checks if the given string is valid.
71
72 @param value:
73 String to check. Can never be None.
74 @return: true if the string is valid, false otherwise
75 """
76 pass
77