From: Zooko O'Whielacronx Date: Mon, 14 Dec 2009 21:27:03 +0000 (-0800) Subject: use hashlib module if available, thus avoiding a DeprecationWarning for importing... X-Git-Tag: trac-4200~70 X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/%5B%5E?a=commitdiff_plain;h=b69e1c600dc7ff7fb20391f15256b04569fd4a3c;p=tahoe-lafs%2Ftahoe-lafs.git use hashlib module if available, thus avoiding a DeprecationWarning for importing the old sha module; fixes #859 --- diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index 69161924..d12cb8b7 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -28,7 +28,15 @@ the foolscap-based server implemented in src/allmydata/storage/*.py . # # 6: implement other sorts of IStorageClient classes: S3, etc -import sha, time +try: + from hashlib import sha1 +except ImportError: + # hashlib was added in Python 2.5 + import sha + def sha1(x): + return sha.new(x) + +import time from zope.interface import implements, Interface from foolscap.api import eventually from allmydata.interfaces import IStorageBroker @@ -119,7 +127,7 @@ class StorageFarmBroker: assert self.permute_peers == True servers = self.get_all_servers() key = peer_selection_index - return sorted(servers, key=lambda x: sha.new(key+x[0]).digest()) + return sorted(servers, key=lambda x: sha1(key+x[0]).digest()) def get_all_servers(self): # return a frozenset of (peerid, versioned-rref) tuples