[mod_python] problem in file download

John D. Garberson john.garberson at nexos.com
Fri Jun 7 10:54:18 EST 2002


Hi,

You wrote a few days back:

> 
> Hello,
> 
> I'm trying to download a file:
> 
....
....
....
a = getattr(file, name)
> 
> AttributeError: 'file' object has no attribute '__methods__'
> 
> 
> does anyone have any idea to solve this?
> 
> Villiam



Having to downgrade seems a bit extreme [;-)

I don't know much about the publisher.py module, never having used it.
But if you do this import:

------------------------------------------------------------------------

from types import BuiltinMethodType

------------------------------------------------------------------------

then this function:

------------------------------------------------------------------------

def sim_methods(obj):
    return filter(lambda s, t=obj:
           type(getattr(t, s)) == BuiltinMethodType,
                                             dir(obj))

--------------------------------------------------------------------------

works under both 2.0 and 2.2.1 (I don't have a 2.1 any more) and delivers
the list of methods that it seems you want, looking at the publisher.py
source.  If you're not a fan of the functional programming approach, then
a list comprehension:

-----------------------------------------------------------------------

def sim_methods(obj):
    return [m for m in dir(obj)
                   if type(getattr(obj, m)) == BuiltinMethodType]

-----------------------------------------------------------------------

works just as well.

You could just replace the 'for m in field.file.__methods__:'

with

'for m in sim_methods(field.file):'

Hope this helps.

John


     John Garberson                             nexos ag 
     john.garberson at nexos.com                   Frobenstrasse 66 
                                                CH-4053 Basel, Switzerland
                                                Tel. 41 61 283 55 03
                                                Fax  41 61 283 55 01




More information about the Mod_python mailing list