[mod_python] problem with publisher.py File class w/ possible fix

Marc Fiuczynski marcf at becomm.com
Wed Mar 21 12:55:55 EST 2001


Hi,

I am having a problem with the publisher.py File class, which I have fixed,
but I would like your approval.

My configuration is as follows:
mod_python 2.7.2
python 2.0
apache 1.3.14
Red Hat Linux 7.0

I am using mod python to do http_post operations with files.  This uses the
publisher.py File class.  The __init__ method of that class steals all of
the file-like methods, as shown below:

        # steal all the file-like methods
        methods = field.file.__methods__
        for m in methods:
            self.__dict__[m] = methods[m]

I was getting an error in that last line saying that 'm' needed to be an
int.  (Sorry, I forget the actual error).  I found some other code that was
doing the exact same thing and noticed that they were assigning the methods
in a different manner (using setattr).  See below:

        # steal all the file-like methods
        file = field.file
        for method in file.__methods__:
            setattr(self, method, getattr(file, method))

This seems to work.  I am too nascent to Python to understand the history of
the built-in __xyz__ fields in objects, and whether this is something
specific to Python 2.0 versus an older version of Python.  Please review and
if it is the right thing, then feel free to incorporate this change into
your mod_python code base.

Cheers,
Marc




More information about the Mod_python mailing list