[ 
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.

> Add a way to import a published page into another published page
> ----------------------------------------------------------------
>
>          Key: MODPYTHON-54
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-54
>      Project: mod_python
>         Type: Improvement
>     Versions: 3.2.0
>     Reporter: Nicolas Lehuen
>     Assignee: Nicolas Lehuen
>      Fix For: 3.2.0

>
> Before mod_python 3.2, standard Python modules and published modules could be 
> imported the same way, using apache.import_module. This had a number of 
> disadvantages, leading to MODPYTHON-8, MODPYTHON-9, MODPYTHON-10, 
> MODPYTHON-11 and MODPYTHON-12.
> All these bugs were fixed by separating the published modules from the 
> standard Python module. apache.import_module can still be used to import 
> standard modules, but published modules are now fully managed  by 
> mod_python.publisher, and are not inserted into sys.modules.
> The problem is that there is a use case of importing a published module from 
> another published module :
> /index.py----------------
> def index(req):
>     return "Hello, world !"
> def utility_function(foobar):
>     return foobar+1
> /other.py----------------
> import os
> directory = os.path.split(__file__)[0]
> other_index = apache.import_module("index",path=[directory])
> def index(req):
>     return "%s %i"%(other_index.index(req),other_index.utility_function(2004))
> This was alread a bit of a hack in 3.1.4, but in 3.2 it does not really work 
> the expected way since the imported module (other_index in the example) is 
> not the same module as the one the publisher would use to publish /index.py. 
> This could be troublesome if the developer wanted to share some data between 
> the modules, e.g. a cache or a connection pool, but not if he only wanted to 
> share some code.
> Therefore, we need to provide a clean API in mod_python.publisher to allow 
> developers to reference another published module.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to