[mod_python] Import Issues

Tommy !! the_edge2020 at hotmail.com
Sun Apr 6 15:02:02 EST 2003


Hi all,

I achieved what I wanted by modifying publisher.py - obviously this is a bit 
dirty since it's handler-specific, but oh well - it works.

Basically, I use the following code in publisher.py prior to calling the 
target python script itself (where 'path' is the path to the python script 
determined by publisher.py):

if not path in sys.path:
  sys.path.append( path )

# ...

while path in sys.path:
  del sys.path[sys.path.index( path )]


Is there a chance something like this could be added to future versions of 
mod_python? If not, why not? I don't see why it should be necessary to 
modify httpd.conf or a .htaccess file for every web application I write when 
it could be as simple as writing a script & some supporting moudles :)

Another question - what's to stop a remote user from running any given 
method in an arbitrary python script within a directory when using the 
publisher handler?

Regards,
Tom L






>From: Mike Verdone <mike_verdone at shaw.ca>
>To: Tommy !! <the_edge2020 at hotmail.com>, mod_python at modpython.org
>Subject: Re: [mod_python] Import Issues
>Date: Sat, 05 Apr 2003 11:20:26 -0700
>MIME-Version: 1.0
>Received: from mc5-f20.law1.hotmail.com ([65.54.252.27]) by 
>mc5-s2.law1.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600); Sat, 5 Apr 
>2003 10:29:20 -0800
>Received: from eden.ispol.com ([206.239.103.254]) by 
>mc5-f20.law1.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600); Sat, 5 Apr 
>2003 10:28:26 -0800
>Received: from eden.ispol.com (localhost.ispol.com [127.0.0.1])by 
>eden.ispol.com (8.12.6/8.11.1) with ESMTP id h35IL4WT029214;Sat, 5 Apr 2003 
>13:21:04 -0500 (EST)(envelope-from mod_python-admin at modpython.org)
>Received: from pd6mo2so.prod.shaw.ca (shawidc-mo1.cg.shawcable.net 
>[24.71.223.10])by eden.ispol.com (8.12.6/8.11.1) with ESMTP id 
>h35IK9WT029190for <mod_python at modpython.org>; Sat, 5 Apr 2003 13:20:09 
>-0500 (EST)(envelope-from mike_verdone at shaw.ca)
>Received: from pd3mr3so.prod.shaw.ca (pd3mr3so-ser.prod.shaw.ca 
>[10.0.141.179]) by l-daemon (iPlanet Messaging Server 5.1 HotFix 0.8 (built 
>May 12 2002)) with ESMTP id <0HCV004PCUXCO3 at l-daemon> for 
>mod_python at modpython.org; Sat, 05 Apr 2003 11:20:00 -0700 (MST)
>Received: from pn2ml5so.prod.shaw.ca (pn2ml5so-qfe0.prod.shaw.ca 
>[10.0.121.149]) by l-daemon (iPlanet Messaging Server 5.1 HotFix 0.8 (built 
>May 12 2002)) with ESMTP id <0HCV00BORUXCL2 at l-daemon> for 
>mod_python at modpython.org; Sat, 05 Apr 2003 11:20:00 -0700 (MST)
>Received: from 192.168.0.42 (h68-144-147-185.cg.shawcable.net 
>[68.144.147.185]) by l-daemon (iPlanet Messaging Server 5.1 HotFix 0.8 
>(built May 12 2002)) with ESMTP id <0HCV00F46UXCP9 at l-daemon> for 
>mod_python at modpython.org; Sat, 05 Apr 2003 11:20:00 -0700 (MST)
>X-Message-Info: pdGgd64CkwYBecCeulYyOTshuDTWlDUk
>In-reply-to: <F46Y7ZggDttW3SC7g4Z0002e234 at hotmail.com>
>Message-id: <200304051120.26133.mike_verdone at shaw.ca>
>User-Agent: KMail/1.5.1
>References: <F46Y7ZggDttW3SC7g4Z0002e234 at hotmail.com>
>Sender: mod_python-admin at modpython.org
>Errors-To: mod_python-admin at modpython.org
>X-BeenThere: mod_python at modpython.org
>X-Mailman-Version: 2.0.12
>Precedence: bulk
>List-Help: <mailto:mod_python-request at modpython.org?subject=help>
>List-Post: <mailto:mod_python at modpython.org>
>List-Subscribe: 
><http://www.modpython.org/mailman/listinfo/mod_python>,<mailto:mod_python-request at modpython.org?subject=subscribe>
>List-Id: mod_python user mailing list <mod_python.modpython.org>
>List-Unsubscribe: 
><http://www.modpython.org/mailman/listinfo/mod_python>,<mailto:mod_python-request at modpython.org?subject=unsubscribe>
>List-Archive: <http://www.modpython.org/pipermail/mod_python/>
>Return-Path: mod_python-admin at modpython.org
>X-OriginalArrivalTime: 05 Apr 2003 18:28:28.0117 (UTC) 
>FILETIME=[26ED0850:01C2FBA1]
>
>On April 5, 2003 10:53 am, Tommy !! wrote:
> > Hi all,
> >
> > Just curious as to why (by design?) mod_python does not allow one to 
>import
> > modules in the same directory as the executing script - instead you have 
>to
> > resort to altering sys.path inside each script in order to get it 
>importing
> > correctly.
> >
> > This is an issue if you don't have access to the web server to modify
> > httpd.conf and .htaccess files are disabled/limited. Additionally, I may
> > not have access to the site-packages directory, or any other directory, 
>for
> > that matter, from which my script could import reusable components.
> >
>
>The main problem is that mod_python doesn't know what directory it's in 
>when
>it executes a script except in two cases (as far as I can tell):
>
>1. You put the AddHandler directive in the .htaccess file in that 
>directory.
>
>2. You enclose the AddHandler directive in a <Directory> block specifying 
>the
>full path in apache.conf.
>
>Otherwise mod_python has no idea where it's really executing from, and 
>seems
>to default to the apache dir. If your administrator has restricted 
>.htaccess
>and won't set up apache.conf for you, then you're kinda hooped.
>
>Have you looked at the PythonPath directive? You may be able to get away 
>with
>that in your .htacces. e.g.:
>
>PythonPath "['/the/scripts/directory'] + sys.path"
>
>Good luck!
>
>Mike.
>
>_______________________________________________
>Mod_python mailing list
>Mod_python at modpython.org
>http://www.modpython.org/mailman/listinfo/mod_python


_________________________________________________________________
Hotmail now available on Australian mobile phones. Go to  
http://ninemsn.com.au/mobilecentral/hotmail_mobile.asp




More information about the Mod_python mailing list