Jorey Bump wrote:
Jim Gallacher wrote:
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?
I think we should correct it. I'm sure users don't care that we
implement this with TemporaryFile. That being said, I wonder how many
applications on Windows we may break by fixing this? Version 3.1.4
also used TemporaryFile, so this is not a new bug.
Are you sure there is anything to correct? In both cases, the object has
the same methods available for manipulating files (t.write('a'), for
example). They are not the same type of object, so they have different
dir() output, but don't they have the same functionality? What
specifically gets broken in util.FieldStorage?
No, I'm not sure. Now that I play around with it I'm not sure I
understand the problem at all. Perhaps Nick could elaborate?
Testing with python3.2.3 on Wine:
>>> import tempfile
>>> from types import *
>>> t = tempfile.TemporaryFile()
>>> t
<open file '<fdopen>', mode 'w+b' at 0x40D6A560>
>>> t.file
<open file '<fdopen>', mode 'w+b' at 0x40D6A560>
>>> t.write('stuff')
>>> t.seek(0)
>>> t.read()
>>> isinstance(t, FileType)
False
Other than the fact that "isinstance(t, FileType): returns False, I
don't see the problem. Nick?
Jim