[mod_python] The DOs and DONTs of mod_python: second problem maybecornered.

Graham Dumpleton grahamd at dscpl.com.au
Wed Oct 19 05:15:45 EDT 2005


On 19/10/2005, at 2:16 PM, Graham Dumpleton wrote:

>
> Now if I create a mod_python.publisher function:
>
>   import pyexpat
>
>   def index():
>     return pyexpat.version_info
>
> and access that page, I get returned:
>
>   1952
>
> I don't quite understand why it is returning an integer rather than  
> a tuple,
> it may actually indicate a problem. As one can see though, it is  
> now actually
> using 1.95.2 which Apache loaded and not that embedded in the pyexpat
> Python module .so.

Remember now why it is an integer. In mod_python.publisher in mod_python
3.2 the behaviour changed in respect of how iterable values are  
converted
to a string. Prior to 3.2, a list would be converted using str(). In  
3.2 it uses the
code:

     elif hasattr(object,'__iter__'):

         # To publish iterables, we recursively publish each item
         # This way, generators can be published
         result = False
         for item in object:
             result |= publish_object(req,item)
         return result

That is, it iterates over each item, effectively concatenating  
together the values
for each item. Thus we get "1952" instead of "(1,95,2)".

I wasn't keen on this when I saw it had been done and still not happy  
about
it. I felt that this is something that should have been done at the  
user level. :-(

Graham


More information about the Mod_python mailing list