Simplify wrapper, as digest_size is known in advance each time.

This commit is contained in:
Legrandin 2011-02-07 23:18:12 +01:00
parent 9620229917
commit dd3f0007c5
3 changed files with 9 additions and 7 deletions

View file

@ -38,17 +38,17 @@ def new(data=""):
obj = Wrapper(hashFactory, data)
obj.oid = oid
obj.new = globals()['new']
if not hasattr(obj, 'digest_size'):
obj.digest_size = digest_size
return obj
try:
# The md5 module is deprecated in Python 2.6, so use hashlib when possible.
import hashlib
hashFactory = hashlib.md5
digest_size = new().digest_size
except ImportError:
import md5
hashFactory = md5
if hasattr(md5, 'digestsize'):
digest_size = md5.digestsize
digest_size = 16

View file

@ -38,17 +38,17 @@ def new(data=""):
obj = Wrapper(hashFactory, data)
obj.oid = oid
obj.new = globals()['new']
if not hasattr(obj, 'digest_size'):
obj.digest_size = digest_size
return obj
try:
# The sha module is deprecated in Python 2.6, so use hashlib when possible.
import hashlib
hashFactory = hashlib.sha1
digest_size = new().digest_size
except ImportError:
import sha
hashFactory = sha
if hasattr(sha, 'digestsize'):
digest_size = sha.digestsize
digest_size = 20

View file

@ -40,5 +40,7 @@ class Wrapper:
try:
return getattr(getattr(self,'_wrapped'),name)
except AttributeError:
if hasattr(self, name):
return getattr(self,name)
raise