Package gavo :: Package utils :: Module serializers :: Class ValueMapperFactoryRegistry
[frames] | no frames]

Class ValueMapperFactoryRegistry

source code

object --+
         |
        ValueMapperFactoryRegistry

An object clients can ask for functions fixing up values for encoding.

A mapper factory is just a function that takes an AnnotatedColumn instance. It must return either None (for "I don't know how to make a function for this combination these column properties") or a callable that takes a value of the given type and returns a mapped value.

To add a mapper, call registerFactory. To find a mapper for a set of column properties, call getMapper -- column properties should be an instance of AnnotatedColumn, but for now a dictionary with the right keys should mostly do.

Mapper factories are tried in the reverse order of registration, and the first that returns non-None wins, i.e., you should register more general factories first. If no registred mapper declares itself responsible, getMapper returns an identity function. If you want to catch such a situation, you can use somthing like res = vmfr.getMapper(...); if res is utils.identity ...

Instance Methods
 
__init__(self, factories=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
clone(self)
returns a clone of the factory.
source code
 
getFactories(self)
returns the list of factories.
source code
 
registerFactory(self, factory) source code
 
appendFactory(self, factory) source code
 
getMapper(self, colDesc)
returns a mapper for values with the python value instance, according to colDesc.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, factories=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

clone(self)

source code 

returns a clone of the factory.

This is a copy, i.e., factories added will not change the original.

getFactories(self)

source code 

returns the list of factories.

This is not a copy. It may be manipulated to remove or add factories.

getMapper(self, colDesc)

source code 

returns a mapper for values with the python value instance, according to colDesc.

This method may change colDesc.

We do a linear search here, so you shouldn't call this function too frequently.