[or-cvs] r22379: {torctl} Patch from Harry Bock to eliminate deprecation warnings on P (torctl/trunk/python/TorCtl)

Mike Perry mikeperry-svn at fscked.org
Sun May 23 04:13:22 UTC 2010


Author: mikeperry
Date: 2010-05-23 04:13:21 +0000 (Sun, 23 May 2010)
New Revision: 22379

Modified:
   torctl/trunk/python/TorCtl/PathSupport.py
   torctl/trunk/python/TorCtl/TorCtl.py
   torctl/trunk/python/TorCtl/TorUtil.py
Log:

Patch from Harry Bock to eliminate deprecation warnings on
Python 2.5+.



Modified: torctl/trunk/python/TorCtl/PathSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/PathSupport.py	2010-05-22 23:07:09 UTC (rev 22378)
+++ torctl/trunk/python/TorCtl/PathSupport.py	2010-05-23 04:13:21 UTC (rev 22379)
@@ -57,10 +57,13 @@
 import time
 import TorUtil
 import traceback
-import sets
 import threading
 from TorUtil import *
 
+import sys
+if sys.version_info < (2, 5):
+  from sets import Set as set
+
 __all__ = ["NodeRestrictionList", "PathRestrictionList",
 "PercentileRestriction", "OSRestriction", "ConserveExitsRestriction",
 "FlagsRestriction", "MinBWRestriction", "VersionIncludeRestriction",
@@ -1299,7 +1302,7 @@
       import SocksiPy
       socket.socket = __oldsocket
    """
-  port_table = sets.Set()
+  port_table = set()
   _table_lock = threading.Lock()
 
   def connect(self, args):

Modified: torctl/trunk/python/TorCtl/TorCtl.py
===================================================================
--- torctl/trunk/python/TorCtl/TorCtl.py	2010-05-22 23:07:09 UTC (rev 22378)
+++ torctl/trunk/python/TorCtl/TorCtl.py	2010-05-23 04:13:21 UTC (rev 22379)
@@ -42,11 +42,16 @@
 import binascii
 import types
 import time
-import sha
-import sets
 import copy
+
 from TorUtil import *
 
+if sys.version_info < (2, 5):
+  from sets import Set as set
+  from sha import sha as sha1
+else:
+  from hashlib import sha1
+
 # Types of "EVENT" message.
 EVENT_TYPE = Enum2(
           CIRC="CIRC",
@@ -819,7 +824,7 @@
     """Fill in a Router class corresponding to a given NS class"""
     desc = self.sendAndRecv("GETINFO desc/id/" + ns.idhex + "\r\n")[0][2]
     sig_start = desc.find("\nrouter-signature\n")+len("\nrouter-signature\n")
-    fp_base64 = sha.sha(desc[:sig_start]).digest().encode("base64")[:-2]
+    fp_base64 = sha1(desc[:sig_start]).digest().encode("base64")[:-2]
     r = Router.build_from_desc(desc.split("\n"), ns)
     if fp_base64 != ns.orhash:
       plog("INFO", "Router descriptor for "+ns.idhex+" does not match ns fingerprint (NS @ "+str(ns.updated)+" vs Desc @ "+str(r.published)+")")
@@ -1344,8 +1349,8 @@
     # 4. They list a bandwidth of 0
     # 5. They have 'opt hibernating' set
     routers = self.c.read_routers(nslist) # Sets .down if 3,4,5
-    old_idhexes = sets.Set(self.routers.keys())
-    new_idhexes = sets.Set(map(lambda r: r.idhex, routers)) 
+    old_idhexes = set(self.routers.keys())
+    new_idhexes = set(map(lambda r: r.idhex, routers)) 
     for r in routers:
       if r.idhex in self.routers:
         if self.routers[r.idhex].nickname != r.nickname:
@@ -1359,8 +1364,8 @@
         self.routers[rc.idhex] = rc
 
     removed_idhexes = old_idhexes - new_idhexes
-    removed_idhexes.union_update(sets.Set(map(lambda r: r.idhex,
-                      filter(lambda r: r.down, routers))))
+    removed_idhexes.update(set(map(lambda r: r.idhex,
+                                   filter(lambda r: r.down, routers))))
 
     for i in removed_idhexes:
       if i not in self.routers: continue

Modified: torctl/trunk/python/TorCtl/TorUtil.py
===================================================================
--- torctl/trunk/python/TorCtl/TorUtil.py	2010-05-22 23:07:09 UTC (rev 22378)
+++ torctl/trunk/python/TorCtl/TorUtil.py	2010-05-23 04:13:21 UTC (rev 22379)
@@ -12,11 +12,15 @@
 import sys
 import socket
 import binascii
-import sha
 import math
 import time
 import ConfigParser
 
+if sys.version_info < (2, 5):
+  from sha import sha as sha1
+else:
+  from hashlib import sha1
+
 __all__ = ["Enum", "Enum2", "Callable", "sort_list", "quote", "escape_dots", "unescape_dots",
       "BufSock", "secret_to_key", "urandom_rng", "s2k_gen", "s2k_check", "plog", 
      "ListenSocket", "zprob", "logfile", "loglevel"]
@@ -257,7 +261,7 @@
   EXPBIAS = 6
   count = (16+(c&15)) << ((c>>4) + EXPBIAS)
 
-  d = sha.new()
+  d = sha1()
   tmp = s2k_specifier[:8]+secret
   slen = len(tmp)
   while count:



More information about the tor-commits mailing list