prevent loading of specific modules

Wolfgang Draxinger wdraxinger at darkstargames.de
Fri Jul 12 18:33:41 EDT 2002


Say I've several different interpreters, and I want to prevent them to 
load specific modules, maybe because another loaded module conflicts 
with it. How can I do this?

E.g. I wrote a small extension module, say "spam"
in it's

void init_spam(void)
{
	Py_InitModule("spam", spam_methods);
	/*do something, that "eggs" cannot be loaded*/
}

I want to prevent python to load "eggs", on a low level C basis, 
something like a hook on PyImport_ImportModule() or something else.
My first idea was to override sys.import with a custom function,
e.g. spam.import that calls PyImport_ImportModule(). However if the 
script does a

del sys
import sys
reload(sys)

my override is lost, and thus spam could conflict with eggs if both 
loaded. A similair problem is, that I override e.g. sys.stdout with my 
own stuff, but this is lost when something like above is done. How can I 
prevent this?
-- 
+------------------------------------------------+
| +----------------+ WOLFGANG DRAXINGER          |
| | ,-.   DARKSTAR | lead programmer             |
| |(   ) +---------+ wdraxinger at darkstargames.de |
| | `-' / GAMES /                                |
| +----+''''''''     http://www.darkstargames.de |
+------------------------------------------------+




More information about the Python-list mailing list