Wrapper

Used to convert functions to validator/converters.

You can give a simple function for to_python , from_python , validate_python or validate_other . If that function raises an exception, the value is considered invalid. Whatever value the function returns is considered the converted value.

Unlike validators, the state argument is not used. Functions like int can be used here, that take a single argument.

Examples:

>>> def downcase(v):
...     return v.lower()
>>> wrap = Wrapper(to_python=downcase)
>>> wrap.to_python('This')
'this'
>>> wrap.from_python('This')
'This'
>>> wrap2 = Wrapper(from_python=downcase)
>>> wrap2.from_python('This')
'this'
>>> wrap2.from_python(1)
Traceback (most recent call last):
  ...
Invalid: 'int' object has no attribute 'lower'
>>> wrap3 = Wrapper(validate_python=int)
>>> wrap3.to_python('1')
'1'
>>> wrap3.to_python('a')
Traceback (most recent call last):
  ...
Invalid: invalid literal for int(): a

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)

Attributes

a gettextargs

{}

a func_to_python

None

a func_validate_other

None

a strip

False

a use_builtins_gettext

True

a accept_python

True

a __singletonmethods__

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

a func_validate_python

None

a declarative_count

12

a __unpackargs__

()

a compound

False

a not_empty

False

a func_from_python

None

a __mutableattributes__

()

a repeating

False

Methods

f __initargs__(self, new_attrs) ...

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

f __classinit__(cls, new_attrs) ...

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

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

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

f wrap(self, func) ...

See the source for more information.