#8817: Accessing ImageField's dimensions doesn't close file -------------------------------------------+-------------------------------- Reporter: tripediac | Owner: mitsuhiko Status: closed | Milestone: 1.1 Component: File uploads/storage | Version: SVN Resolution: fixed | Keywords: Stage: Ready for checkin | Has_patch: 1 Needs_docs: 0 | Needs_tests: 0 Needs_better_patch: 0 | -------------------------------------------+-------------------------------- Comment (by mitsuhiko):
I personally think the problem should better be solved by replacing the custom `NamedTemporaryFile` with the standard one from the `tempfile` module. I can't really see what the one in django is used for. The docstring says this: {{{ The temp module provides a NamedTemporaryFile that can be re-opened on any platform. Most platforms use the standard Python tempfile.TemporaryFile class, but MS Windows users are given a custom class. This is needed because in Windows NT, the default implementation of NamedTemporaryFile uses the O_TEMPORARY flag, and thus cannot be reopened [1]. 1: http://mail.python.org/pipermail/python-list/2005-December/359474.html }}} The point of the temporary file is that it disappears if `close()` is called. Why is there code doing something like `open(f.name, 'r')` on a temporary file in django? Maybe that could be refactored that it does not open the file a second time. If not it would probably make sense to open the file using the windows API and by passing all `FILE_SHARE_` flags to it and the `FILE_ATTRIBUTE_TEMPORARY` and `FILE_FLAG_DELETE_ON_CLOSE` flags. That should give a posix like behavior. -- Ticket URL: <http://code.djangoproject.com/ticket/8817#comment:13> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---