[tor-commits] [stem/master] Dumbing down syntax for python 2.5

atagar at torproject.org atagar at torproject.org
Wed Jun 13 16:29:46 UTC 2012


commit 98b3a8dfb10944ff3ec7b41a3b1f39297173bf26
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Jun 13 08:39:57 2012 -0700

    Dumbing down syntax for python 2.5
    
    Evidently even with the 'with' keyword's future import it still chokes on comma
    delimited entries (instead you need to do nested 'with' blocks). Ick. Oh well,
    if that's all we need to maintain 2.5 compatability then I'll be happy.
    
    It's a pity we can't tell python 'run in 2.5 compatability mode' to check for
    these things. I doubt that we'll remember to run against a 2.5 instance to keep
    stem working there. Oh well, guess this is a problem that'll need to be
    addressed when figuring out a release procedure.
---
 stem/control.py          |   33 +++++++++++++++++----------------
 stem/util/conf.py        |   15 ++++++++-------
 test/check_whitespace.py |    2 ++
 3 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index f20451b..09c61e4 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -309,22 +309,23 @@ class BaseController:
     # Any changes to our is_alive() state happen under the send lock, so we
     # need to have it to ensure it doesn't change beneath us.
     
-    with self._socket._get_send_lock(), self._status_listeners_lock:
-      change_timestamp = time.time()
-      
-      if expect_alive != None and expect_alive != self.is_alive():
-        return
-      
-      for listener, spawn in self._status_listeners:
-        if spawn:
-          name = "%s notification" % state
-          args = (self, state, change_timestamp)
-          
-          notice_thread = threading.Thread(target = listener, args = args, name = name)
-          notice_thread.setDaemon(True)
-          notice_thread.start()
-        else:
-          listener(self, state, change_timestamp)
+    with self._socket._get_send_lock():
+      with self._status_listeners_lock:
+        change_timestamp = time.time()
+        
+        if expect_alive != None and expect_alive != self.is_alive():
+          return
+        
+        for listener, spawn in self._status_listeners:
+          if spawn:
+            name = "%s notification" % state
+            args = (self, state, change_timestamp)
+            
+            notice_thread = threading.Thread(target = listener, args = args, name = name)
+            notice_thread.setDaemon(True)
+            notice_thread.start()
+          else:
+            listener(self, state, change_timestamp)
   
   def _launch_threads(self):
     """
diff --git a/stem/util/conf.py b/stem/util/conf.py
index 70287c2..3f1865a 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -280,13 +280,14 @@ class Config():
     elif not self._path:
       raise ValueError("Unable to save configuration: no path provided")
     
-    with self._contents_lock, open(self._path, 'w') as output_file:
-      for entry_key in sorted(self.keys()):
-        for entry_value in self.get_value(entry_key, multiple = True):
-          # check for multi line entries
-          if "\n" in entry_value: entry_value = "\n|" + entry_value.replace("\n", "\n|")
-          
-          output_file.write('%s %s\n' % (entry_key, entry_value))
+    with self._contents_lock:
+      with open(self._path, 'w') as output_file:
+        for entry_key in sorted(self.keys()):
+          for entry_value in self.get_value(entry_key, multiple = True):
+            # check for multi line entries
+            if "\n" in entry_value: entry_value = "\n|" + entry_value.replace("\n", "\n|")
+            
+            output_file.write('%s %s\n' % (entry_key, entry_value))
   
   def clear(self):
     """
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index 6c47cab..23ca1af 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -14,6 +14,8 @@ it's so much easier to do here...):
   from __future__ import with_statement
 """
 
+from __future__ import with_statement
+
 import re
 import os
 





More information about the tor-commits mailing list