Hiding modules

Josiah Carlson jcarlson at nospam.uci.edu
Mon Feb 16 19:50:57 CET 2004

import sys
import traceback

class MyDict(UserDict):
     def __getitem__(self, key):
             raise ""
             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