String

Converts things to string, but treats empty things as the empty string.

Also takes a max and min argument, and the string length must fall in that range.

Also you may give an encoding argument, which will encode any unicode that is found. Lists and tuples are joined with list_joiner (default ', ') in from_python.

>>> String(min=2).to_python('a')
Traceback (most recent call last):
    ...
Invalid: Enter a value 2 characters long or more
>>> String(max=10).to_python('xxxxxxxxxxx')
Traceback (most recent call last):
    ...
Invalid: Enter a value less than 10 characters long
>>> String().from_python(None)
''
>>> String().from_python([])
''
>>> String().to_python(None)
''
>>> String(min=3).to_python(None)
Traceback (most recent call last):
    ...
Invalid: Please enter a value
>>> String(min=1).to_python('')
Traceback (most recent call last):
    ...
Invalid: Please enter a value

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
tooLong:
Enter a value less than %(max)i characters long
tooShort:
Enter a value %(min)i characters long or more

Attributes

a encoding

None

a strip

False

a use_builtins_gettext

True

a accept_python

True

a min

None

a list_joiner

', '

a __singletonmethods__

('to_python', 'from_python', 'message', 'all_messages', 'subvalidators')

a max

None

a gettextargs

{}

a declarative_count

27

a __unpackargs__

()

a compound

False

a not_empty

None

a __mutableattributes__

()

a repeating

False

Methods

f __call__(self, *args, **kw) ...

f __classinit__(cls, new_attrs) ...

f __init__(self, *args, **kw) ...

f __sourcerepr__(self, source, binding=None) ...

f __classsourcerepr__(cls, source, binding=None) ...

f __initargs__(self, new_attrs) ...

f validate_other(self, value, state) ...

f empty_value(self, value) ...

See the source for more information.