Indrek Järve wrote:
This behaviour has been with Python for quite a while, so claiming it's simply a Python bug will be the same as declaring we don't support Windows.

Our company's software that runs on Windows and uses mod_python simply patches util.py with the following change:
227c227
<                 if isinstance(item.file, FileType):
---
> if isinstance(item.file, FileType) or (hasattr(item.file, 'file') and isinstance(item.file.file, FileType)):

I haven't tried this with mp32 yet (we're still running on Python 2.3 and I haven't had time to investigate how to compile mp on Windows), but on 3.0/3.1 it appears to work just fine for our customers.

The relevant part of FieldStorage has changed in 3.2.

     isinstance(item.file, FileType) or \
        isinstance(getattr(item.file, 'file', None), FileType):

so no more patching for you! Now I just need to understand what Nick is on about. ;)

Jim


Nick wrote:

More info:

python 2.4.2 on Linux:
>>> import tempfile
>>> t = tempfile.TemporaryFile()
>>> t
<open file '<fdopen>', mode 'w+b' at 0xb7df07b8>
>>> type(t)
<type 'file'>
>>> dir(t)
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'close', 'closed', 'encoding', 'fileno', 'flush', 'isatty', 'mode', 'name', 'newlines', 'next', 'read', 'readinto', 'readline', 'readlines', 'seek', 'softspace', 'tell', 'truncate', 'write', 'writelines', 'xreadlines']

python 2.4.1 on windows:
>>> import tempfile
>>> t = tempfile.TemporaryFile()
>>> t
<open file '<fdopen>', mode 'w+b' at 0x0099FBA8>
>>> type(t)
<type 'instance'>
>>> dir(t)
['__doc__', '__getattr__', '__init__', '__module__', '__repr__', 'close_called', 'file', 'name']

So this is an inconsistency within Python. Should mod_python attempt to correct it, or just claim a Python bug?

Nick

Nick wrote:

This may be a Python Windows thing, but it shows up in mod_python:

When using util.FieldStorage on multipart/form-data encoded POST data containing a file, in Linux a field.file will yield a file object (actually a subclass of file), but in Windows you have to get the file object through field.file.file. This probably has something to do with the fact that Windows' implementation of tempfile.TemporaryFile is different from Linux, but it should be made consistent in the mod_python interface.

Nick

Reply via email to