Mercurial > cpython-lru_cache-weakref
diff Lib/hmac.py @ 64197:8397f2e007eb
speed hack can be implemented more cleanly by directly calling __new__
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 21 Aug 2010 02:45:15 +0000 |
| parents | f3db504cdfb1 |
| children | 8e57b5d8f58f |
line wrap: on
line diff
--- a/Lib/hmac.py Sat Aug 21 02:43:31 2010 +0000 +++ b/Lib/hmac.py Sat Aug 21 02:45:15 2010 +0000 @@ -12,10 +12,6 @@ # hashing module used. Use digest_size from the instance of HMAC instead. digest_size = None -# A unique object passed by HMAC.copy() to the HMAC constructor, in order -# that the latter return very quickly. HMAC("") in contrast is quite -# expensive. -_secret_backdoor_key = object() class HMAC: """RFC 2104 HMAC class. Also complies with RFC 4231. @@ -36,9 +32,6 @@ Note: key and msg must be bytes objects. """ - if key is _secret_backdoor_key: # cheap - return - if not isinstance(key, bytes): raise TypeError("expected bytes, but got %r" % type(key).__name__) @@ -89,7 +82,8 @@ An update to this copy won't affect the original object. """ - other = self.__class__(_secret_backdoor_key) + # Call __new__ directly to avoid the expensive __init__. + other = self.__class__.__new__(self.__class__) other.digest_cons = self.digest_cons other.digest_size = self.digest_size other.inner = self.inner.copy()
