[or-cvs] [pytorctl/master 2/2] Fix the Python 2.4 fix.

mikeperry at torproject.org mikeperry at torproject.org
Thu Aug 26 03:32:00 UTC 2010


Author: Harry Bock <hbock at ele.uri.edu>
Date: Tue, 24 Aug 2010 11:03:34 -0400
Subject: Fix the Python 2.4 fix.
Commit: befe9af010bb8f43d46079df7ec3dff230b9ac4d

Oops - apparently I used a Python 2.5ism in trying to remove a
Python 2.5ism :)
---
 TorCtl.py |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/TorCtl.py b/TorCtl.py
index 01e0949..48ebcfc 100755
--- a/TorCtl.py
+++ b/TorCtl.py
@@ -323,6 +323,17 @@ desc_re = {
 for kw, reg in desc_re.iteritems():
   desc_re[kw] = re.compile(reg)
 
+def partition(string, delimiter):
+  """ Implementation of string.partition-like function for Python <
+  2.5.  Returns a tuple (first, rest), where first is the text up to
+  the first delimiter, and rest is the text after the first delimiter.
+  """
+  sp = string.split(delimiter, 1)
+  if len(sp) > 1:
+    return sp[0], sp[1]
+  else:
+    return sp[0], ""
+
 class Router:
   """ 
   Class to represent a router from a descriptor. Can either be
@@ -384,16 +395,13 @@ class Router:
 
     for line in desc:
       # Pull off the keyword...
-      sp = line.split(" ", 1)
-      kw = sp[0]
-      rest = sp[1] if len(sp) > 1 else ""
+      kw, rest = partition(line, " ")
 
       # ...and if it's "opt", extend it by the next keyword
       # so we get "opt hibernating" as one keyword.
       if kw == "opt":
-        sp = rest.split(" ", 1)
-        rest = sp[1] if len(sp) > 1 else ""
-        kw += " " + sp[0]
+        okw, rest = partition(rest, " ")
+        kw += " " + okw
 
       # try to match the descriptor line by keyword.
       try:
-- 
1.7.1



More information about the tor-commits mailing list