2 """
3 Adapter class as part of the Adapter design pattern.
4
5 - External Usage Documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Structural-Pattern-Usage}
6 - External Adapter Pattern Documentation: U{https://en.wikipedia.org/wiki/Adapter_pattern}
7 """
8 - def __init__(self, adaptee, **adapted_methods):
9 """
10 Initialize a new adapter instance.
11
12 @param adaptee: The object to adapt to a new interface.
13 @type adaptee: Object
14 @param adapted_methods: A dictionary of methods to adapt.
15 @type adapted_methods: dict
16 """
17 self.__adaptee = adaptee
18 self.__dict__.update({k: v for k, v in adapted_methods.items() if callable(v) and
19 getattr(self.__adaptee, v.__name__, None)})
20
22 """
23 All non-adapted calls are passed to the adaptee.
24
25 @param attr: The attribute to get from the adaptee.
26 """
27 return getattr(self.__adaptee, attr)
28
30 """
31 Get the adaptee's __dict__
32 """
33 return self.__adaptee.__dict__
34