Author: tomaz
Date: Sun Dec 30 07:44:54 2012
New Revision: 1426905
URL: http://svn.apache.org/viewvc?rev=1426905&view=rev
Log:
Use mkstemp instead of deprecated and potentially insecure mktemp method inside
the local_storage test.
Also insure that this file is always closed.
Modified:
libcloud/trunk/libcloud/test/storage/test_local.py
Modified: libcloud/trunk/libcloud/test/storage/test_local.py
URL:
http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/storage/test_local.py?rev=1426905&r1=1426904&r2=1426905&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/storage/test_local.py (original)
+++ libcloud/trunk/libcloud/test/storage/test_local.py Sun Dec 30 07:44:54 2012
@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import with_statement
+
import os
import sys
import shutil
@@ -34,7 +36,7 @@ from libcloud.storage.types import Objec
try:
from libcloud.storage.drivers.local import LocalStorageDriver
except ImportError:
- print('lockfile library is not available, skipping tests...')
+ print('lockfile library is not available, skipping local_storage tests...')
LocalStorageDriver = None
from libcloud.storage.drivers.dummy import DummyIterator
@@ -56,10 +58,11 @@ class LocalTests(unittest.TestCase):
self.key = None
def make_tmp_file(self):
- tmppath = tempfile.mktemp()
- tmpfile = open(tmppath, 'w')
- tmpfile.write('blah' * 1024)
- tmpfile.close()
+ _, tmppath = tempfile.mkstemp()
+
+ with open(tmppath, 'w') as fp:
+ fp.write('blah' * 1024)
+
return tmppath
def remove_tmp_file(self, tmppath):