API Doc¶
Main function¶
Copyright 2013, Gilles Devaux
All rights reserved.
Types¶
- class voyeur.types.DeferredType(field, _callable=None)[source]¶
A type that can read value from another data field.
You can apply a callable to the value
>>> from voyeur import view >>> definition = { >>> 'field': DeferredType('anotherfield', int), >>> } >>> >>> data = {'anotherfield': '2'} >>> result = view(data, definition) >>> assert result == {'field':2}
- class voyeur.types.Type[source]¶
So you can use objects as fields. You need to use an instance.
- The main difference with another callable is that the whole object
- will be passed as the first argument and the key as the second
>>> class MyType(Type): >>> def __call__(self, *args, **kwargs): >>> return 'domything' >>> >>> definition = { >>> 'field': MyType(), >>> }