Nicolas Lehuen (JIRA) wrote ..
>      [ 
> http://issues.apache.org/jira/browse/MODPYTHON-54?page=comments#action_65702
> ]
>      
> Nicolas Lehuen commented on MODPYTHON-54:
> -----------------------------------------
> 
> I have added two function to mod_python.publisher :
> 
> def import_page(relative_path, auto_reload=True):
>     """
>         This imports a published page. The relative_path argument is a
> path
>         relative to the directory of the page where import_page() is called.
>         Hence, if we have index.py and foobar.py in the same directory,
> index.py
>         can simply do something like :
>         
>         import mod_python.publisher
>         foobar = mod_python.publisher.import_page('foobar.py')
>         
>         If auto_reload is True (the default), the returned object is not
> really
>         the module itself, but a placeholder object which allows the real
> module
>         to be automatically reloaded whenever its source file changes.
>     """
> 
> and 
> 
> def get_page(req, relative_path):
>     """
>         This imports a published page. The relative_path argument is a
> path 
>         relative to the published page where the request is really handled
> (not
>         relative to the path given in the URL).
>         
>         Warning : in order to maintain consistency in case of module 
> reloading,
>         do not store the resulting module in a place that outlives the
> request
>         duration.
>     """
> 
> Now we need a bit of documentation.

Don't understand why it has to be relative for import_page(). Should
be able to specify any path. The code can do an os.path.isabs() call
and if it is absolute use it as is and if relative only then consider
trying to automagically turn it into an absolute path somehow.

Overall I feel that these functions might need a bit more thought.

The handle around the module worries me a bit as it would appear to
work in read mode only. Ie., not sure it would work if someone tried to
actually set a global variable within the module from outside of it.
The lack of __setattr__() means it will probably set the variable in the
handle and not the cached module.

There are other things about it which means it will fail as appearing
to be a module. For example, dir() on the handle returns handle
stuff and not module stuff. Granted that for most this might not make
a difference but for a small number it might.

I'll think some more about the code and see if I can come up with any
suggestions.

BTW, do like the idea of looking back up the stack frame to find the
context. Am not sure that it will work all the time, although cases
that it will not probably work wouldn't come up when using publisher.
I'll probably look at falling back to this stack frame peek for my
Vampire importing system, so if I come up with additional checks
required to handle those cases where it may not work, will let you
know about that as well.

Graham

Reply via email to