-
- # we don't know where we're going to save this stuff yet,
- # so I guess we'll write it to another tempfile. One we know the path of.
- # I'm assuming the tempfile we get from pylons is set to delete itself
- # when it closes, and has no visible path. Maybe I'm wrong?
- intermediate_file_descriptor, intermediate_path = tempfile.mkstemp()
-
- # that function gives me an integer file descriptor for some reason.
- intermediate_file = os.fdopen(intermediate_file_descriptor, "wb")
-
+
+ # The incoming fileobj could be a tempfile that's already been unlinked --
+ # and probably is, as it's coming from a Pylons upload object. Thus we
+ # have to copy the data rather than the file, and we may have to read the
+ # file anyway to hash it, so do both at the same time.
+
+ # Need a named temporary file to write to; it gets renamed once the hash is
+ # computed
+ temp_fd, temp_path = tempfile.mkstemp()
+ temp_file = os.fdopen(temp_fd, "wb")
+