|
OK, I've finally settled to only implement get_page(req,path), which accepts an absolute or relative path. import_module was either too flaky in its previous implementation (with its DummyModule wrapper which I wasn't too proud of), or too ambitious in the envisioned implementation (which managed dependencies between pages) given that Vampire already does this very well.
get_page requires a request object, so it can only be used in the context of a request. So this is possible : # index.py from mod_python.publisher import get_page def index(req): return 'foobar.py page says "%s"'%getpage(req,'foobar.py').index(req) # foobar.py def index(req): return "Hello, world !" But this is no longer possible : # index.py from mod_python.publisher import import_page foobar = import_page('foobar.py') I keep this for a future release, with a possible convergence between Vampire and mod_python on this subject ? Duh, we're not resolved yet, we need a bit of documentation before !
Linked issues which will be addressed by rewritten module importer and top level handler dispatcher.
Resolved by new module importer for 3.3, but for 3.3 release looks like the new importer will have to be enabled explicitly as will not be the default.
With the new importer, the existing apache.import_module() function should be used as mod_python.publisher will also use that itself and thus all modules are loaded via the same module caching system. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.