Tommy !!
the_edge2020 at hotmail.com
Sun Apr 6 11:57:40 EST 2003
Hi Mike (and pascal), Wouldn't mod_python be able to determine the directory it is executing in from the request (in a handler maybe)? Or, at the very least, in the Apache module itself, since mod_python must obviously know where the current script is being executed in order to actually execute it (see the request_rec structure in the Apache 2 C source code to see the relevant fields). I would think that you could either: a) modify the handler itself to check the request for the path to the module, and then use os.path.dir (? from memory) to grab the directory it's executing in, and then throw that into the sys.path? b) take the same path that the Apache module itself does when it calls *sound of source code ruffling* PythonChildInitHandler (mod_python.c) and use the Python API to manipulate the sys.path global itself (except, obviously, from python_handler in the same file, where you *should* actually know where the file is located) Anyways I'm going to have a bit of a hack around the source code and see what I come up with. Thanks for your time guys, if you have any further comments I'd love to hear about it :) Kind 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 _________________________________________________________________ MSN Instant Messenger now available on Australian mobile phones. Go to http://ninemsn.com.au/mobilecentral/hotmail_messenger.asp
|