[mod_python] Re: Mod_python Digest, Vol 31, Issue 32

Gavin gavin at sz.net.cn
Mon Oct 17 03:06:23 EDT 2005


Hello all, 

I  plan to develop an HTTP API for my application. How to change HTTP 
status code and HTTP reason message?

Thanks in advance!

Sincerely

Frank Ning



----- Original Message ----- 
From: <mod_python-request at modpython.org>
To: <mod_python at modpython.org>
Sent: Monday, October 17, 2005 12:00 AM
Subject: Mod_python Digest, Vol 31, Issue 32


> Send Mod_python mailing list submissions to
> mod_python at modpython.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mailman.modpython.org/mailman/listinfo/mod_python
> or, via email, send a message with subject or body 'help' to
> mod_python-request at modpython.org
> 
> You can reach the person managing the list at
> mod_python-owner at modpython.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Mod_python digest..."
> 
> 
> Today's Topics:
> 
>   1. Re: database connection (Julien Cigar)
>   2. Re: database connection (Graham Dumpleton)
>   3. Re: database connection (Jim Gallacher)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Sun, 16 Oct 2005 13:05:11 +0200
> From: Julien Cigar <jcigar at ulb.ac.be>
> Subject: Re: [mod_python] database connection
> To: mod_python at modpython.org
> Message-ID: <435233E7.7020707 at ulb.ac.be>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Graham Dumpleton wrote:
> 
>>
>> On 16/10/2005, at 7:42 PM, Julien Cigar wrote:
>>
>>> Graham Dumpleton wrote:
>>>
>>>> A comment on something else in your example first.
>>>>
>>>>> pageAction1 = apache.import_module('pages/action1')
>>>>
>>>>
>>>>
>>>> I wouldn't rely rely on being able to specific '/' in the module 
>>>> name as
>>>> argument. The documentation only mentions that '.' can be used if
>>>> needing to reference a subcomponent of a package. What you are doing is
>>>> relying on a strange quirk of the implementation and in mod_python 3.3
>>>> if the module loading system is overhauled there may be no guarantee
>>>> that it would work the same. You could always campaign though that it
>>>> is a useful future that should be maintained but documented. :-)
>>>>
>>>> BTW, does the "pages" directory actually have an "__init__.py" file. I
>>>> think what you are doing doesn't require it to, but wanted to check if
>>>> you do have it or not.
>>>>
>>> My directory structure looks like this :
>>> index.py
>>> config.cfg
>>> config.py
>>> pages/page1.py
>>> pages/page2.py
>>> pages/page3.py
>>> ...
>>>
>>> My "pages" directory doesn't contain an __init__.py file (should I ?)
>>> I don't understand what's wrong with 
>>> apache.import_module(pages/page1.py) .. ? I always done like this :)
>>> Is it specific to mod_python ? I mean can you import pages/page1.py 
>>> with the classic Pyhon import ?
>>
>>
>> You can't use '/' when using the "import" statement in classic Python.
>> Ie., can't do:
>>
>>   import pages/page1
>>
>> You can use '.', ie.,
>>
>>   import pages.page1
>>
>> But then this is a package import and the "pages" directory needs to be
>> set up as a package, ie., it must contain an "__init__.py" file in it,
>> even if "__init__.py" has nothing in it.
>>
>> Similarly, if you use the __import__ builtin function, you can't use '/',
>> ie., can't do:
>>
>>   page1 = __import__("pages/page1")
>>
>> but can do:
>>
>>   page1 = __import__("pages.page1")
>>
>> In other words, that you can specify a '/' like you are is quite specific
>> to the current mod_python implementation of apache.import_module(). Well,
>> that is what I thought ......
>>
>> At this point I am a bit confused as I can't find anything in the 
>> mod_python
>> code which would even allow '/' to work. When I even try using it on my
>> platform, Python throws an exception:
>>
>>   ImportError: No module named pages/page1
>>
>> What version of mod_python are you using, what version of Python and what
>> platform? I don't understand how it could be working for you.
>>
>> Graham
>>
> I'm using mod_python version 3.1.3 on a Debian Linux platform (kernel 
> 2.6.12) with Python 2.3
> A small piece of my code can be found on 
> http://rafb.net/paste/results/9sjUSi95.html
> 
> 
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Sun, 16 Oct 2005 21:15:50 +1000
> From: Graham Dumpleton <grahamd at dscpl.com.au>
> Subject: Re: [mod_python] database connection
> To: Julien Cigar <jcigar at ulb.ac.be>
> Cc: mod_python at modpython.org
> Message-ID: <260d4bc9a723e51bbac503df8ec32361 at dscpl.com.au>
> Content-Type: text/plain; charset=US-ASCII; format=flowed
> 
> 
> On 16/10/2005, at 9:05 PM, Julien Cigar wrote:
> 
>>> In other words, that you can specify a '/' like you are is quite 
>>> specific
>>> to the current mod_python implementation of apache.import_module(). 
>>> Well,
>>> that is what I thought ......
>>>
>>> At this point I am a bit confused as I can't find anything in the 
>>> mod_python
>>> code which would even allow '/' to work. When I even try using it on 
>>> my
>>> platform, Python throws an exception:
>>>
>>>   ImportError: No module named pages/page1
>>>
>>> What version of mod_python are you using, what version of Python and 
>>> what
>>> platform? I don't understand how it could be working for you.
>>>
>> I'm using mod_python version 3.1.3 on a Debian Linux platform (kernel 
>> 2.6.12) with Python 2.3
>> A small piece of my code can be found on 
>> http://rafb.net/paste/results/9sjUSi95.html
> 
> Interesting. I just got onto a Linux system as well and tried __import__
> and it does actually work for '/'. Ie.,
> 
> Python 2.3.3 (#1, May  7 2004, 10:31:40)
> [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> __import__('pages/page1')
> hi
> <module 'pages/page1' from 'pages/page1.pyc'>
> >>> __import__('pages.page1')
> hi
> <module 'pages' from 'pages/__init__.pyc'>
> 
> Yet the same thing on Mac OS X doesn't work:
> 
> Python 2.3 (#1, Sep 13 2003, 00:49:11)
> [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> __import__('pages/page1')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> ImportError: No module named pages/page1
> >>> __import__('pages.page1')
> page1
> <module 'pages' from 'pages/__init__.pyc'>
> 
> Looks like it may work for you on Linux, but doesn't look like it is 
> going
> to be portable to other platforms.
> 
> Will be interesting to see what other platforms do.
> 
> Graham
> 
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Sun, 16 Oct 2005 10:22:46 -0400
> From: Jim Gallacher <jg.lists at sympatico.ca>
> Subject: Re: [mod_python] database connection
> To: Graham Dumpleton <grahamd at dscpl.com.au>
> Cc: mod_python at modpython.org
> Message-ID: <43526236.1030105 at sympatico.ca>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Graham Dumpleton wrote:
>> 
>> On 16/10/2005, at 9:05 PM, Julien Cigar wrote:
>> 
>>>> In other words, that you can specify a '/' like you are is quite 
>>>> specific
>>>> to the current mod_python implementation of apache.import_module(). 
>>>> Well,
>>>> that is what I thought ......
>>>>
>>>> At this point I am a bit confused as I can't find anything in the 
>>>> mod_python
>>>> code which would even allow '/' to work. When I even try using it on my
>>>> platform, Python throws an exception:
>>>>
>>>>   ImportError: No module named pages/page1
>>>>
>>>> What version of mod_python are you using, what version of Python and 
>>>> what
>>>> platform? I don't understand how it could be working for you.
>>>>
>>> I'm using mod_python version 3.1.3 on a Debian Linux platform (kernel 
>>> 2.6.12) with Python 2.3
>>> A small piece of my code can be found on 
>>> http://rafb.net/paste/results/9sjUSi95.html
>> 
>> 
>> Interesting. I just got onto a Linux system as well and tried __import__
>> and it does actually work for '/'. Ie.,
>> 
>> Python 2.3.3 (#1, May  7 2004, 10:31:40)
>> [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> __import__('pages/page1')
>> hi
>> <module 'pages/page1' from 'pages/page1.pyc'>
>>  >>> __import__('pages.page1')
>> hi
>> <module 'pages' from 'pages/__init__.pyc'>
>> 
>> Yet the same thing on Mac OS X doesn't work:
>> 
>> Python 2.3 (#1, Sep 13 2003, 00:49:11)
>> [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> __import__('pages/page1')
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>> ImportError: No module named pages/page1
>>  >>> __import__('pages.page1')
>> page1
>> <module 'pages' from 'pages/__init__.pyc'>
>> 
>> Looks like it may work for you on Linux, but doesn't look like it is going
>> to be portable to other platforms.
>> 
>> Will be interesting to see what other platforms do.
> 
> FreeBSD 5.4:
> 
> Python 2.4.1 (#2, Jul  7 2005, 19:02:14)
> [GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
> Type "help", "copyright", "credits" or "license" for more information.
> >>> __import__('pages/page1')
> <module 'pages/page1' from 'pages/page1.py'>
> 
> Python 2.4.1 (#2, Jul  7 2005, 19:02:14)
> [GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
> Type "help", "copyright", "credits" or "license" for more information.
> >>> __import__('pages.page1')
> <module 'pages' from 'pages/__init__.py'>
> 
> 
> Jim
> 
> 
> 
> 
> ------------------------------
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
> 
> 
> End of Mod_python Digest, Vol 31, Issue 32
> ******************************************
>



More information about the Mod_python mailing list