ยปCore Development>Code coverage>Lib/idlelib/delegator.py

Python code coverage for Lib/idlelib/delegator.py

#countcontent
1n/aclass Delegator:
2n/a
3n/a def __init__(self, delegate=None):
4n/a self.delegate = delegate
5n/a self.__cache = set()
6n/a # Cache is used to only remove added attributes
7n/a # when changing the delegate.
8n/a
9n/a def __getattr__(self, name):
10n/a attr = getattr(self.delegate, name) # May raise AttributeError
11n/a setattr(self, name, attr)
12n/a self.__cache.add(name)
13n/a return attr
14n/a
15n/a def resetcache(self):
16n/a "Removes added attributes while leaving original attributes."
17n/a # Function is really about resetting delagator dict
18n/a # to original state. Cache is just a means
19n/a for key in self.__cache:
20n/a try:
21n/a delattr(self, key)
22n/a except AttributeError:
23n/a pass
24n/a self.__cache.clear()
25n/a
26n/a def setdelegate(self, delegate):
27n/a "Reset attributes and change delegate."
28n/a self.resetcache()
29n/a self.delegate = delegate
30n/a
31n/aif __name__ == '__main__':
32n/a from unittest import main
33n/a main('idlelib.idle_test.test_delegator', verbosity=2)