45def adapt(obj, protocol, alternate=AdaptationError):
46
47 t = type(obj)
48
49
50 if t is protocol:
51 return obj
52
53 try:
54
55 conform = getattr(t, '__conform__', None)
56 if conform is not None:
57 result = conform(obj, protocol)
58 if result is not None:
59 return result
60
61
62 adapt = getattr(type(protocol), '__adapt__', None)
63 if adapt is not None:
64 result =
adapt(protocol, obj)
65 if result is not None:
66 return result
67 except LiskovViolation:
68 pass
69 else:
70
71 try:
72 if isinstance(obj, protocol):
73 return obj
74 except:
75 pass
76
77
def adapt(obj, protocol, alternate=AdaptationError)