MCPcopy Create free account
hub / github.com/LabPy/lantz / ReverseMapProcessor

Class ReverseMapProcessor

lantz/processors.py:275–301  ·  view source on GitHub ↗

Processor to map the function parameter values. The syntax is equal to `Processor` except that a dict is used as mapping table. Examples:: >>> conv = ReverseMapProcessor({True: 42}) >>> conv(42) True

Source from the content-addressed store, hash-verified

273
274
275class ReverseMapProcessor(Processor):
276 """Processor to map the function parameter values.
277
278 The syntax is equal to `Processor` except that a dict is used as
279 mapping table.
280
281 Examples::
282
283 >>> conv = ReverseMapProcessor({True: 42})
284 >>> conv(42)
285 True
286 """
287
288 #: Shared cache of reversed dictionaries indexed by the id()
289 __reversed_cache = {}
290
291 @classmethod
292 def to_callable(cls, obj):
293 if isinstance(obj, dict):
294 obj = cls.__reversed_cache.setdefault(id(obj),
295 {value: key for key, value
296 in obj.items()})
297 return get_mapping(obj)
298 if isinstance(obj, set):
299 return check_membership(obj)
300 raise TypeError('ReverseMapProcessor argument must be a dict or a callable, '
301 'not {}'.format(obj))
302
303
304class RangeProcessor(Processor):

Callers 1

rebuildMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected