[mod_python] loading mod_python.apache module interactively

Daniel J. Popowich dpopowich at mtrsd.k12.ma.us
Thu May 6 09:31:45 EST 2004

I needed to import my mod_python code outside of apache to run epydoc
(epydoc.sourceforge.net), an API documentation generator, that needs
to parse code to get at doc strings.

Here's my trick: I wrote my own minimal _apache.py that I placed in my
PYTHONPATH such that when I run epydoc (or an interactive session) my
_apache.py is loaded, but in apache, where I don't touch PythonPath
directive, mod_python._apache gets loaded.

This works for mod_python 3.1.3.  Your mileage may very.

    # _apache.py
    This module exists so you can import mod_python.apache outside of a
    running apache server.  This doesn't mean anything will work, just
    that you'll be able to do the import.

    This is useful for running tools (like epydoc) which need to do an
    import, not to run code, but to parse and/or read doc strings.

    class _pseudo:
	def __call__(self, *args):

    _p = _pseudo()

    for attr in ('table', 'log_error', 'table', 'config_tree',
		 'server_root', 'mpm_query', 'SERVER_RETURN',
		 'parse_qs', 'parse_qsl', 'mpm_query'):

	exec '%s = _p' % attr

    del _p, _pseudo, attr

More information about the Mod_python mailing list