[issue9968] Let cgi.FieldStorage have named uploaded file

phep report at bugs.python.org
Wed Jul 27 21:56:51 CEST 2011


phep <patrice.pillot at teletopie.net> added the comment:

>> where does the 1ko barrier come from? Was it only chosen out of 
>> performance considerations [...]
> 
> Most certainly.  I’ll look at the history of the file later to try to
> find the developer who decided that.

Guido van Rossum made the changes. Before that a temporary file was created for every form field.

>> tempfile.NamedTemporaryFile was already used in python 3 (fixed in 
>> r57595, with not many explanations though).
> 
> That’s a TemporaryFile, without a name.  For more explanations, follow

Yes, my sleepy eyes and drowsy brain fooled me more than once last
night. Sigh...

> the parents of the changeset and you’ll find aee21e0c9a70 
> (referencing #1033) and cbd50ece3b61, where you can see an XXX
> note that is probably the “wish” referred to in the cryptic commit
> message.

Thanks.

A last question before trying to write the patch: In order for the change I propose to be interesting, one should let caller code decide where (on disk) the NamedTemporaryFile should be created since writing this on a different partition than the one the file will eventually reside on would ruin the whole trick. Also, I believe one can think of other reasons to give this freedom.

Unfortunately, in order to do that, I can see no other solution than to change the FieldStorage constructor signature since the temp files are created as soon as the object is instantiated. So, we would end up with something along those lines:

class FieldStorage(cgi.FieldStorage):
    def __init__(self, tempdir=tempfile.gettempdir()):
        self.tempdir = tempdir
	...

or a somewhat more convoluted form that would avoid importing tempfile needlessly.

Do you think this would be acceptable ?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9968>
_______________________________________


More information about the Python-bugs-list mailing list