Added 'description' class attribute to every command class (to help the
[python/dscho.git] / Tools / idle / Delegator.py
blob3665247c97d5c294fcb1fc5a0978868678a4a332
2 class Delegator:
4 # The cache is only used to be able to change delegates!
6 def __init__(self, delegate=None):
7 self.delegate = delegate
8 self.__cache = {}
10 def __getattr__(self, name):
11 attr = getattr(self.delegate, name) # May raise AttributeError
12 setattr(self, name, attr)
13 self.__cache[name] = attr
14 return attr
16 def resetcache(self):
17 for key in self.__cache.keys():
18 try:
19 delattr(self, key)
20 except AttributeError:
21 pass
22 self.__cache.clear()
24 def cachereport(self):
25 keys = self.__cache.keys()
26 keys.sort()
27 print keys
29 def setdelegate(self, delegate):
30 self.resetcache()
31 self.delegate = delegate
33 def getdelegate(self):
34 return self.delegate