[mod_python] Unable to import modules in subdirs

Brandon N woodsman at gmail.com
Fri Oct 28 10:40:28 EDT 2005


Are you forced, with mod_python, to write all package code within the
__init__.py? I ask because of what you've mentioned a few times now and what
I keep encountering.

I have Vampire up and running, though from a doc it specifies "...The
mechanism will also not work where a module is actually a package. Any
application specific modules should therefore not be structured as
packages..." which I imagine is a restriction coming from mod_python. I have
existing code that is already structured in various packages and I'd like to
keep it that way.

I'm able to import Admin but Admin.RemoteAdmin fails (as before). The only
way I've found around this is via an import of RemoteAdmin within Admin's
__init__.py which isn't much of a fix.

With that klunky method I get the desired:
import Admin.RemoteAdmin as RA
A = RA.RemoteAdmin( )

Is there a more pythonic way to accomplish this from within mod_python?

On 10/27/05, Jorey Bump <list at joreybump.com> wrote:
>
> Brandon N wrote:
>
> > I meant seeing as others had pointed out the concern that one shouldn't
> > put .py files under htdocs/ or similar directories for fear that someone
> > might find access to one's source files, wholly intact.
> >
> > Though
> > > In order for
> > > Apache to make this determination, the .py files must be in the public
> > > directories that Apache is managing.
> > made it clear for me.
> >
> > Is that at all a security issue. Or rather, is there a standard method
> > of referencing code outside of the public directories?
>
> Yes. You import it, as you would with most Python applications. I use
> Publisher, and typically have only a few lines of code in my published
> modules, which act as interfaces to packages in my extended path:
>
> /var/www/vhosts/walamaloo/website/mp/six.py:
>
> """
> Published module used as interface to rules package.
> """
> # all the code is in this package
> # /var/www/vhosts/walamaloo/python/bruce/faculty/rules/__init__.py
> import bruce.faculty.rules
>
> def index(req):
> """
> Default function for users.
> """
> return bruce.faculty.rules.four(req)
>
> def admin(req):
> """
> Requires authentication using proprietary mechanism.
> """
> return bruce.faculty.rules.onethreefiveseven(req)
>
>
> This is just my preference. You can put all of your code in a published
> module, if you want. But this approach allows me to hide sensitive
> information outside of the DocumentRoot and encourages code reuse. I can
> build apps relatively quickly because my extended path is filled with
> various utility modules.
>
> You might find some similarities to PHP's require() or include(), but
> those are a bit simplistic compared to Python's import mechanism. On the
> other hand, I have to restart apache often when developing new
> applications, so PHP does have have one thing going for it (but only
> one). :)
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20051028/1287be8e/attachment.html


More information about the Mod_python mailing list