I: [mod_python] problem with file download in mod-python 3.0.1

Manera, Villiam vmanera at manord.com
Thu Jan 2 11:09:59 EST 2003


Da: Manera, Villiam 
Inviato: giovedì 2 gennaio 2003 11.08
A: 'Gregory (Grisha) Trubetskoy'
Oggetto: R: [mod_python] problem with file download in mod-python 3.0.1


The problem is in python 2.2, Christopher Sean Hilton [chris at vindaloo.com]
wrote:

His problem is that python 2.2 does not include the __methods__ attribute 
for classes but the publisher.py code which actually handles the file inload

depends on it. If he downgrades from python 2.2 to python 2.1 he'll have the

__methods__ attribute of the file class. Someone needs to address this in 
the mod_python code however:

        for m in field.file.__methods__:
            self.__dict__[m] = getattr(field.file, m)

        self.headers = field.headers
        self.filename = field.filename

doesn't work in python 2.2 because __methods__ doesn't exist. The code 
appears to be trying to make local copies of all of the methods in the 
object that gets passed to the user. I had this problem in Unix (FreeBSD) 
two weeks ago and downgrading my python from 2.2 to 2.1 solved it. A google 
search on python, __methods__, 2.1 and 2.2 will yield more information.

Chris

after this John D. Garberson [john.garberson at nexos.com] wrote:
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
==============================================================
This work fine and I don't investigate any more from more elegant solution
I'm not so good in python!!

Villiam M.
-----Messaggio originale-----
Da: Gregory (Grisha) Trubetskoy [mailto:grisha at modpython.org]
Inviato: venerdì 20 dicembre 2002 22.35
A: Manera, Villiam
Cc: Mod_python at modpython.org
Oggetto: Re: [mod_python] problem with file download in mod-python 3.0.1



I must be missing something obvious, but without testing it and just by
looking at the code, I'm not sure I understand what the benefit is of
filtering out BuiltinMethodType, as opposed to just using straight
dir(obj).

The above might be a moot point since just as Brian Hawthorne suggested
I'm not sure why we don't need the File class at all and am in the process
of trying to fish out any memories from my tired brain about how it came
about in the fist place....

Grisha

On Thu, 12 Dec 2002, Manera, Villiam wrote:

> I'm testing mod-python 3.0.1 with apache 2.0.43 and python 2.2.2
>
> I've founded a older problem in file download (from python 2.1 to 2.2)
>
> the workaround is still the same:
>
> in publisher.py:
>
>  class File:
>      """ Like a file, but also has headers and filename
>      """
>      def __init__(self, field):
>          # steal all the file-like methods
>          for m in dir(field.file):
> 		 self.__dict__[m] = getattr(field.file, m)
>
>          self.headers = field.headers
>          self.filename = field.filename
> ======================workaround
> ==============================================
>  class File:
>      """ Like a file, but also has headers and filename
>      """
>      def __init__(self, field):
>          # steal all the file-like methods
>          #for m in dir(field.file):    #dont' work
>          for m in self.sim_methods(field.file):
>              self.__dict__[m] = getattr(field.file, m)
>
>          self.headers = field.headers
>          self.filename = field.filename
>
> 	#new--------
>      def sim_methods(self,obj):
>          from types import BuiltinMethodType
>          return filter(lambda s, t=obj:
>             type(getattr(t, s)) == BuiltinMethodType, dir(obj))
>
>
> I hope it will be put in place
>
> regards
>
> Villiam Manera
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
>



_______________________________________________
Mod_python mailing list
Mod_python at modpython.org
http://www.modpython.org/mailman/listinfo/mod_python




More information about the Mod_python mailing list