From: zooko Date: Mon, 15 Jun 2009 22:19:23 +0000 (+0530) Subject: silence deprecation warning by using hashlib if it is present (which it is on Python... X-Git-Url: https://git.rkrishnan.org/vdrive/%22file:/frontends/(%5B%5E?a=commitdiff_plain;h=31f95b77ee6c49c2facb2508a3c28d216f53c62a;p=tahoe-lafs%2Fzfec.git silence deprecation warning by using hashlib if it is present (which it is on Python >= 2.5.0) Ignore-this: 8c1c031028640cf022e4efb2ff9b6e12 darcs-hash:c65550b3ff75901d39e274e7001417aa29790649 --- diff --git a/zfec/zfec/filefec.py b/zfec/zfec/filefec.py index a6c0a35..99de3bd 100644 --- a/zfec/zfec/filefec.py +++ b/zfec/zfec/filefec.py @@ -347,7 +347,12 @@ def encode_file(inf, cb, k, m, chunksize=4096): res = enc.encode(l) cb(res, indatasize) -import sha +try: + from hashlib import sha1 +except ImportError: + # hashlib was added in Python 2.5.0. + import sha as sha1 + def encode_file_not_really(inf, cb, k, m, chunksize=4096): enc = zfec.Encoder(k, m) l = tuple([ array.array('c') for i in range(k) ]) @@ -380,7 +385,7 @@ def encode_file_not_really(inf, cb, k, m, chunksize=4096): cb(None, None) def encode_file_not_really_and_hash(inf, cb, k, m, chunksize=4096): - hasher = sha.new() + hasher = sha1.new() enc = zfec.Encoder(k, m) l = tuple([ array.array('c') for i in range(k) ]) indatasize = k*chunksize # will be reset to shorter upon EOF