python import hooks: accessing the full dotted module name before processing
<p>I understand the fact that the importer protocol operates at the level of individual imports. However, in my case, it would be really helpful if I could know the full "dotted module name" BEFORE fully experiencing it one path element at time (that is, "a priori" if I'm allowed to say that) from my import hook.</p>

<pre><code>class myimporter(object):
    def find_module(self,fullname,path=None):
        if fullname == 'rootnamespace':
            #at this moment I need to know the full dotted module name
            #that I am going to process (e.g. rootnamespace.foo.bar.baz)

    def load_module(self,fullname):
         pass
</code></pre>

<p>Is there a way (hopefully safe and sound) to know beforehand the full "dotted module name" from within an import hook?</p>

<hr>

<p>--- more infos, probably not really needed (so you can skip straight to answering me ;) ), however:</p>

<p>If the reader wonders why would I need that or just maybe a little bit more info is to be helpful: I want to import perl modules in python. How strange does this sound? :) In reality, the import process will just make available a python stub for a perl module. The stub is generated by introspecting the perl package and see what it has to offer; I wont enter in the details of implementation here:</p>

<pre><code>import perlmod.www.mechanize as wwwmech
mymech = wwwmech() #return a python proxy object to be used with later calls
mymech.get(uri) #returns another proxy object to the newly generated HTTP::Response perl object
#etc etc
</code></pre>

<p>my problem lies at </p>

<pre><code>import perlmod.www.mechanize
</code></pre>

<p>because I need to know beforehand if the requested module does really exist in the system's perl installation, without being forced to wait the full module name so I can take the decision if I should fail or not. Moreover, if the user does:</p>

<pre><code>import perlmod.www
</code></pre>

<p>I have no chance to get back and say "wait wait wait, this is wrong" after loading a www stub package. My hook won't be called after that.</p>

<p>Basically, when my import hook is called for "www" I must already know if the import will fail or succeed for the full dotted module name. I will stop here with the details, please don't forget the real question :)</p>

<p>Thank you very much, even only for reading this.</p>
