#16569 closed Bug (invalid)
NamedTemporaryFile is missing the delete argument
Reported by: | Leon van der Ree | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 1.3 |
Severity: | Normal | Keywords: | NamedTemporaryFile, delete |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I am developing under Linux, while my test server is running Windows, which made me aware of the following error.
I wrote the following piece of code:
[code]
from django.core.files.temp import NamedTemporaryFile
img_temp = NamedTemporaryFile(delete=True)
code
which works fine under Linux, but fails under Windows.
I looked at the code in the django.core.files.temp module, and see it makes a distinction between Windows and other systems:
[code]
if os.name == 'nt':
code
in which case NamedTemporaryFile = TemporaryFile as defined above it.
However, according to http://docs.python.org/library/tempfile.html#tempfile.NamedTemporaryFile NamedTemporaryFile should be able to handle delete as well!
A solution would be to define NamedTemporaryFile as follows:
[code]
class NamedTemporaryFile(TemporaryFile):
def init(self, kwargs):
kwargs.pop('delete', True) # TODO: handle this delete flag
super(NamedTemporaryFile,self).init(kwargs)
code
But I haven't thought about how to handle the delete argument.
Change History (3)
comment:1 by , 13 years ago
Has patch: | unset |
---|---|
Resolution: | → invalid |
Status: | new → closed |
NamedTemporaryFile isn't a public API — there isn't any reference to this class in the documentation: https://docs.djangoproject.com/search/?q=NamedTemporaryFile&release=5
Django doesn't guarantee any consistency, usability or stability of the internal APIs. Use them at your own risk.
On a side note,
delete=True
is the default: http://docs.python.org/library/tempfile#tempfile.NamedTemporaryFile Just don't specify it and you'll be fine.