more #859: avoid deprecation warning for unit tests too, hush pyflakes

* factor maybe-import-sha logic into util.hashutil
This commit is contained in:
Brian Warner 2009-12-14 16:01:47 -08:00
parent b69e1c600d
commit a4a6c02ef8
3 changed files with 11 additions and 9 deletions

View File

@ -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?

View File

@ -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):

View File

@ -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