[tor-commits] [stem/master] Missed another tarfile 'with' declaration

atagar at torproject.org atagar at torproject.org
Mon Jun 25 01:45:02 UTC 2012


commit ac34b8151c5b46369578922ba4f90fdce15128b3
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Jun 22 09:18:39 2012 -0700

    Missed another tarfile 'with' declaration
    
    Missed that we were using the 'with' keyword for a tarfile in the integ tests.
    Using a try/catch instead so this'll work on python 2.5.
---
 test/integ/descriptor/reader.py |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 27d096f..25952de 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -50,13 +50,20 @@ def _get_raw_tar_descriptors():
     test_path = os.path.join(DESCRIPTOR_TEST_DATA, "descriptor_archive.tar")
     raw_descriptors = []
     
-    with tarfile.open(test_path) as tar_file:
+    # TODO: revert to using the 'with' keyword for this when dropping python 2.5 support
+    tar_file = None
+    
+    try:
+      tar_file = tarfile.open(test_path)
+      
       for tar_entry in tar_file:
         if tar_entry.isfile():
           entry = tar_file.extractfile(tar_entry)
           entry.readline() # strip header
           raw_descriptors.append(entry.read())
           entry.close()
+    finally:
+      if tar_file: tar_file.close()
     
     TAR_DESCRIPTORS = raw_descriptors
   





More information about the tor-commits mailing list