[mod_python] "File" class object in form fields.

Graham Dumpleton grahamd at dscpl.com.au
Tue Oct 19 18:31:02 EDT 2004


In mod_python 2.X, there is code in publisher which says:

       # if it is a file, make File()
       if field.filename:
           val = File(field)
       else:
           val = field.value

class File:
    """ Like a file, but also has headers and filename
    """

    def __init__(self, field):

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

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

In mod_python 3.X, it is:

    # add form data to args
    for field in fs.list:
        if field.filename:
            val = field
        else:
            val = field.value
        args.setdefault(field.name, []).append(val)

The difference being that in mod_python 2.X, it would wrap what it saw as
a file input field into an instance of a special File object.

In Vampire I originally wrote code having only access to mod_python 2.X
and so similarly wrapped fields into a File object if needed. Now seeing that
mod_python 3.X doesn't do it, should I also now not be doing it if it is seen
to be better not do it.

For those who have actually done input forms with file uploading (I haven't)
what does the difference really mean in practice? Which is the better way?

At this stage I am inclined to do it like mod_python 3.X, especially how that
was how I had done this stuff in another system before I even ever looked at
mod_python.

--
Graham Dumpleton (grahamd at dscpl.com.au)


More information about the Mod_python mailing list