First off, you're right, some weird things were happening.  If you
looked at the modules in sys.modules by looking at Admin/AppControl, you
could see that there were packages with my fake package names that
included Servlet, Page, etc.  That isn't surprising, because this
happens in all the contexts, but in the other contexts, those modules
just pointed to the top level module, ie, they were links.  IN my fake
modules, those modules were actually loaded again.  So something wasn't
quite right.

OK, I sat back and thought about this.  The reason we're doing the
context as a package thing is so that we don't have to put each
individual directory into sys.path, which could give naming conflicts
and result in importing the wrong module. It also allows one to say from
SubDir2.Module1 import Module1 when the Context structure looks like
Context/SubDir1/Subdir2/Module1, and not have to have SubDir2 in the
path or fully specify it package wise.  It just works (TM).

So, problem 2 isn't a problem in the AbsolutePath case, because we're
only talking about isolated files.  None of the files reference each
other, they're all standalone.  (For now, at least).

If I can ignore problem 2, then dealing with problem 1 gets easier.  I
use imp to load the module directly, not part of any package, and then I
give it a unique name.  We never reference servlet packages after they
are loaded, particularly not in this case.  So, it seems to work right.

I've put this in CVS.  

Jay

On 04 Aug 2001 11:50:56 -0400, Geoff Talvola wrote:
> 
> I tried an experiment -- in ServletFactory._importModuleFromDirectory() I 
> removed the code that writes out an empty __init__.py if it's 
> missing.  Instead, I just had it skip the import of the package if 
> __init__.py was missing.
> 
> This failed and gave me numerous strange errors about my servlets not being 
> derived from Servlet.
> 
>  From this experiment I conclude that you really _do_ need to have an 
> actual __init__.py if you're going to import something as a package, 
> otherwise something goes wrong in the import mechanism.  So I think the 
> code snippet above could be dangerous.
> 
> I remember many months ago when I was writing the "import contexts as 
> packages" code I tried for a long time to find a way to fake it and not 
> require the __init__.py file to be on disk, but I could never get it to work.
> 
> 
> - Geoff
> 
> 
> _______________________________________________
> Webware-devel mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/webware-devel



_______________________________________________
Webware-devel mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/webware-devel

Reply via email to