Right on, that seemed to work, thanks. This is different than sys.path_hooks though, which requires a callable or string subclass?
After some experimentation it looks like you can disallow an import by raising an import error from your meta_path hook. It seems a little weird that python will then raise a new ImportError from import.c:find_module(), but I guess the behavior is desirable.. On Wed, Apr 16, 2008 at 5:17 PM, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Wed, 16 Apr 2008 09:04:36 -0300, Patrick Stinson > <[EMAIL PROTECTED]> escribió: > > > I am defining a simple finder/loader object and adding it to > > sys.meta_path > > like this: > > > > PyRun_SimpleString("import sys; import ousiainternal; sys.meta_path = > > [ousiainternal.OusiaImporter]"); > > You should append to the existing meta_path, not replace it, erasing any > previous content. > And it must be an *instance* of your importer, not the type itself. > Note that you're polluting the __main__ module namespace by using > PyRun_SimpleString; I'd use API calls like PySys_GetObject("meta_path") > and PyList_Append (PEP 302 guarantees it is a list). > > > "sys.meta_path.append(Importer)\n"; > > Here you append to sys.meta_path, but fail to create the instance first. > > > PyRun_SimpleString(importer_source); > > You should check the return value; I bet you got a -1 (failure). > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Patrick Kidd Stinson http://www.patrickkidd.com/ http://pkaudio.sourceforge.net/ http://pksampler.sourceforge.net/
-- http://mail.python.org/mailman/listinfo/python-list