Commit 035b33e2 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix tempfile reset code & test on newer Python

Python 2.7.3 (rc status) and 3.2.3/3.3 (rc, respectively alpha status)
have fixed http://bugs.python.org/issue12856 which we worked around
ourselves.

This means two things:

- we don't need to manually reset the module
- we can't test for the no-reset case

Unfortunately current Debian Sid has the 2.7.3 RC but still labeled as
2.7.2+ 

, so we have to manually do an extra check (in the unit test
only); I expect Debian will update to official 2.7.3 as soon as it's
released, and then we can remove this override.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 7bfb3367
#
#
# Copyright (C) 2006, 2007, 2010, 2011 Google Inc.
# Copyright (C) 2006, 2007, 2010, 2011, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -22,6 +22,7 @@
"""
import sys
import time
import socket
import errno
......@@ -182,6 +183,11 @@ def ResetTempfileModule(_time=time.time):
"""
# pylint: disable=W0212
if ((sys.hexversion >= 0x020703F0 and sys.hexversion < 0x03000000) or
sys.hexversion >=0x030203F0):
# Python 2.7 automatically resets the RNG on pid changes (i.e. forking)
return
try:
lock = tempfile._once_lock
lock.acquire()
......
#!/usr/bin/python
#
# Copyright (C) 2010 Google Inc.
# Copyright (C) 2010, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -47,6 +47,14 @@ class TestResetTempfileModule(unittest.TestCase):
shutil.rmtree(self.tmpdir)
def testNoReset(self):
if ((sys.hexversion >= 0x020703F0 and sys.hexversion < 0x03000000) or
sys.hexversion >=0x030203F0):
# We can't test the no_reset case on Python 2.7+
return
# evil Debian sid...
if (hasattr(tempfile._RandomNameSequence, "rng") and
type(tempfile._RandomNameSequence.rng) == property):
return
self._Test(False)
def testReset(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment