Hiding modules
Josiah Carlson
jcarlson at nospam.uci.edu
Mon Feb 16 13:50:57 EST 2004
import sys
import traceback
class MyDict(UserDict):
def __getitem__(self, key):
try:
raise ""
except:
a = traceback.extract_stack()
#do all your call checking on a
#similar checks for __setitem__
sys.modules = MyDict(sys.modules)
Do as many checks on the caller that tries to access a module via
sys.modules as you want.
You could also replace new.module with similar attribute get and set
permission checking, though my testing suggests that this may not be
enough (perhaps import keeps a reference to the original version of
new.module, or something).
- Josiah
More information about the Python-list
mailing list