-#!/usr/bin/python2
+#!/usr/bin/python
# Copyright (c) 2003 Intel Corporation
# All rights reserved.
MaxTransferTime= DEFAULT_CURL_MAX_TRANSFER_TIME,
FormData= None):
- if hasattr(tempfile, "NamedTemporaryFile"):
- buffer = tempfile.NamedTemporaryFile()
- buffer_name = buffer.name
- else:
- buffer_name = tempfile.mktemp("MakeRequest")
- buffer = open(buffer_name, "w+")
+ (fd, buffer_name) = tempfile.mkstemp("MakeRequest-XXXXXX")
+ os.close(fd)
+ buffer = open(buffer_name, "w+b")
+
+ # the file "buffer_name" will be deleted by DownloadFile()
ok = self.DownloadFile(PartialPath, GetVars, PostVars,
DoSSL, DoCertCheck, buffer_name,
MaxTransferTime,
FormData)
- # check the code, return the string only if it was successfull
+ # check the ok code, return the string only if it was successfull
if ok:
buffer.seek(0)
- return buffer.read()
+ ret = buffer.read()
else:
- return None
+ ret = None
+
+ buffer.close()
+ try:
+ # just in case it is not deleted by DownloadFile()
+ os.unlink(buffer_name)
+ except OSError:
+ pass
+
+ return ret
def DownloadFile(self, PartialPath, GetVars, PostVars,
DoSSL, DoCertCheck, DestFilePath,