Processor to map the function parameter values. The syntax is equal to `Processor` except that a dict is used as mapping table. Examples:: >>> conv = MapProcessor({True: 42}) >>> conv(True) 42
| 249 | |
| 250 | |
| 251 | class MapProcessor(Processor): |
| 252 | """Processor to map the function parameter values. |
| 253 | |
| 254 | The syntax is equal to `Processor` except that a dict is used as |
| 255 | mapping table. |
| 256 | |
| 257 | Examples:: |
| 258 | |
| 259 | >>> conv = MapProcessor({True: 42}) |
| 260 | >>> conv(True) |
| 261 | 42 |
| 262 | |
| 263 | """ |
| 264 | |
| 265 | @classmethod |
| 266 | def to_callable(cls, obj): |
| 267 | if isinstance(obj, dict): |
| 268 | return get_mapping(obj) |
| 269 | if isinstance(obj, set): |
| 270 | return check_membership(obj) |
| 271 | raise TypeError('MapProcessor argument must be a dict or a callable, ' |
| 272 | 'not {}'.format(obj)) |
| 273 | |
| 274 | |
| 275 | class ReverseMapProcessor(Processor): |