mercurial/util.py
changeset 6470 ac0bcd951c2c
parent 6339 ed9b07a97587
child 6501 4f7feeb6d6ee
--- 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: