Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 6470:ac0bcd951c2c
python 2.6 compatibility: compatibility wrappers for hash functions
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Fri, 04 Apr 2008 22:36:40 +0200 |
parents | ed9b07a97587 |
children | 4f7feeb6d6ee |
line wrap: on
line diff
--- a/mercurial/util.py Fri Apr 04 22:41:17 2008 +0200 +++ b/mercurial/util.py Fri Apr 04 22:36:40 2008 +0200 @@ -17,12 +17,38 @@ import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil import urlparse +# Python compatibility + try: set = set frozenset = frozenset except NameError: from sets import Set as set, ImmutableSet as frozenset +_md5 = None +def md5(s): + global _md5 + if _md5 is None: + try: + import hashlib + _md5 = hashlib.md5 + except ImportError: + import md5 + _md5 = md5.md5 + return _md5(s) + +_sha1 = None +def sha1(s): + global _sha1 + if _sha1 is None: + try: + import hashlib + _sha1 = hashlib.sha1 + except ImportError: + import sha + _sha1 = sha.sha + return _sha1(s) + try: _encoding = os.environ.get("HGENCODING") if sys.platform == 'darwin' and not _encoding: