source: python/trunk/Lib/idlelib/Delegator.py

Last change on this file was 391, checked in by dmik, 11 years ago

python: Merge vendor 2.7.6 to trunk.

  • Property svn:eol-style set to native
File size: 665 bytes
Line 
1class Delegator:
2
3 # The cache is only used to be able to change delegates!
4
5 def __init__(self, delegate=None):
6 self.delegate = delegate
7 self.__cache = set()
8
9 def __getattr__(self, name):
10 attr = getattr(self.delegate, name) # May raise AttributeError
11 setattr(self, name, attr)
12 self.__cache.add(name)
13 return attr
14
15 def resetcache(self):
16 for key in self.__cache:
17 try:
18 delattr(self, key)
19 except AttributeError:
20 pass
21 self.__cache.clear()
22
23 def setdelegate(self, delegate):
24 self.resetcache()
25 self.delegate = delegate
Note: See TracBrowser for help on using the repository browser.