Hiding modules

Tommy Trojan hauck at gseos.com
Tue Feb 17 10:34:33 EST 2004


Josiah,

thanks, I will check out your solution. It looks similar to an import hook
to me. There is still a problem that the user could just reset sys.modules
to his own dict.

Thanks,
  Thomas


"Josiah Carlson" <jcarlson at nospam.uci.edu> wrote in message
news:c0r3j8$268$1 at news.service.uci.edu...
>
> 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