25 _adapter_factory_registry = {}
28 _adapter_factory_registry[objtype, protocol] = factory
31 del _adapter_factory_registry[objtype, protocol]
34 factory = _adapter_factory_registry.get((type(obj), protocol))
38 adapter = factory(obj, protocol, alternate)
39 if adapter
is AdaptationError:
40 raise AdaptationError,obj
45 def adapt(obj, protocol, alternate=AdaptationError):
55 conform = getattr(t,
'__conform__',
None)
56 if conform
is not None:
57 result = conform(obj, protocol)
58 if result
is not None:
62 adapt = getattr(type(protocol),
'__adapt__',
None)
64 result =
adapt(protocol, obj)
65 if result
is not None:
67 except LiskovViolation:
72 if isinstance(obj, protocol):