Well, here's another alternative: provide some other attribute to Field,
such as is_file, to determine whether or not the Field is an actual file
upload or something else. Because as implemented, the file attribute will
always return a file-type object.
Nick
Nick wrote:
Jorey Bump wrote:
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?
At a minimum, the documentation:
"This is a file object. For file uploads it points to a temporary file.
For simple values, it is a StringIO object, so you can read simple
string values via this attribute instead of using the value attribute
as well."
As I stated, it just may be enough to document here that it's a file
-or- a file-type object. That's what the Python documentation for
tempfile.TemporaryFile states, so maybe calling it a "bug" is wrong.
But it's equally simple to return the actual file object, and in my
opinion more convenient for programmers to do isinstance(field.file,
file) to see if you have an uploaded file vs. some other kind of value.
I don't know enough about Windows though to know what will happen if you
garbage collect the tempfile._TemporaryFileWrapper object but keeping a
reference to the file.
It's unfortunate that it's not possible to subclass a builtin type and
overload its methods (that I know of).
Nick