ConfirmType

Confirms that the input/output is of the proper type.

Uses the parameters:

subclass:
The class or a tuple of classes; the item must be an instance of the class or a subclass.
type:
A type or tuple of types (or classes); the item must be of the exact class or type. Subclasses are not allowed.

Examples:

>>> cint = ConfirmType(subclass=int)
>>> cint.to_python(True)
True
>>> cint.to_python('1')
Traceback (most recent call last):
    ...
Invalid: '1' is not a subclass of <type 'int'>
>>> cintfloat = ConfirmType(subclass=(float, int))
>>> cintfloat.to_python(1.0), cintfloat.from_python(1.0)
(1.0, 1.0)
>>> cintfloat.to_python(1), cintfloat.from_python(1)
(1, 1)
>>> cintfloat.to_python(None)
Traceback (most recent call last):
    ...
Invalid: None is not a subclass of one of the types <type 'float'>, <type 'int'>
>>> cint2 = ConfirmType(type=int)
>>> cint2(accept_python=False).from_python(True)
Traceback (most recent call last):
    ...
Invalid: True must be of the type <type 'int'>

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
inSubclass:
%(object)r is not a subclass of one of the types %(subclassList)s
inType:
%(object)r must be one of the types %(typeList)s
noneType:
The input must be a string (not None)
subclass:
%(object)r is not a subclass of %(subclass)s
type:
%(object)r must be of the type %(type)s

Attributes

a gettextargs

{}

a strip

False

a accept_python

True

a subclass

None

a __singletonmethods__

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

a type

None

a declarative_count

11

a use_builtins_gettext

True

a __unpackargs__

()

a compound

False

a not_empty

False

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 __init__(self, *args, **kw) ...

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

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

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

f is_empty(self, value) ...

See the source for more information.