Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 12051:ff5cec76b1c5 stable 1.6.3
util: avoid using hashlib on Python < 2.5 (issue2278)
The following patch allows the use of python2.4 with a standalone
hashlib rather than assuming that python2.5 is in use when hashlib is
imported successfully.
author | Sol Jerome <sol.jerome@gmail.com> |
---|---|
date | Tue, 17 Aug 2010 17:38:19 -0500 |
parents | a79214972da2 |
children | 5d22e631c365 b6173aee4a47 |
comparison
equal
deleted
inserted
replaced
12050:c5fd25c1bc4a | 12051:ff5cec76b1c5 |
---|---|
26 | 26 |
27 def _fastsha1(s): | 27 def _fastsha1(s): |
28 # This function will import sha1 from hashlib or sha (whichever is | 28 # This function will import sha1 from hashlib or sha (whichever is |
29 # available) and overwrite itself with it on the first call. | 29 # available) and overwrite itself with it on the first call. |
30 # Subsequent calls will go directly to the imported function. | 30 # Subsequent calls will go directly to the imported function. |
31 try: | 31 if sys.version_info >= (2, 5): |
32 from hashlib import sha1 as _sha1 | 32 from hashlib import sha1 as _sha1 |
33 except ImportError: | 33 else: |
34 from sha import sha as _sha1 | 34 from sha import sha as _sha1 |
35 global _fastsha1, sha1 | 35 global _fastsha1, sha1 |
36 _fastsha1 = sha1 = _sha1 | 36 _fastsha1 = sha1 = _sha1 |
37 return _sha1(s) | 37 return _sha1(s) |
38 | 38 |