Backport importlib to at least Python 2.5 by getting rid of use of str.format.
[python.git] / Lib / idlelib / Delegator.py
blob6125591fe0dd1aef5ad67dda101001c8f63b97ae
1 class Delegator:
3 # The cache is only used to be able to change delegates!
5 def __init__(self, delegate=None):
6 self.delegate = delegate
7 self.__cache = {}
9 def __getattr__(self, name):
10 attr = getattr(self.delegate, name) # May raise AttributeError
11 setattr(self, name, attr)
12 self.__cache[name] = attr
13 return attr
15 def resetcache(self):
16 for key in self.__cache.keys():
17 try:
18 delattr(self, key)
19 except AttributeError:
20 pass
21 self.__cache.clear()
23 def cachereport(self):
24 keys = self.__cache.keys()
25 keys.sort()
26 print keys
28 def setdelegate(self, delegate):
29 self.resetcache()
30 self.delegate = delegate
32 def getdelegate(self):
33 return self.delegate