From: Brian Warner Date: Tue, 15 Dec 2009 00:01:47 +0000 (-0800) Subject: more #859: avoid deprecation warning for unit tests too, hush pyflakes X-Git-Tag: trac-4200~69 X-Git-Url: https://git.rkrishnan.org/frontends/banana.xhtml?a=commitdiff_plain;h=a4a6c02ef8ae2e0edb30bb0051873ffca6af6fc0;p=tahoe-lafs%2Ftahoe-lafs.git more #859: avoid deprecation warning for unit tests too, hush pyflakes * factor maybe-import-sha logic into util.hashutil --- diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index d12cb8b7..7945eac0 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -28,13 +28,6 @@ the foolscap-based server implemented in src/allmydata/storage/*.py . # # 6: implement other sorts of IStorageClient classes: S3, etc -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 @@ -43,6 +36,7 @@ from allmydata.interfaces import IStorageBroker from allmydata.util import idlib, log from allmydata.util.assertutil import _assert, precondition from allmydata.util.rrefutil import add_version_to_remote_reference +from allmydata.util.hashutil import sha1 # who is responsible for de-duplication? # both? diff --git a/src/allmydata/test/no_network.py b/src/allmydata/test/no_network.py index fdf7e78e..d1fa8340 100644 --- a/src/allmydata/test/no_network.py +++ b/src/allmydata/test/no_network.py @@ -14,7 +14,6 @@ # or the control.furl . import os.path -import sha from zope.interface import implements from twisted.application import service from twisted.internet import reactor @@ -25,6 +24,7 @@ from allmydata import uri as tahoe_uri from allmydata.client import Client from allmydata.storage.server import StorageServer, storage_index_to_dir from allmydata.util import fileutil, idlib, hashutil +from allmydata.util.hashutil import sha1 from allmydata.test.common_web import HTTPClientGETFactory from allmydata.interfaces import IStorageBroker @@ -105,7 +105,7 @@ class NoNetworkStorageBroker: implements(IStorageBroker) def get_servers_for_index(self, key): return sorted(self.client._servers, - key=lambda x: sha.new(key+x[0]).digest()) + key=lambda x: sha1(key+x[0]).digest()) def get_all_servers(self): return frozenset(self.client._servers) def get_nickname_for_serverid(self, serverid): diff --git a/src/allmydata/util/hashutil.py b/src/allmydata/util/hashutil.py index 2b40a97c..2af8749b 100644 --- a/src/allmydata/util/hashutil.py +++ b/src/allmydata/util/hashutil.py @@ -2,6 +2,14 @@ from pycryptopp.hash.sha256 import SHA256 import os from allmydata.util.netstring import netstring +try: + import hashlib + sha1 = hashlib.sha1 +except ImportError: + # hashlib was added in Python 2.5 + import sha + sha1 = sha.new + # Be very very cautious when modifying this file. Almost any change will # cause a compatibility break, invalidating all outstanding URIs and making # any previously uploaded files become inaccessible. BE CONSERVATIVE AND TEST